Skip to content

Commit 9b4b0a9

Browse files
Conflict resolving
2 parents 7a02816 + 7f0a193 commit 9b4b0a9

File tree

2 files changed

+219
-0
lines changed

2 files changed

+219
-0
lines changed

practice_2/maria_assertions.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
def assert_equal(a, b):
2+
if a != b:
3+
raise AssertionError("'{}' is not equal to '{}'".format(a, b))
4+
5+
def assert_not_equal(a, b):
6+
if a == b:
7+
raise AssertionError("'{}' is equal to '{}'".format(a, b))
8+
9+
def assert_true(x):
10+
if not x:
11+
raise AssertionError("'{}' is not true".format(x))
12+
13+
def assert_false(x):
14+
if x:
15+
raise AssertionError("'{}' is not false".format(x))
16+
17+
def assert_is(a, b):
18+
if a is not b:
19+
raise AssertionError("'{}' is not identical to '{}'".format(id(a), id(b)))
20+
21+
def assert_is_not(a, b):
22+
if a is b:
23+
raise AssertionError("'{}' is identical to '{}'".format(id(a),id(b)))
24+
25+
def assert_is_none(x):
26+
if x is not None:
27+
raise AssertionError("'{}' is not none".format(x))
28+
29+
def assert_is_not_none(x):
30+
if x is None:
31+
raise AssertionError("'{}' is none".format(x))
32+
33+
def assert_in(a, b):
34+
if a not in b:
35+
raise AssertionError("'{}' doesn't contain '{}'".format(b, a))
36+
37+
def assert_not_in(a, b):
38+
if a in b:
39+
raise AssertionError("'{}' contains '{}'".format(b, a))
40+

practice_2/maria_assertions_tests.py

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
from examples_2.utils import print_stars
2+
from practice_2.maria_assertions import *
3+
4+
def assert_equal_test(a, b):
5+
try:
6+
assert_equal(a, b)
7+
except AssertionError as e:
8+
print("Failed - Exception caught: %r" % e.message)
9+
else:
10+
print("Passed - '{}' is equal to '{}'".format(a, b))
11+
finally:
12+
print_stars()
13+
14+
def assert_not_equal_test(a, b):
15+
try:
16+
assert_not_equal(a, b)
17+
except AssertionError as e:
18+
print("Failed - Exception caught: %r" % e.message)
19+
else:
20+
print("Passed - '{}' is not equal to '{}'".format(a, b))
21+
finally:
22+
print_stars()
23+
24+
def assert_true_test(x):
25+
try:
26+
assert_true(x)
27+
except AssertionError as e:
28+
print("Failed - Exception caught: %r" % e.message)
29+
else:
30+
print("Passed - '{}' is true".format(x))
31+
finally:
32+
print_stars()
33+
34+
def assert_false_test(x):
35+
try:
36+
assert_false(x)
37+
except AssertionError as e:
38+
print("Failed - Exception caught: %r" % e.message)
39+
else:
40+
print("Passed - '{}' is false".format(x))
41+
finally:
42+
print_stars()
43+
44+
def assert_is_test(a, b):
45+
try:
46+
assert_is(a, b)
47+
except AssertionError as e:
48+
print("Failed - Exception caught: %r" % e.message)
49+
else:
50+
print("Passed - '{}' is identical to '{}'".format(id(a), id(b)))
51+
finally:
52+
print_stars()
53+
54+
def assert_is_not_test(a, b):
55+
try:
56+
assert_is_not(a, b)
57+
except AssertionError as e:
58+
print("Failed - Exception caught: %r" % e.message)
59+
else:
60+
print("Passed - '{}' is not identical to '{}'".format(id(a), id(b)))
61+
finally:
62+
print_stars()
63+
64+
def assert_is_none_test(x):
65+
try:
66+
assert_is_none(x)
67+
except AssertionError as e:
68+
print("Failed - Exception caught: %r" % e.message)
69+
else:
70+
print("Passed - '{}' is none".format(x))
71+
finally:
72+
print_stars()
73+
74+
def assert_is_not_none_test(x):
75+
try:
76+
assert_is_not_none(x)
77+
except AssertionError as e:
78+
print("Failed - Exception caught: %r" % e.message)
79+
else:
80+
print("Passed - '{}' is not none".format(x))
81+
finally:
82+
print_stars()
83+
84+
def assert_in_test(a, b):
85+
try:
86+
assert_in(a, b)
87+
except AssertionError as e:
88+
print("Failed - Exception caught: %r" % e.message)
89+
else:
90+
print("Passed - '{}' in '{}'".format(a, b))
91+
finally:
92+
print_stars()
93+
94+
def assert_not_in_test(a, b):
95+
try:
96+
assert_not_in(a, b)
97+
except AssertionError as e:
98+
print("Failed - Exception caught: %r" % e.message)
99+
else:
100+
print("Passed - '{}' not in '{}'".format(a, b))
101+
finally:
102+
print_stars()
103+
104+
print_stars()
105+
print("Test 'assert_equal' function")
106+
print_stars()
107+
a = [1, 4]
108+
b = [1, 4]
109+
assert_equal_test(a, b)
110+
b = [1, 5]
111+
assert_equal_test(a, b)
112+
113+
print("Test 'assert_not_equal' function")
114+
print_stars()
115+
a = [1, 4]
116+
b = 7
117+
assert_not_equal_test(a, b)
118+
b = [1, 4]
119+
assert_not_equal_test(a, b)
120+
121+
print("Test 'assert_true' function")
122+
print_stars()
123+
x = 5
124+
assert_true_test(x)
125+
x = 0
126+
assert_true_test(x)
127+
128+
print("Test 'assert_false' function")
129+
print_stars()
130+
x = ""
131+
assert_false_test(x)
132+
x = " String "
133+
assert_false_test(x)
134+
135+
print("Test 'assert_is' function")
136+
print_stars()
137+
a = [1, 4]
138+
b = a
139+
assert_is_test(a, b)
140+
b = [1, 4]
141+
assert_is_test(a, b)
142+
143+
print("Test 'assert_is_not' function")
144+
print_stars()
145+
a = [1, 4]
146+
b = [1, 4]
147+
assert_is_not_test(a, b)
148+
b = a
149+
assert_is_not_test(a, b)
150+
151+
print("Test 'assert_is_none' function")
152+
print_stars()
153+
x = None
154+
assert_is_none_test(x)
155+
x = 0
156+
assert_is_none_test(x)
157+
158+
print("Test 'assert_is_not_none' function")
159+
print_stars()
160+
x = ""
161+
assert_is_not_none_test(x)
162+
x = None
163+
assert_is_not_none_test(x)
164+
165+
print("Test 'assert_in' function")
166+
print_stars()
167+
a = 3
168+
b = [1, 2, 3]
169+
assert_in_test(a, b)
170+
a = 7
171+
assert_in_test(a, b)
172+
173+
print("Test 'assert_in' function")
174+
print_stars()
175+
a = "z"
176+
b = "String"
177+
assert_not_in_test(a, b)
178+
a = "t"
179+
assert_not_in_test(a, b)

0 commit comments

Comments
 (0)