forked from UWPCE-PythonCert/IntroPython2016a
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_random_pytest.py
More file actions
38 lines (24 loc) · 771 Bytes
/
test_random_pytest.py
File metadata and controls
38 lines (24 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
"""
port of the random unit tests from the python docs to py.test
"""
import random
import pytest
seq = list(range(10))
def test_shuffle():
# make sure the shuffled sequence does not lose any elements
random.shuffle(seq)
# seq.sort() # this will amke it fail, so we can see output
print("seq:", seq) # only see output if it fails
assert seq == list(range(10))
def test_shuffle_immutable():
pytest.raises(TypeError, random.shuffle, (1, 2, 3))
def test_choice():
element = random.choice(seq)
assert (element in seq)
def test_sample():
for element in random.sample(seq, 5):
assert element in seq
def test_sample_too_large():
with pytest.raises(ValueError):
random.sample(seq, 20)