|
1 | 1 | import datetime
|
2 | 2 | import unittest
|
3 | 3 |
|
| 4 | +from sys import version_info |
| 5 | + |
4 | 6 | import odml.dtypes as typ
|
5 | 7 |
|
6 | 8 |
|
7 | 9 | class TestTypes(unittest.TestCase):
|
8 | 10 |
|
| 11 | + def assertLocalRegExp(self, text, regular_expression): |
| 12 | + """ |
| 13 | + Python 2 is dead and assertRegexpMatches is deprecated and |
| 14 | + will be removed, but keep compatibility until py 2 support is |
| 15 | + fully dropped. |
| 16 | + """ |
| 17 | + |
| 18 | + if version_info.major < 3: |
| 19 | + self.assertRegexpMatches(text, regular_expression) |
| 20 | + else: |
| 21 | + self.assertRegex(text, regular_expression) |
| 22 | + |
9 | 23 | def setUp(self):
|
10 | 24 | pass
|
11 | 25 |
|
@@ -36,8 +50,8 @@ def test_date(self):
|
36 | 50 | self.assertIsInstance(typ.date_get(""), datetime.date)
|
37 | 51 |
|
38 | 52 | re = "^[0-9]{4}-(0[1-9]|1[0-2])-([0-2][0-9]|3[0-1])$"
|
39 |
| - self.assertRegexpMatches(typ.date_get(None).strftime(typ.FORMAT_DATE), re) |
40 |
| - self.assertRegexpMatches(typ.date_get("").strftime(typ.FORMAT_DATE), re) |
| 53 | + self.assertLocalRegExp(typ.date_get(None).strftime(typ.FORMAT_DATE), re) |
| 54 | + self.assertLocalRegExp(typ.date_get("").strftime(typ.FORMAT_DATE), re) |
41 | 55 |
|
42 | 56 | date = datetime.date(2011, 12, 1)
|
43 | 57 | date_string = '2011-12-01'
|
@@ -68,8 +82,8 @@ def test_time(self):
|
68 | 82 | self.assertIsInstance(typ.time_get(""), datetime.time)
|
69 | 83 |
|
70 | 84 | re = "^[0-5][0-9]:[0-5][0-9]:[0-5][0-9]$"
|
71 |
| - self.assertRegexpMatches(typ.time_get(None).strftime(typ.FORMAT_TIME), re) |
72 |
| - self.assertRegexpMatches(typ.time_get("").strftime(typ.FORMAT_TIME), re) |
| 85 | + self.assertLocalRegExp(typ.time_get(None).strftime(typ.FORMAT_TIME), re) |
| 86 | + self.assertLocalRegExp(typ.time_get("").strftime(typ.FORMAT_TIME), re) |
73 | 87 |
|
74 | 88 | time = datetime.time(12, 34, 56)
|
75 | 89 | time_string = '12:34:56'
|
@@ -101,8 +115,8 @@ def test_datetime(self):
|
101 | 115 |
|
102 | 116 | re = "^[0-9]{4}-(0[1-9]|1[0-2])-([0-2][0-9]|3[0-1]) " \
|
103 | 117 | "[0-5][0-9]:[0-5][0-9]:[0-5][0-9]$"
|
104 |
| - self.assertRegexpMatches(typ.datetime_get(None).strftime(typ.FORMAT_DATETIME), re) |
105 |
| - self.assertRegexpMatches(typ.datetime_get("").strftime(typ.FORMAT_DATETIME), re) |
| 118 | + self.assertLocalRegExp(typ.datetime_get(None).strftime(typ.FORMAT_DATETIME), re) |
| 119 | + self.assertLocalRegExp(typ.datetime_get("").strftime(typ.FORMAT_DATETIME), re) |
106 | 120 |
|
107 | 121 | date = datetime.datetime(2011, 12, 1, 12, 34, 56)
|
108 | 122 | date_string = '2011-12-01 12:34:56'
|
@@ -199,10 +213,10 @@ def test_tuple(self):
|
199 | 213 | self.assertEqual(typ.tuple_get("(39.12; 67.19)"), ["39.12", "67.19"])
|
200 | 214 |
|
201 | 215 | # Test fail on missing parenthesis.
|
202 |
| - with self.assertRaises(AssertionError): |
| 216 | + with self.assertRaises(ValueError): |
203 | 217 | _ = typ.tuple_get("fail")
|
204 | 218 | # Test fail on mismatching element count and count number.
|
205 |
| - with self.assertRaises(AssertionError): |
| 219 | + with self.assertRaises(ValueError): |
206 | 220 | _ = typ.tuple_get("(1; 2; 3)", 2)
|
207 | 221 |
|
208 | 222 | def test_dtype_none(self):
|
|
0 commit comments