-
Notifications
You must be signed in to change notification settings - Fork 17
/
test_represent.py
35 lines (27 loc) · 1.01 KB
/
test_represent.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
#!/usr/bin/env python3
# pylint: disable=missing-docstring,invalid-name,too-many-public-methods,no-self-use
# pylint: disable=unused-argument
import textwrap
import unittest
from typing import Optional # pylint: disable=unused-import
import icontract._represent
import tests.error
import tests.mock
class TestReprValues(unittest.TestCase):
def test_named_expression(self) -> None:
@icontract.require(lambda x: (t := x + 1) and t > 1) # pylint: disable=undefined-variable
def func(x: int) -> int:
return x
violation_err = None # type: Optional[icontract.ViolationError]
try:
func(x=0)
except icontract.ViolationError as err:
violation_err = err
self.assertIsNotNone(violation_err)
self.assertEqual(
textwrap.dedent('''\
(t := x + 1) and t > 1:
t was 1
x was 0'''), tests.error.wo_mandatory_location(str(violation_err)))
if __name__ == '__main__':
unittest.main()