diff --git a/pytox/common.py b/pytox/common.py index ad6190d..83794d5 100644 --- a/pytox/common.py +++ b/pytox/common.py @@ -30,6 +30,5 @@ def check_len(name: str, data: T, expected_length: int) -> T: if len(data) < expected_length: raise LengthException( f"parameter '{name}' received bytes of invalid" - f"length {len(data)}, expected at least {expected_length}" - ) + f"length {len(data)}, expected at least {expected_length}") return data diff --git a/test/auto_tests/self_connection_status_test.py b/test/auto_tests/self_connection_status_test.py index d5e1087..e3115c0 100644 --- a/test/auto_tests/self_connection_status_test.py +++ b/test/auto_tests/self_connection_status_test.py @@ -13,9 +13,9 @@ class TestException(Exception): class TestTox(core.Tox_Ptr): connection_status_from_cb = core.TOX_CONNECTION_NONE - def handle_self_connection_status( - self, connection_status: core.Tox_Connection - ) -> None: + def handle_self_connection_status(self, + connection_status: core.Tox_Connection + ) -> None: print(connection_status) self.connection_status_from_cb = connection_status raise TestException(connection_status) @@ -27,16 +27,14 @@ def test_connection_status_cb(self) -> None: with TestTox() as tox2: # Test that exceptions can pass through C code. with self.assertRaises(TestException) as ex: - while ( - tox1.connection_status == core.TOX_CONNECTION_NONE - or tox2.connection_status == core.TOX_CONNECTION_NONE - ): + while (tox1.connection_status == core.TOX_CONNECTION_NONE + or + tox2.connection_status == core.TOX_CONNECTION_NONE): tox1.iterate() tox2.iterate() time.sleep(tox1.iteration_interval / 1000) - self.assertEqual( - tox1.connection_status, tox1.connection_status_from_cb - ) + self.assertEqual(tox1.connection_status, + tox1.connection_status_from_cb) self.assertEqual(ex.exception.status, tox1.connection_status) diff --git a/test/toxencryptsave_test.py b/test/toxencryptsave_test.py index d6bc425..aad39ec 100644 --- a/test/toxencryptsave_test.py +++ b/test/toxencryptsave_test.py @@ -8,23 +8,22 @@ class ToxencryptsaveTest(unittest.TestCase): def test_encrypt_decrypt(self) -> None: with c.Tox_Pass_Key_Ptr(b"hello") as pk: self.assertNotEqual(pk.encrypt(b"hello world"), b"hello world") - self.assertEqual(pk.decrypt(pk.encrypt(b"hello world")), b"hello world") + self.assertEqual(pk.decrypt(pk.encrypt(b"hello world")), + b"hello world") def test_encrypt_decrypt_with_correct_salt(self) -> None: with c.Tox_Pass_Key_Ptr(b"hello", b"a" * 32) as pk1: with c.Tox_Pass_Key_Ptr(b"hello", b"a" * 32) as pk2: - self.assertEqual( - pk2.decrypt(pk1.encrypt(b"hello world")), b"hello world" - ) + self.assertEqual(pk2.decrypt(pk1.encrypt(b"hello world")), + b"hello world") def test_encrypt_decrypt_with_wrong_salt(self) -> None: with c.Tox_Pass_Key_Ptr(passphrase=b"hello", salt=b"a" * 32) as pk1: with c.Tox_Pass_Key_Ptr(b"hello", b"b" * 32) as pk2: with self.assertRaises(c.ApiException) as ex: pk2.decrypt(pk1.encrypt(b"hello world")) - self.assertEqual( - ex.exception.error.name, c.TOX_ERR_DECRYPTION_FAILED.name - ) + self.assertEqual(ex.exception.error.name, + c.TOX_ERR_DECRYPTION_FAILED.name) def test_salt_too_small(self) -> None: with self.assertRaises(common.LengthException): diff --git a/tools/stubgen.py b/tools/stubgen.py index 26a1308..a83acfa 100644 --- a/tools/stubgen.py +++ b/tools/stubgen.py @@ -15,7 +15,8 @@ ] -def process_class(name: str, cls: list[str], imports: set[str], attr: object) -> None: +def process_class(name: str, cls: list[str], imports: set[str], + attr: object) -> None: for mem in dir(attr): mem_attr = getattr(attr, mem) if mem == "__enter__": @@ -26,10 +27,8 @@ def process_class(name: str, cls: list[str], imports: set[str], attr: object) -> cls.append( " def __exit__(self, exc_type: type[BaseException] | None, exc_value: BaseException | None, exc_traceback: TracebackType | None) -> None: ..." ) - elif ( - mem == "__init__" - or "cython_function_or_method" in mem_attr.__class__.__name__ - ): + elif (mem == "__init__" + or "cython_function_or_method" in mem_attr.__class__.__name__): doc = mem_attr.__doc__.split("\n")[0] if " -> " not in doc: doc += " -> None" @@ -62,15 +61,14 @@ def main() -> None: continue if isinstance(attr, pytox.common.__class__): continue - if ( - hasattr(attr, "__module__") - and f"{prefix}.{attr.__module__}" != pkg.__name__ - ): + if (hasattr(attr, "__module__") + and f"{prefix}.{attr.__module__}" != pkg.__name__): continue attrs.append((sym, attr)) consts: list[str] = [] - classes: collections.OrderedDict[str, list[str]] = collections.OrderedDict() + classes: collections.OrderedDict[ + str, list[str]] = collections.OrderedDict() imports: set[str] = set() missing: set[str] = { "Tox_Conference_Number", @@ -106,7 +104,8 @@ def main() -> None: for sym, attr in attrs: if isinstance(attr, int): - enum = tuple(c for c in classes.keys() if sym.startswith(c.upper())) + enum = tuple(c for c in classes.keys() + if sym.startswith(c.upper())) if enum: consts.append(f"{sym}: {enum[0]}") else: @@ -119,8 +118,8 @@ def main() -> None: raise Exception(f"nope {sym}: {type(attr)}") with open( - os.path.join(out_dir, f"{pkg.__name__.replace('.', '/')}.pyi"), "w" - ) as pyi: + os.path.join(out_dir, f"{pkg.__name__.replace('.', '/')}.pyi"), + "w") as pyi: pyi.write(f"# {pkg.__name__}\n") for s in sorted(imports): pyi.write(s + "\n")