| 1 |
From: Benjamin Drung <[email protected]> |
| 2 |
Date: Fri, 15 Dec 2023 14:26:33 +0100 |
| 3 |
Subject: test: support Python 3.12 |
| 4 |
|
| 5 |
Python 3.12 dropped `TestCase.assertDictContainsSubset` and |
| 6 |
`TestCase.assertRaisesRegexp`. |
| 7 |
|
| 8 |
Bug-Debian: https://bugs.debian.org/1055554 |
| 9 |
Forwarded: https://github.com/schwehr/libais/pull/246 |
| 10 |
--- |
| 11 |
test/compatibility/gpsd_test.py | 14 +++++++++++--- |
| 12 |
test/test_decode.py | 4 ++-- |
| 13 |
2 files changed, 13 insertions(+), 5 deletions(-) |
| 14 |
|
| 15 |
diff --git a/test/compatibility/gpsd_test.py b/test/compatibility/gpsd_test.py |
| 16 |
index 61d69fc..c2b1140 100644 |
| 17 |
--- a/test/compatibility/gpsd_test.py |
| 18 |
+++ b/test/compatibility/gpsd_test.py |
| 19 |
@@ -32,6 +32,14 @@ class SingleMessageTestsTest(unittest.TestCase): |
| 20 |
def setUp(self): |
| 21 |
self.mangle = ais.compatibility.gpsd.Mangler() |
| 22 |
|
| 23 |
+ def assertDictContainsSubset2(self, actual, expected): |
| 24 |
+ # assertDictContainsSubset was deprecated because of incorrect arg order. |
| 25 |
+ # This method has the correct order. |
| 26 |
+ self.assertIsInstance(expected, dict) |
| 27 |
+ self.assertIsInstance(actual, dict) |
| 28 |
+ for key, value in expected.items(): |
| 29 |
+ self.assertEqual(actual[key], value, 'kv: %s, %s' % (key, value)) |
| 30 |
+ |
| 31 |
def testMsg1(self): |
| 32 |
fields = '!AIVDM,1,1,,B,169A91O005KbT4gUoUl9d;5j0D0U,0*2D'.split(',') |
| 33 |
decoded = ais.decode(fields[5], int(fields[6][0])) |
| 34 |
@@ -50,7 +58,7 @@ class SingleMessageTestsTest(unittest.TestCase): |
| 35 |
'second': 57, |
| 36 |
'maneuver': 0, |
| 37 |
'raim': False} |
| 38 |
- self.assertDictContainsSubset(expected, mangled) |
| 39 |
+ self.assertDictContainsSubset2(mangled, expected) |
| 40 |
|
| 41 |
# Float values will not match, so just test existence. |
| 42 |
for field in ('lat', 'lon'): |
| 43 |
@@ -69,7 +77,7 @@ class SingleMessageTestsTest(unittest.TestCase): |
| 44 |
'shiptype': 204, |
| 45 |
'shiptype_text': '204 - Unknown', |
| 46 |
'type': 5} |
| 47 |
- self.assertDictContainsSubset(expected, mangled) |
| 48 |
+ self.assertDictContainsSubset2(mangled, expected) |
| 49 |
|
| 50 |
def testTimestamps(self): |
| 51 |
msg = { |
| 52 |
@@ -89,7 +97,7 @@ class SingleMessageTestsTest(unittest.TestCase): |
| 53 |
'timestamp': '2015-05-15T09:27:23Z', |
| 54 |
'tagblock_timestamp': '2015-05-15T09:27:23.000000Z' |
| 55 |
} |
| 56 |
- self.assertDictContainsSubset(expected, mangled) |
| 57 |
+ self.assertDictContainsSubset2(mangled, expected) |
| 58 |
|
| 59 |
|
| 60 |
class StreamingTest(unittest.TestCase): |
| 61 |
diff --git a/test/test_decode.py b/test/test_decode.py |
| 62 |
index 8167165..8f6d033 100644 |
| 63 |
--- a/test/test_decode.py |
| 64 |
+++ b/test/test_decode.py |
| 65 |
@@ -33,8 +33,8 @@ class Ais6Decoders(unittest.TestCase): |
| 66 |
def testDecodeUnknownMessage6(self): |
| 67 |
# !AIVDM,1,1,,B,6B?n;be:cbapalgc;i6?Ow4,2*4A' |
| 68 |
# TODO(schwehr): Expose the C++ Python exception to Python. |
| 69 |
- self.assertRaisesRegexp(ais.DecodeError, '6:669:11', |
| 70 |
- ais.decode, '6B?n;be:cbapalgc;i6?Ow4', 2) |
| 71 |
+ self.assertRaisesRegex(ais.DecodeError, '6:669:11', |
| 72 |
+ ais.decode, '6B?n;be:cbapalgc;i6?Ow4', 2) |
| 73 |
|
| 74 |
if __name__=='__main__': |
| 75 |
unittest.main() |