|
16 | 16 | # limitations under the License. |
17 | 17 |
|
18 | 18 |
|
19 | | -from unittest import TestCase |
| 19 | +import pytest |
20 | 20 |
|
21 | 21 | from neo4j.time import ( |
22 | 22 | ClockTime, |
23 | 23 | Duration, |
24 | 24 | ) |
25 | 25 |
|
26 | 26 |
|
27 | | -class TestClockTime(TestCase): |
| 27 | +class TestClockTime: |
28 | 28 |
|
29 | 29 | def test_zero_(self): |
30 | 30 | ct = ClockTime() |
31 | | - self.assertEqual(ct.seconds, 0) |
32 | | - self.assertEqual(ct.nanoseconds, 0) |
| 31 | + assert ct.seconds == 0 |
| 32 | + assert ct.nanoseconds == 0 |
33 | 33 |
|
34 | 34 | def test_only_seconds(self): |
35 | 35 | ct = ClockTime(123456) |
36 | | - self.assertEqual(ct.seconds, 123456) |
37 | | - self.assertEqual(ct.nanoseconds, 0) |
| 36 | + assert ct.seconds == 123456 |
| 37 | + assert ct.nanoseconds == 0 |
38 | 38 |
|
39 | 39 | def test_float(self): |
40 | 40 | ct = ClockTime(123456.789) |
41 | | - self.assertEqual(ct.seconds, 123456) |
42 | | - self.assertEqual(ct.nanoseconds, 789000000) |
| 41 | + assert ct.seconds == 123456 |
| 42 | + assert ct.nanoseconds == 789000000 |
43 | 43 |
|
44 | 44 | def test_only_nanoseconds(self): |
45 | 45 | ct = ClockTime(0, 123456789) |
46 | | - self.assertEqual(ct.seconds, 0) |
47 | | - self.assertEqual(ct.nanoseconds, 123456789) |
| 46 | + assert ct.seconds == 0 |
| 47 | + assert ct.nanoseconds == 123456789 |
48 | 48 |
|
49 | 49 | def test_nanoseconds_overflow(self): |
50 | 50 | ct = ClockTime(0, 2123456789) |
51 | | - self.assertEqual(ct.seconds, 2) |
52 | | - self.assertEqual(ct.nanoseconds, 123456789) |
| 51 | + assert ct.seconds == 2 |
| 52 | + assert ct.nanoseconds == 123456789 |
53 | 53 |
|
54 | 54 | def test_positive_nanoseconds(self): |
55 | 55 | ct = ClockTime(1, 1) |
56 | | - self.assertEqual(ct.seconds, 1) |
57 | | - self.assertEqual(ct.nanoseconds, 1) |
| 56 | + assert ct.seconds == 1 |
| 57 | + assert ct.nanoseconds == 1 |
58 | 58 |
|
59 | 59 | def test_negative_nanoseconds(self): |
60 | 60 | ct = ClockTime(1, -1) |
61 | | - self.assertEqual(ct.seconds, 0) |
62 | | - self.assertEqual(ct.nanoseconds, 999999999) |
| 61 | + assert ct.seconds == 0 |
| 62 | + assert ct.nanoseconds == 999999999 |
63 | 63 |
|
64 | 64 | def test_add_float(self): |
65 | 65 | ct = ClockTime(123456.789) + 0.1 |
66 | | - self.assertEqual(ct.seconds, 123456) |
67 | | - self.assertEqual(ct.nanoseconds, 889000000) |
| 66 | + assert ct.seconds == 123456 |
| 67 | + assert ct.nanoseconds == 889000000 |
68 | 68 |
|
69 | 69 | def test_add_duration(self): |
70 | 70 | ct = ClockTime(123456.789) + Duration(seconds=1) |
71 | | - self.assertEqual(ct.seconds, 123457) |
72 | | - self.assertEqual(ct.nanoseconds, 789000000) |
| 71 | + assert ct.seconds == 123457 |
| 72 | + assert ct.nanoseconds == 789000000 |
73 | 73 |
|
74 | 74 | def test_add_duration_with_months(self): |
75 | | - with self.assertRaises(ValueError): |
| 75 | + with pytest.raises(ValueError): |
76 | 76 | _ = ClockTime(123456.789) + Duration(months=1) |
77 | 77 |
|
78 | 78 | def test_add_object(self): |
79 | | - with self.assertRaises(TypeError): |
| 79 | + with pytest.raises(TypeError): |
80 | 80 | _ = ClockTime(123456.789) + object() |
81 | 81 |
|
82 | 82 | def test_sub_float(self): |
83 | 83 | ct = ClockTime(123456.789) - 0.1 |
84 | | - self.assertEqual(ct.seconds, 123456) |
85 | | - self.assertEqual(ct.nanoseconds, 689000000) |
| 84 | + assert ct.seconds == 123456 |
| 85 | + assert ct.nanoseconds == 689000000 |
86 | 86 |
|
87 | 87 | def test_sub_duration(self): |
88 | 88 | ct = ClockTime(123456.789) - Duration(seconds=1) |
89 | | - self.assertEqual(ct.seconds, 123455) |
90 | | - self.assertEqual(ct.nanoseconds, 789000000) |
| 89 | + assert ct.seconds == 123455 |
| 90 | + assert ct.nanoseconds == 789000000 |
91 | 91 |
|
92 | 92 | def test_sub_duration_with_months(self): |
93 | | - with self.assertRaises(ValueError): |
| 93 | + with pytest.raises(ValueError): |
94 | 94 | _ = ClockTime(123456.789) - Duration(months=1) |
95 | 95 |
|
96 | 96 | def test_sub_object(self): |
97 | | - with self.assertRaises(TypeError): |
| 97 | + with pytest.raises(TypeError): |
98 | 98 | _ = ClockTime(123456.789) - object() |
99 | 99 |
|
100 | 100 | def test_repr(self): |
101 | 101 | ct = ClockTime(123456.789) |
102 | | - self.assertTrue(repr(ct).startswith("ClockTime")) |
| 102 | + assert repr(ct).startswith("ClockTime") |
0 commit comments