-
Notifications
You must be signed in to change notification settings - Fork 0
/
py3k_test.py
56 lines (47 loc) · 1.2 KB
/
py3k_test.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
In addition to test.py, this tests extra features only available on python 3
"""
import argparse
import textwrap
import sys
import logging
from commandline_parsable import parsable_base
logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger(__name__)
@parsable_base(base_instantiable=True, factory_function="create")
class ClassA(object):
"""
This is the Base-Class
"""
@classmethod
def create(cls, arg1 :int):
instance = cls()
instance.arg1 = arg1
return instance
class ClassB(ClassA):
"""
The is B-B-B-Better
"""
pass
class ClassC(ClassA):
"""
The C-C-C-C-classical option
"""
pass
class ClassD(ClassB):
"""
This is D-D-D-D-delicate
"""
pass
def test_argument_is_converted():
log.error("Getting instances")
instances = ClassA.from_string("ClassD[12],ClassB[15]")
log.error("Done")
assert instances[0].arg1 == 12
assert isinstance(instances[0].arg1, int)
def test_argument_conversion_error():
"""
If a conversion does not work, we pass the unconverted string (like in python2)
"""
instances = ClassA.from_string("ClassD[12.4]")
assert isinstance(instances[0].arg1, str)