]> Cypherpunks repositories - keks.git/commitdiff
More understandable naming of context manager's variable
authorSergey Matveev <stargrave@stargrave.org>
Sat, 30 Nov 2024 16:40:56 +0000 (19:40 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 30 Nov 2024 19:38:56 +0000 (22:38 +0300)
"cm" just tells that it is "context manager". "class Class" is similar.
"err" can be more appropriate name, telling that it holds something
related to the error.

pyac/tests/test_blob.py
pyac/tests/test_float.py
pyac/tests/test_generic.py
pyac/tests/test_int.py
pyac/tests/test_list.py
pyac/tests/test_map.py
pyac/tests/test_str.py
pyac/tests/test_tai.py

index 697a8bee99127163a28b368eae309f0a3a8712f6b4682bb9c1b05ce9ffdcfeff..12de3d473c86ff5d6321bf105b62a6628e117f5611502e61a9d6da92ad90dc2b 100644 (file)
@@ -28,24 +28,24 @@ class TestBlob(TestCase):
 
     def test_throws_when_not_enough_data(self) -> None:
         encoded = b"\x0B\x00\x00\x00\x00\x00\x00\x00\x03\x01test\x01da"
-        with self.assertRaises(NotEnoughData) as cm:
+        with self.assertRaises(NotEnoughData) as err:
             loads(encoded)
-        self.assertEqual(cm.exception.n, 4)
+        self.assertEqual(err.exception.n, 4)
 
     def test_throws_when_not_enough_data_for_length(self) -> None:
         encoded = b"\x0B\x00\x00\x00\x00"
-        with self.assertRaises(NotEnoughData) as cm:
+        with self.assertRaises(NotEnoughData) as err:
             loads(encoded)
-        self.assertEqual(cm.exception.n, 9)
+        self.assertEqual(err.exception.n, 9)
 
     def test_throws_when_wrong_terminator_length(self) -> None:
         encoded = b"\x0B\x00\x00\x00\x00\x00\x00\x00\x03\x01test\x01data\x8Aterminator"
-        with self.assertRaises(DecodeError) as cm:
+        with self.assertRaises(DecodeError) as err:
             loads(encoded)
-        self.assertEqual(str(cm.exception), "wrong terminator len")
+        self.assertEqual(str(err.exception), "wrong terminator len")
 
     def test_throws_when_wrong_terminator_tag(self) -> None:
         encoded = b"\x0B\x00\x00\x00\x00\x00\x00\x00\x03\x01test\x01data\x04that was a wrong tag"
-        with self.assertRaises(DecodeError) as cm:
+        with self.assertRaises(DecodeError) as err:
             loads(encoded)
-        self.assertEqual(str(cm.exception), "unexpected tag")
+        self.assertEqual(str(err.exception), "unexpected tag")
index 17197f42046914160ce9df5c0a9a42832efe06414321f6da5350a612f81be517..be0405252c59b07125425420941e7a16b6ab38a7458f50f81c62f70db5226b08 100644 (file)
@@ -9,9 +9,9 @@ from pyac import Raw
 
 class TestFloat(TestCase):
     def test_throws_when_dumps_float(self) -> None:
-        with self.assertRaises(NotImplementedError) as cm:
+        with self.assertRaises(NotImplementedError) as err:
             dumps(1.5)
-        self.assertEqual(str(cm.exception), "no FLOAT* support")
+        self.assertEqual(str(err.exception), "no FLOAT* support")
 
     def test_float_loads(self) -> None:
         floats: List[bytes] = [
index 1c5a792257ba228b841ce3c5a26404a88927f1d1f671014e07b8d278cf07fd88..3001b67786ba9440d13bff2caab0454ee049695b814372c9af1eef5d9b376cbc 100644 (file)
@@ -8,18 +8,18 @@ from pyac import NotEnoughData
 
 class TestUnknownType(TestCase):
     def runTest(self) -> None:
-        with self.assertRaises(NotImplementedError) as cm:
+        with self.assertRaises(NotImplementedError) as err:
             class A:
                 pass
             dumps(A())
-        self.assertEqual(str(cm.exception), "unsupported type")
+        self.assertEqual(str(err.exception), "unsupported type")
 
 
 class TestUnknownTag(TestCase):
     def runTest(self) -> None:
-        with self.assertRaises(DecodeError) as cm:
+        with self.assertRaises(DecodeError) as err:
             loads(b"\x05")
-        self.assertEqual(str(cm.exception), "unknown tag")
+        self.assertEqual(str(err.exception), "unknown tag")
 
 
 class TestEmptyData(TestCase):
index 145bb4290f08fa1d3c818c717b29fead576b1728a9f49151b8b305bea5ad30b9..df829a9851aa33cf73e3fd9fc8bb3184781e80aa12abe107cf8491ac0af7230e 100644 (file)
@@ -44,18 +44,18 @@ class TestInt(TestCase):
 
     def test_int_decode_not_enough_data(self) -> None:
         encoded: bytes = b"\x0C\x81"
-        with self.assertRaises(NotEnoughData) as cm:
+        with self.assertRaises(NotEnoughData) as err:
             loads(encoded)
-        self.assertEqual(cm.exception.n, 2)
+        self.assertEqual(err.exception.n, 2)
 
     def test_throws_when_unminimal_int(self) -> None:
-        with self.assertRaises(DecodeError) as cm:
+        with self.assertRaises(DecodeError) as err:
             encoded: bytes = b"\x0C\x81\x00\x7B"
             loads(encoded)
-        self.assertEqual(str(cm.exception), "non-minimal encoding")
+        self.assertEqual(str(err.exception), "non-minimal encoding")
 
     def test_throws_when_non_bin_in_int(self) -> None:
-        with self.assertRaises(DecodeError) as cm:
+        with self.assertRaises(DecodeError) as err:
             encoded: bytes = b"\x0C\x01\x7B"
             loads(encoded)
-        self.assertEqual(str(cm.exception), "non-BIN in INT")
+        self.assertEqual(str(err.exception), "non-BIN in INT")
index 3b102a15ab269404feee9244b69fa9889264df28daefe9e0f55d786fe8fc012f..b7173933cb44b613921509d2e7b2675fdf21ba5fc437c06bd79bdf4aac04c2f3 100644 (file)
@@ -39,6 +39,6 @@ class TestList(TestCase):
     @given(lists(any_st, max_size=4))
     def test_no_eoc(self, test_list: List) -> None:
         encoded = dumps(test_list)[:-1]
-        with self.assertRaises(NotEnoughData) as cm:
+        with self.assertRaises(NotEnoughData) as err:
             loads(encoded)
-        self.assertEqual(cm.exception.n, 1)
+        self.assertEqual(err.exception.n, 1)
index caf27186d485e99d8d067b76a3886a606413559d601a6c64c73fdef7edf2576f..1a9217f64c0085145a5da24310501448169f85f1489b46faea2cf8382e835002 100644 (file)
@@ -65,34 +65,34 @@ class TestMap(TestCase):
 
     def test_map_throws_when_decoding_unsorted_keys(self):
         encoded = b"\x09\xc4key2\x0c\x81\x01\xc4key1\xc6value1\x00"
-        with self.assertRaises(DecodeError) as cm:
+        with self.assertRaises(DecodeError) as err:
             loads(encoded)
-        self.assertEqual(str(cm.exception), "unsorted keys")
+        self.assertEqual(str(err.exception), "unsorted keys")
 
     def test_map_throws_when_encoding_non_string_key(self):
-        with self.assertRaises(ValueError) as cm:
+        with self.assertRaises(ValueError) as err:
             dumps({1: "a"})
-        self.assertEqual(str(cm.exception), "map keys can contain only strings")
+        self.assertEqual(str(err.exception), "map keys can contain only strings")
 
     def test_map_throws_when_decoding_non_string_key(self):
         encoded = b"\x09\x0c\x80\xc6value2\x00"
-        with self.assertRaises(DecodeError) as cm:
+        with self.assertRaises(DecodeError) as err:
             loads(encoded)
-        self.assertEqual(str(cm.exception), "non-string key")
+        self.assertEqual(str(err.exception), "non-string key")
 
     def test_map_throws_when_unexpected_eoc(self):
         encoded = b"\x09\xc4key1\x00\x00"
-        with self.assertRaises(DecodeError) as cm:
+        with self.assertRaises(DecodeError) as err:
             decoded, tail = loads(encoded)
-        self.assertEqual(str(cm.exception), "unexpected EOC")
+        self.assertEqual(str(err.exception), "unexpected EOC")
 
     def test_map_throws_when_encoding_empty_str_as_key(self):
-        with self.assertRaises(ValueError) as cm:
+        with self.assertRaises(ValueError) as err:
             dumps({"": "a"})
-        self.assertEqual(str(cm.exception), "map keys can not be empty")
+        self.assertEqual(str(err.exception), "map keys can not be empty")
 
     def test_map_throws_when_decoding_empty_str_as_key(self):
         encoded = b"\x09\xc0\x0c\x81\x01\xc4key1\xc6value1\x00"
-        with self.assertRaises(DecodeError) as cm:
+        with self.assertRaises(DecodeError) as err:
             decoded, tail = loads(encoded)
-        self.assertEqual(str(cm.exception), "empty key")
+        self.assertEqual(str(err.exception), "empty key")
index d51d733ae83053daa57ae7321b4e2b51e7150e10e76b982d7b2518ecf3c0f6c3..ae1d8fc6fc9dcd6ced3e4a9f6eceff85d9681c600eb1c67e43217e65021912cd 100644 (file)
@@ -60,32 +60,32 @@ class TestString(TestCase):
 
     def test_throws_when_not_enough_data(self) -> None:
         encoded = b"\x85he"
-        with self.assertRaises(NotEnoughData) as cm:
+        with self.assertRaises(NotEnoughData) as err:
             loads(encoded)
-        self.assertEqual(cm.exception.n, 6)
+        self.assertEqual(err.exception.n, 6)
 
     def test_throws_when_not_enough_data_for_length(self) -> None:
         long_string = "a" * 318
         encoded = dumps(long_string)[:2]
-        with self.assertRaises(NotEnoughData) as cm:
+        with self.assertRaises(NotEnoughData) as err:
             loads(encoded)
-        self.assertEqual(cm.exception.n, 3)
+        self.assertEqual(err.exception.n, 3)
 
     def test_throws_when_null_byte_in_utf(self) -> None:
-        with self.assertRaises(DecodeError) as cm:
+        with self.assertRaises(DecodeError) as err:
             result, tail = loads(b"\xc5he\x00\x01\x02")
-        self.assertEqual(str(cm.exception), "null byte in UTF-8")
+        self.assertEqual(str(err.exception), "null byte in UTF-8")
 
     @given(invalid_utf8_2byte_s)
     def test_throws_when_invalid_utf_2bytes(self, invalid_utf: bytes) -> None:
-        with self.assertRaises(DecodeError) as cm:
+        with self.assertRaises(DecodeError) as err:
             encoded = dumps("hello")[:-1] + invalid_utf
             result, tail = loads(encoded)
-        self.assertEqual(str(cm.exception), "invalid UTF-8")
+        self.assertEqual(str(err.exception), "invalid UTF-8")
 
     @given(invalid_utf8_3byte_s)
     def test_throws_when_invalid_utf_3bytes(self, invalid_utf: bytes) -> None:
-        with self.assertRaises(DecodeError) as cm:
+        with self.assertRaises(DecodeError) as err:
             encoded = dumps("hello")[:-2] + invalid_utf
             result, tail = loads(encoded)
-        self.assertEqual(str(cm.exception), "invalid UTF-8")
+        self.assertEqual(str(err.exception), "invalid UTF-8")
index d9311c600bead8f36d468a4e9786f6c2e685c337e7d6cbeb5f04b1c22a910ee1..39972f90346538b218c4302c44e273e582e62ecb5ab9979ee370c8e0f1dc99ac 100644 (file)
@@ -107,21 +107,21 @@ class TestTAI64(TestCase):
         self.assertSequenceEqual(tail, b"")
 
     def test_throws_when_first_bit_is_in_use(self) -> None:
-        with self.assertRaises(DecodeError) as cm:
+        with self.assertRaises(DecodeError) as err:
             loads(b"\x18\x80\x00\x00\x00\x65\x19\x5f\x65")
-        self.assertEqual(str(cm.exception), "reserved TAI64 value is in use")
+        self.assertEqual(str(err.exception), "reserved TAI64 value is in use")
 
     def test_throws_when_too_many_nanosecs(self) -> None:
-        with self.assertRaises(DecodeError) as cm:
+        with self.assertRaises(DecodeError) as err:
             loads(b"\x19\x40\x00\x00\x00\x65\x19\x5f\x65" + (999999999 + 1).to_bytes(4, "big"))
-        self.assertEqual(str(cm.exception), "too many nanoseconds")
+        self.assertEqual(str(err.exception), "too many nanoseconds")
 
     def test_throws_when_too_many_attosecs(self) -> None:
-        with self.assertRaises(DecodeError) as cm:
+        with self.assertRaises(DecodeError) as err:
             loads(
                 b"\x1A\x40\x00\x00\x00\x65\x19\x5f\x65\x07\x5b\xca\x00\xA7\x5b\xca\x00"
             )
-        self.assertEqual(str(cm.exception), "too many attoseconds")
+        self.assertEqual(str(err.exception), "too many attoseconds")
 
     def test_leapseconds_match_DJB(self) -> None:
         """Check that our pyac.Leapsecs is equally calculated to DJB's