-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08_test_classes.py
More file actions
34 lines (24 loc) · 808 Bytes
/
08_test_classes.py
File metadata and controls
34 lines (24 loc) · 808 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
def str_to_int(string):
error_message = f"Cannot convert '{string}' to an integer."
try:
integer = float(string.replace(",", "."))
except AttributeError:
if isinstance(string, (int, float)):
integer = string
else:
raise RuntimeError(error_message)
except (TypeError, ValueError):
raise RuntimeError(error_message)
return int(integer)
class TestStrToInt:
def setup(self):
print("\nthis is setup")
def teardown(self):
print("\nthis is teardown")
def setup_class(cls):
print("\nthis is setup_class")
def teardown_class(cls):
print("\nthis is teardown_class")
def test_rounds_down(self):
result = str_to_int("1.99")
assert result == 2