diff options
author | Florian Bruhin <me@the-compiler.org> | 2023-11-22 15:28:20 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2023-11-22 18:02:18 +0100 |
commit | 6b7eb77c4d6f03e75b1a878ddd0915deab409207 (patch) | |
tree | ab6813b000db52b9e524e1dbb7e40e9b3045e575 | |
parent | 9e3d421a15be389ea124cd49c1e43b154b64cc4a (diff) | |
download | qutebrowser-6b7eb77c4d6f03e75b1a878ddd0915deab409207.tar.gz qutebrowser-6b7eb77c4d6f03e75b1a878ddd0915deab409207.zip |
pakjoy: Run black
-rw-r--r-- | qutebrowser/misc/pakjoy.py | 8 | ||||
-rw-r--r-- | tests/unit/misc/test_pakjoy.py | 60 |
2 files changed, 39 insertions, 29 deletions
diff --git a/qutebrowser/misc/pakjoy.py b/qutebrowser/misc/pakjoy.py index ca33245db..71d51d7a6 100644 --- a/qutebrowser/misc/pakjoy.py +++ b/qutebrowser/misc/pakjoy.py @@ -55,10 +55,10 @@ class PakHeader: resource_count: int # uint16 _alias_count: int # uint16 - _FORMAT: ClassVar[str] = '<IHH' + _FORMAT: ClassVar[str] = "<IHH" @classmethod - def parse(cls, fobj: IO[bytes]) -> 'PakHeader': + def parse(cls, fobj: IO[bytes]) -> "PakHeader": """Parse a PAK version 5 header from a file.""" return cls(*binparsing.unpack(cls._FORMAT, fobj)) @@ -72,10 +72,10 @@ class PakEntry: file_offset: int # uint32 size: int = 0 # not in file - _FORMAT: ClassVar[str] = '<HI' + _FORMAT: ClassVar[str] = "<HI" @classmethod - def parse(cls, fobj: IO[bytes]) -> 'PakEntry': + def parse(cls, fobj: IO[bytes]) -> "PakEntry": """Parse a PAK entry from a file.""" return cls(*binparsing.unpack(cls._FORMAT, fobj)) diff --git a/tests/unit/misc/test_pakjoy.py b/tests/unit/misc/test_pakjoy.py index 1ea37f772..326d8adfb 100644 --- a/tests/unit/misc/test_pakjoy.py +++ b/tests/unit/misc/test_pakjoy.py @@ -47,7 +47,7 @@ def patch_version(monkeypatch, *args): webengine=utils.VersionNumber(*args), chromium=None, source="unittest", - ) + ), ) @@ -85,8 +85,7 @@ def json_without_comments(bytestring): str_without_comments = "\n".join( [ line - for line in - bytestring.decode("utf-8").split("\n") + for line in bytestring.decode("utf-8").split("\n") if not line.strip().startswith("//") ] ) @@ -111,9 +110,10 @@ class TestWithRealResourcesFile: json_manifest = json_without_comments(reparsed.manifest) - assert pakjoy.REPLACEMENT_URL.decode("utf-8") in json_manifest[ - "externally_connectable" - ]["matches"] + assert ( + pakjoy.REPLACEMENT_URL.decode("utf-8") + in json_manifest["externally_connectable"]["matches"] + ) def test_copying_resources(self): # Test we managed to copy some files over @@ -141,10 +141,14 @@ class TestWithRealResourcesFile: def raiseme(err): raise err - monkeypatch.setattr(pakjoy.shutil, osfunc, lambda *_args: raiseme(PermissionError(osfunc))) + monkeypatch.setattr( + pakjoy.shutil, osfunc, lambda *_args: raiseme(PermissionError(osfunc)) + ) with caplog.at_level(logging.ERROR, "misc"): pakjoy.patch_webengine() - assert caplog.messages == ["Failed to copy webengine resources, not applying quirk"] + assert caplog.messages == [ + "Failed to copy webengine resources, not applying quirk" + ] def test_expected_file_not_found(self, tmp_cache, monkeypatch, caplog): with caplog.at_level(logging.ERROR, "misc"): @@ -175,7 +179,9 @@ def json_manifest_factory(extension_id=pakjoy.HANGOUTS_MARKER, url=pakjoy.TARGET ] }} }} - """.strip().encode("utf-8") + """.strip().encode( + "utf-8" + ) def pak_factory(version=5, entries=None, encoding=1, sentinel_position=-1): @@ -221,9 +227,10 @@ class TestWithConstructedResourcesFile: json_manifest = json_without_comments(parser.manifest) - assert pakjoy.TARGET_URL.decode("utf-8") in json_manifest[ - "externally_connectable" - ]["matches"] + assert ( + pakjoy.TARGET_URL.decode("utf-8") + in json_manifest["externally_connectable"]["matches"] + ) def test_bad_version(self): buffer = pak_factory(version=99) @@ -234,20 +241,26 @@ class TestWithConstructedResourcesFile: ): pakjoy.PakParser(buffer) - @pytest.mark.parametrize("position, error", [ - (0, "Unexpected sentinel entry"), - (None, "Missing sentinel entry"), - ]) + @pytest.mark.parametrize( + "position, error", + [ + (0, "Unexpected sentinel entry"), + (None, "Missing sentinel entry"), + ], + ) def test_bad_sentinal_position(self, position, error): buffer = pak_factory(sentinel_position=position) with pytest.raises(binparsing.ParseError): pakjoy.PakParser(buffer) - @pytest.mark.parametrize("entry", [ - b"{foo}", - b"V2VsbCBoZWxsbyB0aGVyZQo=", - ]) + @pytest.mark.parametrize( + "entry", + [ + b"{foo}", + b"V2VsbCBoZWxsbyB0aGVyZQo=", + ], + ) def test_marker_not_found(self, entry): buffer = pak_factory(entries=[entry]) @@ -267,8 +280,7 @@ class TestWithConstructedResourcesFile: ): parser.find_patch_offset() - def test_url_not_found_high_level(self, tmp_cache, caplog, - affected_version): + def test_url_not_found_high_level(self, tmp_cache, caplog, affected_version): buffer = pak_factory(entries=[json_manifest_factory(url=b"example.com")]) # Write bytes to file so we can test pakjoy._patch() @@ -279,6 +291,4 @@ class TestWithConstructedResourcesFile: with caplog.at_level(logging.ERROR, "misc"): pakjoy._patch(tmpfile) - assert caplog.messages == [ - "Failed to apply quirk to resources pak." - ] + assert caplog.messages == ["Failed to apply quirk to resources pak."] |