tests/basics/deque*: Tests for ucollections.deque.

This commit is contained in:
Paul Sokolovsky 2018-02-06 11:58:40 +02:00 committed by Damien George
parent 82828340a0
commit 4668ec801e
3 changed files with 128 additions and 0 deletions

47
tests/basics/deque1.py Normal file
View File

@ -0,0 +1,47 @@
try:
try:
from ucollections import deque
except ImportError:
from collections import deque
except ImportError:
print("SKIP")
raise SystemExit
d = deque((), 2)
print(len(d))
print(bool(d))
try:
d.popleft()
except IndexError:
print("IndexError")
print(d.append(1))
print(len(d))
print(bool(d))
print(d.popleft())
print(len(d))
d.append(2)
print(d.popleft())
d.append(3)
d.append(4)
print(len(d))
print(d.popleft(), d.popleft())
try:
d.popleft()
except IndexError:
print("IndexError")
d.append(5)
d.append(6)
d.append(7)
print(len(d))
print(d.popleft(), d.popleft())
print(len(d))
try:
d.popleft()
except IndexError:
print("IndexError")

66
tests/basics/deque2.py Normal file
View File

@ -0,0 +1,66 @@
# Tests for deques with "check overflow" flag and other extensions
# wrt to CPython.
try:
try:
from ucollections import deque
except ImportError:
from collections import deque
except ImportError:
print("SKIP")
raise SystemExit
# Initial sequence is not supported
try:
deque([1, 2, 3], 10)
except ValueError:
print("ValueError")
# Not even empty list, only empty tuple
try:
deque([], 10)
except ValueError:
print("ValueError")
# Only fixed-size deques are supported, so length arg is mandatory
try:
deque(())
except TypeError:
print("TypeError")
d = deque((), 2, True)
try:
d.popleft()
except IndexError:
print("IndexError")
print(d.append(1))
print(d.popleft())
d.append(2)
print(d.popleft())
d.append(3)
d.append(4)
print(d.popleft(), d.popleft())
try:
d.popleft()
except IndexError as e:
print(repr(e))
d.append(5)
d.append(6)
print(len(d))
try:
d.append(7)
except IndexError as e:
print(repr(e))
print(len(d))
print(d.popleft(), d.popleft())
print(len(d))
try:
d.popleft()
except IndexError as e:
print(repr(e))

View File

@ -0,0 +1,15 @@
ValueError
ValueError
TypeError
IndexError
None
1
2
3 4
IndexError('empty',)
2
IndexError('full',)
2
5 6
0
IndexError('empty',)