forked from robotframework/robotframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_misc.py
More file actions
147 lines (121 loc) · 5.96 KB
/
test_misc.py
File metadata and controls
147 lines (121 loc) · 5.96 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import unittest
from robot.utils.asserts import assert_equal
from robot.utils import printable_name, seq2str, roundup, IRONPYTHON
class TestRoundup(unittest.TestCase):
def test_basics(self):
for number in range(1000):
for extra in range(5):
extra /= 10.0
assert_equal(roundup(number + extra), number, +extra)
assert_equal(roundup(number - extra), number, -extra)
assert_equal(roundup(number + 0.5), number+1)
def test_negative(self):
for number in range(1000):
number *= -1
for extra in range(5):
extra /= 10.0
assert_equal(roundup(number + extra), number)
assert_equal(roundup(number - extra), number)
assert_equal(roundup(number - 0.5), number-1)
def test_ndigits_below_zero(self):
assert_equal(roundup(7, -1), 10)
assert_equal(roundup(77, -1), 80)
assert_equal(roundup(123, -2), 100)
assert_equal(roundup(-1234, -2), -1200)
assert_equal(roundup(9999, -2), 10000)
def test_ndigits_above_zero(self):
assert_equal(roundup(0.1234, 1), 0.1)
assert_equal(roundup(0.9999, 1), 1.0)
assert_equal(roundup(0.9876, 3), 0.988)
def test_round_even_up(self):
assert_equal(roundup(0.5), 1)
assert_equal(roundup(5, -1), 10)
assert_equal(roundup(500, -3), 1000)
assert_equal(roundup(0.05, 1), 0.1)
assert_equal(roundup(0.49951, 3), 0.5)
def test_round_even_down_when_negative(self):
assert_equal(roundup(-0.5), -1)
assert_equal(roundup(-5, -1), -10)
assert_equal(roundup(-5.0, -1), -10)
assert_equal(roundup(-500, -3), -1000)
assert_equal(roundup(-0.05, 1), -0.1)
assert_equal(roundup(-0.49951, 3), -0.5)
def test_return_type(self):
for n in [1, 1000, 0.1, 0.001]:
for d in [-3, -2, -1, 0, 1, 2, 3]:
assert_equal(type(roundup(n, d)), float if d > 0 else int)
assert_equal(type(roundup(n, d, return_type=int)), int)
assert_equal(type(roundup(n, d, return_type=float)), float)
def test_problems(self):
assert_equal(roundup(59.85, 1), 59.9) # This caused #2872
if not IRONPYTHON:
assert_equal(roundup(1.15, 1), 1.1) # 1.15 is actually 1.49999..
else:
assert_equal(roundup(1.15, 1), 1.2) # but ipy still rounds it up
class TestSeg2Str(unittest.TestCase):
def _verify(self, input, expected, **config):
assert_equal(seq2str(input, **config), expected)
def test_empty(self):
for seq in [[], (), set()]:
self._verify(seq, '')
def test_one_or_more(self):
for seq, expected in [(['One'], "'One'"),
(['1', '2'], "'1' and '2'"),
(['a', 'b', 'c', 'd'], "'a', 'b', 'c' and 'd'"),
([u'Unicode', u'ASCII'], "'Unicode' and 'ASCII'")]:
self._verify(seq, expected)
def test_non_ascii_unicode(self):
self._verify([u'hyv\xe4'], u"'hyv\xe4'")
def test_ascii_bytes(self):
self._verify([b'ascii'], "'ascii'")
def test_non_ascii_bytes(self):
self._verify([b'non-\xe4scii'], "'non-\\xe4scii'")
def test_other_objects(self):
self._verify([None, 1, True], "'None', '1' and 'True'")
class TestPrintableName(unittest.TestCase):
def test_printable_name(self):
for inp, exp in [('simple', 'Simple'),
('ALLCAPS', 'ALLCAPS'),
('name with spaces', 'Name With Spaces'),
('more spaces', 'More Spaces'),
(' leading and trailing ', 'Leading And Trailing'),
(' 12number34 ', '12number34'),
('Cases AND spaces', 'Cases AND Spaces'),
('under_Score_name', 'Under_Score_name'),
('camelCaseName', 'CamelCaseName'),
('with89numbers', 'With89numbers'),
('with 89 numbers', 'With 89 Numbers'),
('with 89_numbers', 'With 89_numbers'),
('', '')]:
assert_equal(printable_name(inp), exp)
def test_printable_name_with_code_style(self):
for inp, exp in [('simple', 'Simple'),
('ALLCAPS', 'ALLCAPS'),
('name with spaces', 'Name With Spaces'),
(' more spaces ', 'More Spaces'),
('under_score_name', 'Under Score Name'),
('under__score and spaces', 'Under Score And Spaces'),
('__leading and trailing_ __', 'Leading And Trailing'),
('__12number34__', '12 Number 34'),
('miXed_CAPS_nAMe', 'MiXed CAPS NAMe'),
('with 89_numbers', 'With 89 Numbers'),
('camelCaseName', 'Camel Case Name'),
('mixedCAPSCamelName', 'Mixed CAPS Camel Name'),
('camelCaseWithDigit1', 'Camel Case With Digit 1'),
('teamX', 'Team X'),
('name42WithNumbers666', 'Name 42 With Numbers 666'),
('name42WITHNumbers666', 'Name 42 WITH Numbers 666'),
('12more34numbers', '12 More 34 Numbers'),
('2KW', '2 KW'),
('KW2', 'KW 2'),
('xKW', 'X KW'),
('KWx', 'K Wx'),
(':KW', ':KW'),
('KW:', 'KW:'),
('foo-bar', 'Foo-bar'),
('Foo-b:a;r!', 'Foo-b:a;r!'),
('Foo-B:A;R!', 'Foo-B:A;R!'),
('', '')]:
assert_equal(printable_name(inp, code_style=True), exp)
if __name__ == "__main__":
unittest.main()