Skip to content

Commit 97a01a8

Browse files
committed
add tests of is_multiple_of() extension
1 parent b53d265 commit 97a01a8

File tree

1 file changed

+54
-7
lines changed

1 file changed

+54
-7
lines changed

tests/test_extensions.py

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,86 @@
2929
from assertpy import assert_that, add_extension
3030
import numbers
3131

32+
3233
def is_even(self):
3334
if isinstance(self.val, numbers.Integral) is False:
34-
raise TypeError('val is not integer number')
35+
raise TypeError('val must be an integer')
3536
if self.val % 2 != 0:
3637
self._err('Expected <%s> to be even, but was not.' % (self.val))
3738
return self
3839

40+
def is_multiple_of(self, other):
41+
if isinstance(self.val, numbers.Integral) is False:
42+
raise TypeError('val must be an integer')
43+
if isinstance(other, numbers.Integral) is False:
44+
raise TypeError('given arg must be an integer')
45+
_, rem = divmod(self.val, other)
46+
if rem != 0:
47+
self._err('Expected <%s> to be multiple of <%s>, but was not.' % (self.val, other))
48+
return self
49+
50+
3951

40-
def test_extension():
52+
def test_is_even_extension():
4153
add_extension(is_even)
4254
assert_that(124).is_even()
4355
assert_that(124).is_type_of(int).is_even().is_greater_than(123).is_less_than(125).is_equal_to(124)
44-
assert_that(12345678901234567890).is_even()
4556

46-
def test_extension_failure():
57+
def test_is_even_extension_failure():
4758
try:
4859
add_extension(is_even)
4960
assert_that(123).is_even()
5061
fail('should have raised error')
5162
except AssertionError as ex:
5263
assert_that(str(ex)).is_equal_to('Expected <123> to be even, but was not.')
5364

54-
def test_extension_failure_not_callable():
65+
def test_is_even_extension_failure_not_callable():
5566
try:
5667
add_extension('foo')
5768
fail('should have raised error')
5869
except TypeError as ex:
5970
assert_that(str(ex)).is_equal_to('func must be callable')
6071

61-
def test_extension_failure_not_integer():
72+
def test_is_even_extension_failure_not_integer():
6273
try:
6374
add_extension(is_even)
6475
assert_that(124.0).is_even()
6576
fail('should have raised error')
6677
except TypeError as ex:
67-
assert_that(str(ex)).is_equal_to('val is not integer number')
78+
assert_that(str(ex)).is_equal_to('val must be an integer')
79+
80+
def test_is_multiple_of_extension():
81+
add_extension(is_multiple_of)
82+
assert_that(24).is_multiple_of(1)
83+
assert_that(24).is_multiple_of(2)
84+
assert_that(24).is_multiple_of(3)
85+
assert_that(24).is_multiple_of(4)
86+
assert_that(24).is_multiple_of(6)
87+
assert_that(24).is_multiple_of(8)
88+
assert_that(24).is_multiple_of(12)
89+
assert_that(24).is_multiple_of(24)
90+
assert_that(124).is_type_of(int).is_even().is_multiple_of(31).is_equal_to(124)
91+
92+
def test_is_multiple_of_extension_failure():
93+
try:
94+
add_extension(is_multiple_of)
95+
assert_that(24).is_multiple_of(5)
96+
fail('should have raised error')
97+
except AssertionError as ex:
98+
assert_that(str(ex)).is_equal_to('Expected <24> to be multiple of <5>, but was not.')
99+
100+
def test_is_multiple_of_extension_failure_not_integer():
101+
try:
102+
add_extension(is_multiple_of)
103+
assert_that(24.0).is_multiple_of(5)
104+
fail('should have raised error')
105+
except TypeError as ex:
106+
assert_that(str(ex)).is_equal_to('val must be an integer')
107+
108+
def test_is_multiple_of_extension_failure_arg_not_integer():
109+
try:
110+
add_extension(is_multiple_of)
111+
assert_that(24).is_multiple_of('foo')
112+
fail('should have raised error')
113+
except TypeError as ex:
114+
assert_that(str(ex)).is_equal_to('given arg must be an integer')

0 commit comments

Comments
 (0)