-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_case.py
34 lines (25 loc) · 867 Bytes
/
test_case.py
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
import random
from case import Case
def build_random_id():
return ''.join(random.choice('abcdefghijklmnopqrstuvwxyz') for _ in range(10))
def test_case_basic_api():
# hi !
c = Case('', 'hi !')
assert tuple(c) == ('', 'hi !')
assert not c.callable_input
assert not c.callable_output
# hello <input> !
c = Case(build_random_id, 'hello {stdin} !')
assert c.callable_input
assert not c.callable_output
stdin, stdout = c
assert stdout.startswith('hello ')
assert stdin == stdout[len('hello '):-2]
# hello <tupni> !
c = Case(build_random_id,
(lambda stdin: 'hello {} !'.format(''.join(reversed(stdin)))))
assert c.callable_input
assert c.callable_output
stdin, stdout = c
assert stdout.startswith('hello ')
assert stdin == ''.join(reversed(stdout[len('hello '):-2]))