diff --git a/bin/swh-revhash b/bin/swh-revhash index 56b587d905826efbba8976ae13c5129c567f1663..ad76f9e3b1646b12e9440ffd10b5b1142a77e143 100755 --- a/bin/swh-revhash +++ b/bin/swh-revhash @@ -15,9 +15,7 @@ from swh.model import hashutil, identifiers def revhash(revision_raw): - """Compute the revision hash. - - """ + """Compute the revision hash.""" # HACK: string have somehow their \n expanded to \\n if b"\\n" in revision_raw: revision_raw = revision_raw.replace(b"\\n", b"\n") diff --git a/swh/model/cli.py b/swh/model/cli.py index 583d5c1d221105b97d2707d0bda5b5886d3a76e3..622066199f3144bed63044a3a37ef8d93eb38155 100644 --- a/swh/model/cli.py +++ b/swh/model/cli.py @@ -42,7 +42,7 @@ _DULWICH_TYPES = { class CoreSWHIDParamType(click.ParamType): """Click argument that accepts a core SWHID and returns them as - :class:`swh.model.swhids.CoreSWHID` instances """ + :class:`swh.model.swhids.CoreSWHID` instances""" name = "SWHID" @@ -209,7 +209,10 @@ def identify_object( help="reference identifier to be compared with computed one", ) @click.option( - "-r", "--recursive", is_flag=True, help="compute SWHID recursively", + "-r", + "--recursive", + is_flag=True, + help="compute SWHID recursively", ) @click.argument("objects", nargs=-1, required=True) def identify( diff --git a/swh/model/fields/compound.py b/swh/model/fields/compound.py index 90b4685bafc0b9cf8cac78c87d5a95e521468515..dcdbfd690a1115dc528a232c88f7034a7840ae9b 100644 --- a/swh/model/fields/compound.py +++ b/swh/model/fields/compound.py @@ -27,7 +27,10 @@ def validate_against_schema(model, schema, value): if not isinstance(value, dict): raise ValidationError( "Unexpected type %(type)s for %(model)s, expected dict", - params={"model": model, "type": value.__class__.__name__,}, + params={ + "model": model, + "type": value.__class__.__name__, + }, code="model-unexpected-type", ) diff --git a/swh/model/fields/hashes.py b/swh/model/fields/hashes.py index 9b5ee4ad4ec58d512ced2223f7577d935864b502..46c94ece8ffd352ab8d20e2dd754ffc4e311afca 100644 --- a/swh/model/fields/hashes.py +++ b/swh/model/fields/hashes.py @@ -96,7 +96,9 @@ def validate_hash(value, hash_type): raise ValidationError( "Unexpected type %(type)s for hash, expected str or bytes", - params={"type": value.__class__.__name__,}, + params={ + "type": value.__class__.__name__, + }, code="unexpected-hash-value-type", ) diff --git a/swh/model/fields/simple.py b/swh/model/fields/simple.py index 98fcc118532d075f1de3b43022f0e992bc2d5376..71fe1d708aeb1e935f7c4bd4d4208708301855fa 100644 --- a/swh/model/fields/simple.py +++ b/swh/model/fields/simple.py @@ -18,7 +18,10 @@ def validate_type(value, type): typestr = type.__name__ raise ValidationError( "Unexpected type %(type)s, expected %(expected_type)s", - params={"type": value.__class__.__name__, "expected_type": typestr,}, + params={ + "type": value.__class__.__name__, + "expected_type": typestr, + }, code="unexpected-type", ) diff --git a/swh/model/from_disk.py b/swh/model/from_disk.py index 43a9c7157a9d1bf62e769adeb49679e154b1c844..9ef7afa8b44be4063bc148e75c8a70460a206aec 100644 --- a/swh/model/from_disk.py +++ b/swh/model/from_disk.py @@ -214,8 +214,7 @@ class Content(MerkleLeaf): return obj def swhid(self) -> CoreSWHID: - """Return node identifier as a SWHID - """ + """Return node identifier as a SWHID""" return CoreSWHID(object_type=ObjectType.CONTENT, object_id=self.hash) def __repr__(self): @@ -297,14 +296,14 @@ def extract_regex_objs( root_path: bytes, patterns: Iterable[bytes] ) -> Iterator[Pattern[bytes]]: """Generates a regex object for each pattern given in input and checks if - the path is a subdirectory or relative to the root path. + the path is a subdirectory or relative to the root path. - Args: - root_path (bytes): path to the root directory - patterns (list of byte): patterns to match + Args: + root_path (bytes): path to the root directory + patterns (list of byte): patterns to match - Yields: - an SRE_Pattern object + Yields: + an SRE_Pattern object """ absolute_root_path = os.path.abspath(root_path) for pattern in patterns: @@ -494,8 +493,7 @@ class Directory(MerkleNode): return self.__entries def swhid(self) -> CoreSWHID: - """Return node identifier as a SWHID - """ + """Return node identifier as a SWHID""" return CoreSWHID(object_type=ObjectType.DIRECTORY, object_id=self.hash) def compute_hash(self): diff --git a/swh/model/git_objects.py b/swh/model/git_objects.py index 7b36da641d4ce1d445257c4dca9a222015802591..d0f7bf8481d564729a989267386ee0aa295d4e3b 100644 --- a/swh/model/git_objects.py +++ b/swh/model/git_objects.py @@ -177,7 +177,13 @@ def directory_git_object(directory: Union[Dict, model.Directory]) -> bytes: for entry in sorted(directory.entries, key=directory_entry_sort_key): components.extend( - [_perms_to_bytes(entry.perms), b"\x20", entry.name, b"\x00", entry.target,] + [ + _perms_to_bytes(entry.perms), + b"\x20", + entry.name, + b"\x00", + entry.target, + ] ) return format_git_object_from_parts("tree", components) @@ -564,7 +570,10 @@ def raw_extrinsic_metadata_git_object( b"authority", f"{metadata.authority.type.value} {metadata.authority.url}".encode(), ), - (b"fetcher", f"{metadata.fetcher.name} {metadata.fetcher.version}".encode(),), + ( + b"fetcher", + f"{metadata.fetcher.name} {metadata.fetcher.version}".encode(), + ), (b"format", metadata.format.encode()), ] @@ -620,7 +629,10 @@ def extid_git_object(extid: model.ExtID) -> bytes: headers.append((b"extid_version", str(extid_version).encode("ascii"))) headers.extend( - [(b"extid", extid.extid), (b"target", str(extid.target).encode("ascii")),] + [ + (b"extid", extid.extid), + (b"target", str(extid.target).encode("ascii")), + ] ) return format_git_object_from_headers("extid", headers) diff --git a/swh/model/hashutil.py b/swh/model/hashutil.py index 8740787bf4a7ac62c3f18082b85845592e20fceb..106e7c0c8e3a342d09cd431c37004b381d2d8926 100644 --- a/swh/model/hashutil.py +++ b/swh/model/hashutil.py @@ -160,9 +160,7 @@ class MultiHash: def _new_blake2_hash(algo): - """Return a function that initializes a blake2 hash. - - """ + """Return a function that initializes a blake2 hash.""" if algo in _blake2_hash_cache: return _blake2_hash_cache[algo]() diff --git a/swh/model/hypothesis_strategies.py b/swh/model/hypothesis_strategies.py index 54f552cd2abb27d72088269fe7d28faaf49a272f..dabecf962d03c0c7a00895ec215342beb1e31a2a 100644 --- a/swh/model/hypothesis_strategies.py +++ b/swh/model/hypothesis_strategies.py @@ -343,7 +343,8 @@ def directory_entries_d(): target=sha1_git(), type=just("rev"), perms=integers( - min_value=DentryPerms.revision, max_value=DentryPerms.revision + 0o777, + min_value=DentryPerms.revision, + max_value=DentryPerms.revision + 0o777, ), ), ) diff --git a/swh/model/merkle.py b/swh/model/merkle.py index 8934ad18e88266116ff85e7a2fb3ccf9c6452f0d..ab6b8ea35e393ece319fe401359e2e7b9b106433 100644 --- a/swh/model/merkle.py +++ b/swh/model/merkle.py @@ -279,8 +279,8 @@ class MerkleNode(dict, metaclass=abc.ABCMeta): def iter_tree(self, dedup=True) -> Iterator["MerkleNode"]: """Yields all children nodes, recursively. Common nodes are deduplicated - by default (deduplication can be turned off setting the given argument - 'dedup' to False). + by default (deduplication can be turned off setting the given argument + 'dedup' to False). """ yield from self._iter_tree(set(), dedup) diff --git a/swh/model/model.py b/swh/model/model.py index 3eca67445fa6e7fd5be9fa860c97ed53adbd3ed9..1438678c8753f771064d75304c0b998fb5c39537 100644 --- a/swh/model/model.py +++ b/swh/model/model.py @@ -325,7 +325,11 @@ class Person(BaseModel): else: email = raw_email[:close_bracket] - return Person(name=name or None, email=email or None, fullname=fullname,) + return Person( + name=name or None, + email=email or None, + fullname=fullname, + ) def anonymize(self) -> "Person": """Returns an anonymized version of the Person object. @@ -334,7 +338,9 @@ class Person(BaseModel): or email. """ return Person( - fullname=hashlib.sha256(self.fullname).digest(), name=None, email=None, + fullname=hashlib.sha256(self.fullname).digest(), + name=None, + email=None, ) @classmethod @@ -370,13 +376,13 @@ class Timestamp(BaseModel): @seconds.validator def check_seconds(self, attribute, value): """Check that seconds fit in a 64-bits signed integer.""" - if not (-(2 ** 63) <= value < 2 ** 63): + if not (-(2**63) <= value < 2**63): raise ValueError("Seconds must be a signed 64-bits integer.") @microseconds.validator def check_microseconds(self, attribute, value): """Checks that microseconds are positive and < 1000000.""" - if not (0 <= value < 10 ** 6): + if not (0 <= value < 10**6): raise ValueError("Microseconds must be in [0, 1000000[.") @@ -496,8 +502,7 @@ class TimestampWithTimezone(BaseModel): @classmethod def from_iso8601(cls, s): - """Builds a TimestampWithTimezone from an ISO8601-formatted string. - """ + """Builds a TimestampWithTimezone from an ISO8601-formatted string.""" dt = iso8601.parse_date(s) tstz = cls.from_datetime(dt) if dt.tzname() == "-00:00": @@ -549,7 +554,7 @@ class TimestampWithTimezone(BaseModel): minutes = int(offset_str[-2:]) offset = sign * (hours * 60 + minutes) - if (0 <= minutes <= 59) and (-(2 ** 15) <= offset < 2 ** 15): + if (0 <= minutes <= 59) and (-(2**15) <= offset < 2**15): return offset else: # can't parse it to a reasonable value; give up and pretend it's UTC. @@ -597,7 +602,8 @@ class Origin(HashableObject, BaseModel): def swhid(self) -> ExtendedSWHID: """Returns a SWHID representing this origin.""" return ExtendedSWHID( - object_type=SwhidExtendedObjectType.ORIGIN, object_id=self.id, + object_type=SwhidExtendedObjectType.ORIGIN, + object_id=self.id, ) @@ -634,9 +640,7 @@ class OriginVisit(BaseModel): @attr.s(frozen=True, slots=True) class OriginVisitStatus(BaseModel): - """Represents a visit update of an origin at a given point in time. - - """ + """Represents a visit update of an origin at a given point in time.""" object_type: Final = "origin_visit_status" @@ -869,7 +873,9 @@ class Revision(HashableObjectWithManifest, BaseModel): if not self.extra_headers and "extra_headers" in metadata: (extra_headers, metadata) = metadata.copy_pop("extra_headers") object.__setattr__( - self, "extra_headers", tuplify_extra_headers(extra_headers), + self, + "extra_headers", + tuplify_extra_headers(extra_headers), ) attr.validate(self) object.__setattr__(self, "metadata", metadata) diff --git a/swh/model/tests/fields/test_compound.py b/swh/model/tests/fields/test_compound.py index 352bba9d7358d60f46cf6bf34f7bf219fb3a7a9f..23b05b2a2afae4f7c57edc1dab621e4c0779664d 100644 --- a/swh/model/tests/fields/test_compound.py +++ b/swh/model/tests/fields/test_compound.py @@ -157,7 +157,9 @@ class ValidateCompound(unittest.TestCase): def test_validate_whole_schema_shortcut_previous_error(self): with self.assertRaises(ValidationError) as cm: compound.validate_against_schema( - self.test_model, self.test_schema_shortcut, self.test_value_missing, + self.test_model, + self.test_schema_shortcut, + self.test_value_missing, ) exc = cm.exception @@ -167,7 +169,9 @@ class ValidateCompound(unittest.TestCase): def test_validate_whole_schema(self): with self.assertRaises(ValidationError) as cm: compound.validate_against_schema( - self.test_model, self.test_schema_shortcut, self.test_value, + self.test_model, + self.test_schema_shortcut, + self.test_value, ) # The exception should be of the form: diff --git a/swh/model/tests/swh_model_data.py b/swh/model/tests/swh_model_data.py index 03b9ca7729417ca1e0570478592ed96de0379dd1..382b6433cda30c6a141dab8b69a7f5519cdd0331 100644 --- a/swh/model/tests/swh_model_data.py +++ b/swh/model/tests/swh_model_data.py @@ -91,10 +91,18 @@ COMMITTERS = [ DATES = [ TimestampWithTimezone( - timestamp=Timestamp(seconds=1234567891, microseconds=0,), offset_bytes=b"+0200", + timestamp=Timestamp( + seconds=1234567891, + microseconds=0, + ), + offset_bytes=b"+0200", ), TimestampWithTimezone( - timestamp=Timestamp(seconds=1234567892, microseconds=0,), offset_bytes=b"+0200", + timestamp=Timestamp( + seconds=1234567892, + microseconds=0, + ), + offset_bytes=b"+0200", ), ] @@ -153,8 +161,16 @@ REVISIONS = [ ] EXTIDS = [ - ExtID(extid_type="git256", extid=b"\x03" * 32, target=REVISIONS[0].swhid(),), - ExtID(extid_type="hg", extid=b"\x04" * 20, target=REVISIONS[1].swhid(),), + ExtID( + extid_type="git256", + extid=b"\x03" * 32, + target=REVISIONS[0].swhid(), + ), + ExtID( + extid_type="hg", + extid=b"\x04" * 20, + target=REVISIONS[1].swhid(), + ), ExtID( extid_type="hg-nodeid", extid=b"\x05" * 20, @@ -168,7 +184,10 @@ RELEASES = [ id=hash_to_bytes("8059dc4e17fcd0e51ca3bcd6b80f4577d281fd08"), name=b"v0.0.1", date=TimestampWithTimezone( - timestamp=Timestamp(seconds=1234567890, microseconds=0,), + timestamp=Timestamp( + seconds=1234567890, + microseconds=0, + ), offset_bytes=b"+0200", ), author=COMMITTERS[0], @@ -191,7 +210,10 @@ RELEASES = [ id=hash_to_bytes("1cdd1e87234b6f066d0855a3b5b567638a55d583"), name=b"v0.0.1", date=TimestampWithTimezone( - timestamp=Timestamp(seconds=1234567890, microseconds=0,), + timestamp=Timestamp( + seconds=1234567890, + microseconds=0, + ), offset_bytes=b"+0200", ), author=COMMITTERS[0], @@ -211,8 +233,12 @@ RELEASES = [ ] ORIGINS = [ - Origin(url="https://somewhere.org/den/fox",), - Origin(url="https://overtherainbow.org/fox/den",), + Origin( + url="https://somewhere.org/den/fox", + ), + Origin( + url="https://overtherainbow.org/fox/den", + ), ] ORIGIN_VISITS = [ @@ -319,7 +345,10 @@ DIRECTORIES = [ target=hash_to_bytes("4b825dc642cb6eb9a060e54bf8d69288fbee4904"), ), DirectoryEntry( - name=b"subprepo1", perms=0o160000, type="rev", target=REVISIONS[1].id, + name=b"subprepo1", + perms=0o160000, + type="rev", + target=REVISIONS[1].id, ), ), ), @@ -327,7 +356,10 @@ DIRECTORIES = [ id=hash_to_bytes("d135a91ac82a754e7f4bdeff8d56ef06d921eb7d"), entries=( DirectoryEntry( - name=b"file1.ext", perms=0o644, type="file", target=b"\x11" * 20, + name=b"file1.ext", + perms=0o644, + type="file", + target=b"\x11" * 20, ), ), raw_manifest=( @@ -352,13 +384,15 @@ SNAPSHOTS = [ id=hash_to_bytes("0e7f84ede9a254f2cd55649ad5240783f557e65f"), branches={ b"target/revision": SnapshotBranch( - target_type=TargetType.REVISION, target=REVISIONS[0].id, + target_type=TargetType.REVISION, + target=REVISIONS[0].id, ), b"target/alias": SnapshotBranch( target_type=TargetType.ALIAS, target=b"target/revision" ), b"target/directory": SnapshotBranch( - target_type=TargetType.DIRECTORY, target=DIRECTORIES[0].id, + target_type=TargetType.DIRECTORY, + target=DIRECTORIES[0].id, ), b"target/release": SnapshotBranch( target_type=TargetType.RELEASE, target=RELEASES[0].id @@ -374,12 +408,18 @@ SNAPSHOTS = [ METADATA_AUTHORITIES = [ MetadataAuthority( - type=MetadataAuthorityType.FORGE, url="http://example.org/", metadata={}, + type=MetadataAuthorityType.FORGE, + url="http://example.org/", + metadata={}, ), ] METADATA_FETCHERS = [ - MetadataFetcher(name="test-fetcher", version="1.0.0", metadata={},) + MetadataFetcher( + name="test-fetcher", + version="1.0.0", + metadata={}, + ) ] RAW_EXTRINSIC_METADATA = [ diff --git a/swh/model/tests/test_cli.py b/swh/model/tests/test_cli.py index eeb5a63d79f21914b65220aeb5af6329cdf60b3e..ad42349af20b02e3b50ec43022d9cad6740561c3 100644 --- a/swh/model/tests/test_cli.py +++ b/swh/model/tests/test_cli.py @@ -78,7 +78,9 @@ class TestIdentify(DataMixin, unittest.TestCase): with unittest.mock.patch.dict(sys.modules, {"dulwich": None}): with tempfile.TemporaryDirectory(prefix="swh.model.cli") as d: result = self.runner.invoke( - cli.identify, ["--type", "snapshot", d], catch_exceptions=False, + cli.identify, + ["--type", "snapshot", d], + catch_exceptions=False, ) assert result.exit_code == 1 diff --git a/swh/model/tests/test_from_disk.py b/swh/model/tests/test_from_disk.py index fa3d8b68270526cc9a935bda60b332ec8a991b9d..b7674d4307a4166a2ede388af8c8e6f52b72f190 100644 --- a/swh/model/tests/test_from_disk.py +++ b/swh/model/tests/test_from_disk.py @@ -726,11 +726,13 @@ class DirectoryToObjects(DataMixin, unittest.TestCase): for name in self.specials: self.assertContentEqual( - directory[b"specials/" + name], self.empty_content, + directory[b"specials/" + name], + self.empty_content, ) self.assertEqual( - directory[b"empty1/empty2"].get_data(), self.empty_directory, + directory[b"empty1/empty2"].get_data(), + self.empty_directory, ) # Raise on non existent file @@ -763,7 +765,8 @@ class DirectoryToObjects(DataMixin, unittest.TestCase): for name in self.specials: self.assertContentEqual( - directory[b"specials/" + name], self.empty_content, + directory[b"specials/" + name], + self.empty_content, ) # empty directories have been ignored recursively @@ -791,11 +794,13 @@ class DirectoryToObjects(DataMixin, unittest.TestCase): for name in self.specials: self.assertContentEqual( - directory[b"specials/" + name], self.empty_content, + directory[b"specials/" + name], + self.empty_content, ) self.assertEqual( - directory[b"empty1/empty2"].get_data(), self.empty_directory, + directory[b"empty1/empty2"].get_data(), + self.empty_directory, ) with self.assertRaisesRegex(KeyError, "b'symlinks'"): @@ -820,11 +825,13 @@ class DirectoryToObjects(DataMixin, unittest.TestCase): for name in self.specials: self.assertContentEqual( - directory[b"specials/" + name], self.empty_content, + directory[b"specials/" + name], + self.empty_content, ) self.assertEqual( - directory[b"empty1/empty2"].get_data(), self.empty_directory, + directory[b"empty1/empty2"].get_data(), + self.empty_directory, ) with self.assertRaisesRegex(KeyError, "b'symlinks'"): @@ -880,9 +887,7 @@ class TarballIterDirectory(DataMixin, unittest.TestCase): self.make_from_tarball(self.tmpdir_name) def test_iter_directory(self): - """Iter from_disk.directory should yield the full arborescence tree - - """ + """Iter from_disk.directory should yield the full arborescence tree""" directory = Directory.from_disk( path=os.path.join(self.tmpdir_name, b"sample-folder") ) diff --git a/swh/model/tests/test_identifiers.py b/swh/model/tests/test_identifiers.py index 6214584fc258f2fdd4866ad691017e6aae7d9d3e..793e6d5b3aa6f931a1afc8ca17f7b3be61c4e90d 100644 --- a/swh/model/tests/test_identifiers.py +++ b/swh/model/tests/test_identifiers.py @@ -36,9 +36,18 @@ def remove_id(d: Dict) -> Dict: class UtilityFunctionsDateOffset(unittest.TestCase): def setUp(self): self.dates = { - b"1448210036": {"seconds": 1448210036, "microseconds": 0,}, - b"1448210036.002342": {"seconds": 1448210036, "microseconds": 2342,}, - b"1448210036.12": {"seconds": 1448210036, "microseconds": 120000,}, + b"1448210036": { + "seconds": 1448210036, + "microseconds": 0, + }, + b"1448210036.002342": { + "seconds": 1448210036, + "microseconds": 2342, + }, + b"1448210036.12": { + "seconds": 1448210036, + "microseconds": 120000, + }, } def test_format_date(self): @@ -187,14 +196,16 @@ class DirectoryIdentifier(unittest.TestCase): def test_dir_identifier(self): self.assertEqual(Directory.from_dict(self.directory).id, self.directory["id"]) self.assertEqual( - Directory.from_dict(remove_id(self.directory)).id, self.directory["id"], + Directory.from_dict(remove_id(self.directory)).id, + self.directory["id"], ) def test_dir_identifier_entry_order(self): # Reverse order of entries, check the id is still the same. directory = {"entries": reversed(self.directory["entries"])} self.assertEqual( - Directory.from_dict(remove_id(directory)).id, self.directory["id"], + Directory.from_dict(remove_id(directory)).id, + self.directory["id"], ) def test_dir_identifier_empty_directory(self): @@ -279,7 +290,10 @@ dg1KdHOa34shrKDaOVzW "name": b"Software Heritage", "email": b"robot@softwareheritage.org", }, - "date": {"timestamp": {"seconds": 1437047495}, "offset_bytes": b"+0000",}, + "date": { + "timestamp": {"seconds": 1437047495}, + "offset_bytes": b"+0000", + }, "type": "tar", "committer": { "name": b"Software Heritage", @@ -344,9 +358,18 @@ dg1KdHOa34shrKDaOVzW "email": b"worldhello.net@gmail.com", "fullname": b"Jiang Xin <worldhello.net@gmail.com>", }, - "date": {"timestamp": 1428538899, "offset": 480,}, - "committer": {"name": b"Jiang Xin", "email": b"worldhello.net@gmail.com",}, - "committer_date": {"timestamp": 1428538899, "offset": 480,}, + "date": { + "timestamp": 1428538899, + "offset": 480, + }, + "committer": { + "name": b"Jiang Xin", + "email": b"worldhello.net@gmail.com", + }, + "committer_date": { + "timestamp": 1428538899, + "offset": 480, + }, "extra_headers": ((b"gpgsig", gpgsig),), "message": b"""Merge branch 'master' of git://github.com/alexhenrie/git-po @@ -369,9 +392,18 @@ dg1KdHOa34shrKDaOVzW "email": b"worldhello.net@gmail.com", "fullname": b"Jiang Xin <worldhello.net@gmail.com>", }, - "date": {"timestamp": 1428538899, "offset": 480,}, - "committer": {"name": b"Jiang Xin", "email": b"worldhello.net@gmail.com",}, - "committer_date": {"timestamp": 1428538899, "offset": 480,}, + "date": { + "timestamp": 1428538899, + "offset": 480, + }, + "committer": { + "name": b"Jiang Xin", + "email": b"worldhello.net@gmail.com", + }, + "committer_date": { + "timestamp": 1428538899, + "offset": 480, + }, "message": None, "type": "git", "synthetic": False, @@ -389,9 +421,18 @@ dg1KdHOa34shrKDaOVzW "email": b"worldhello.net@gmail.com", "fullname": b"Jiang Xin <worldhello.net@gmail.com>", }, - "date": {"timestamp": 1428538899, "offset": 480,}, - "committer": {"name": b"Jiang Xin", "email": b"worldhello.net@gmail.com",}, - "committer_date": {"timestamp": 1428538899, "offset": 480,}, + "date": { + "timestamp": 1428538899, + "offset": 480, + }, + "committer": { + "name": b"Jiang Xin", + "email": b"worldhello.net@gmail.com", + }, + "committer_date": { + "timestamp": 1428538899, + "offset": 480, + }, "message": b"", "type": "git", "synthetic": False, @@ -401,7 +442,9 @@ dg1KdHOa34shrKDaOVzW "id": _x("010d34f384fa99d047cdd5e2f41e56e5c2feee45"), "directory": _x("85a74718d377195e1efd0843ba4f3260bad4fe07"), "parents": [_x("01e2d0627a9a6edb24c37db45db5ecb31e9de808")], - "author": {"fullname": b"Linus Torvalds <torvalds@linux-foundation.org>",}, + "author": { + "fullname": b"Linus Torvalds <torvalds@linux-foundation.org>", + }, "date": datetime.datetime(2015, 7, 12, 15, 10, 30, tzinfo=linus_tz), "committer": { "fullname": b"Linus Torvalds <torvalds@linux-foundation.org>", @@ -420,10 +463,12 @@ dg1KdHOa34shrKDaOVzW def test_revision_identifier(self): self.assertEqual( - Revision.from_dict(self.revision).id, self.revision["id"], + Revision.from_dict(self.revision).id, + self.revision["id"], ) self.assertEqual( - Revision.from_dict(remove_id(self.revision)).id, self.revision["id"], + Revision.from_dict(remove_id(self.revision)).id, + self.revision["id"], ) def test_revision_identifier_none_metadata(self): @@ -523,7 +568,10 @@ o6X/3T+vm8K3bf3driRr34c= "target": _x("9ee1c939d1cb936b1f98e8d81aeffab57bae46ab"), "target_type": "revision", "name": b"v2.6.12", - "author": {"name": b"Linus Torvalds", "email": b"torvalds@g5.osdl.org",}, + "author": { + "name": b"Linus Torvalds", + "email": b"torvalds@g5.osdl.org", + }, "date": datetime.datetime(2005, 10, 27, 17, 2, 33, tzinfo=linus_tz), "message": None, "synthetic": False, @@ -534,7 +582,10 @@ o6X/3T+vm8K3bf3driRr34c= "target": _x("9ee1c939d1cb936b1f98e8d81aeffab57bae46ab"), "target_type": "revision", "name": b"v2.6.12", - "author": {"name": b"Linus Torvalds", "email": b"torvalds@g5.osdl.org",}, + "author": { + "name": b"Linus Torvalds", + "email": b"torvalds@g5.osdl.org", + }, "date": datetime.datetime(2005, 10, 27, 17, 2, 33, tzinfo=linus_tz), "message": b"", "synthetic": False, @@ -545,8 +596,14 @@ o6X/3T+vm8K3bf3driRr34c= "name": b"20081029", "target": _x("54e9abca4c77421e2921f5f156c9fe4a9f7441c7"), "target_type": "revision", - "date": {"timestamp": {"seconds": 1225281976}, "offset_bytes": b"-0000",}, - "author": {"name": b"Otavio Salvador", "email": b"otavio@debian.org",}, + "date": { + "timestamp": {"seconds": 1225281976}, + "offset_bytes": b"-0000", + }, + "author": { + "name": b"Otavio Salvador", + "email": b"otavio@debian.org", + }, "synthetic": False, "message": b"tagging version 20081029\n\nr56558\n", } @@ -559,7 +616,10 @@ o6X/3T+vm8K3bf3driRr34c= }, "date": { "offset_bytes": b"+1000", - "timestamp": {"microseconds": 0, "seconds": 1377480558,}, + "timestamp": { + "microseconds": 0, + "seconds": 1377480558, + }, }, "id": _x("5c98f559d034162de22d3ebeb95433e6f8885231"), "message": b"Release of v0.3.2.", @@ -577,10 +637,12 @@ o6X/3T+vm8K3bf3driRr34c= def test_release_identifier(self): self.assertEqual( - Release.from_dict(self.release).id, self.release["id"], + Release.from_dict(self.release).id, + self.release["id"], ) self.assertEqual( - Release.from_dict(remove_id(self.release)).id, self.release["id"], + Release.from_dict(remove_id(self.release)).id, + self.release["id"], ) def test_release_identifier_no_author(self): @@ -631,7 +693,10 @@ snapshot_example = { "target": _x("fe95a46679d128ff167b7c55df5d02356c5a1ae1"), "target_type": "content", }, - b"alias": {"target": b"revision", "target_type": "alias",}, + b"alias": { + "target": b"revision", + "target_type": "alias", + }, b"revision": { "target": _x("aafb16d69fd30ff58afdd69036a26047f3aebdc6"), "target_type": "revision", @@ -660,19 +725,27 @@ class SnapshotIdentifier(unittest.TestCase): self.dangling_branch = { "id": _x("c84502e821eb21ed84e9fd3ec40973abc8b32353"), - "branches": {b"HEAD": None,}, + "branches": { + b"HEAD": None, + }, } self.unresolved = { "id": _x("84b4548ea486e4b0a7933fa541ff1503a0afe1e0"), - "branches": {b"foo": {"target": b"bar", "target_type": "alias",},}, + "branches": { + b"foo": { + "target": b"bar", + "target_type": "alias", + }, + }, } self.all_types = snapshot_example def test_empty_snapshot(self): self.assertEqual( - Snapshot.from_dict(remove_id(self.empty)).id, self.empty["id"], + Snapshot.from_dict(remove_id(self.empty)).id, + self.empty["id"], ) def test_dangling_branch(self): @@ -687,7 +760,8 @@ class SnapshotIdentifier(unittest.TestCase): def test_all_types(self): self.assertEqual( - Snapshot.from_dict(remove_id(self.all_types)).id, self.all_types["id"], + Snapshot.from_dict(remove_id(self.all_types)).id, + self.all_types["id"], ) @@ -828,7 +902,13 @@ class RawExtrinsicMetadataIdentifier(unittest.TestCase): metadata = { **self.minimal, "discovery_date": datetime.datetime( - 2021, 1, 25, 12, 27, 51, tzinfo=utc_plus_one, + 2021, + 1, + 25, + 12, + 27, + 51, + tzinfo=utc_plus_one, ), } @@ -855,7 +935,14 @@ class RawExtrinsicMetadataIdentifier(unittest.TestCase): metadata = { **self.minimal, "discovery_date": datetime.datetime( - 2021, 1, 25, 11, 27, 51, 123456, tzinfo=datetime.timezone.utc, + 2021, + 1, + 25, + 11, + 27, + 51, + 123456, + tzinfo=datetime.timezone.utc, ), } @@ -883,7 +970,14 @@ class RawExtrinsicMetadataIdentifier(unittest.TestCase): metadata = { **self.minimal, "discovery_date": datetime.datetime( - 2021, 1, 25, 11, 27, 50, 1_000_000 - 42, tzinfo=tz, + 2021, + 1, + 25, + 11, + 27, + 50, + 1_000_000 - 42, + tzinfo=tz, ), } @@ -908,7 +1002,13 @@ class RawExtrinsicMetadataIdentifier(unittest.TestCase): metadata = { **self.minimal, "discovery_date": datetime.datetime( - 1960, 1, 25, 11, 27, 51, tzinfo=datetime.timezone.utc, + 1960, + 1, + 25, + 11, + 27, + 51, + tzinfo=datetime.timezone.utc, ), } @@ -942,7 +1042,13 @@ class RawExtrinsicMetadataIdentifier(unittest.TestCase): metadata = { **self.minimal, "discovery_date": datetime.datetime( - 1970, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc, + 1970, + 1, + 1, + 0, + 0, + 0, + tzinfo=datetime.timezone.utc, ), } @@ -976,7 +1082,14 @@ class RawExtrinsicMetadataIdentifier(unittest.TestCase): metadata = { **self.minimal, "discovery_date": datetime.datetime( - 1969, 12, 31, 23, 59, 59, 1, tzinfo=datetime.timezone.utc, + 1969, + 12, + 31, + 23, + 59, + 59, + 1, + tzinfo=datetime.timezone.utc, ), } @@ -1035,23 +1148,38 @@ TS_DICTS = [ # with current input dict format (offset_bytes) ( {"timestamp": 12345, "offset_bytes": b"+0000"}, - {"timestamp": {"seconds": 12345, "microseconds": 0}, "offset_bytes": b"+0000",}, + { + "timestamp": {"seconds": 12345, "microseconds": 0}, + "offset_bytes": b"+0000", + }, ), ( {"timestamp": 12345, "offset_bytes": b"-0000"}, - {"timestamp": {"seconds": 12345, "microseconds": 0}, "offset_bytes": b"-0000",}, + { + "timestamp": {"seconds": 12345, "microseconds": 0}, + "offset_bytes": b"-0000", + }, ), ( {"timestamp": 12345, "offset_bytes": b"+0200"}, - {"timestamp": {"seconds": 12345, "microseconds": 0}, "offset_bytes": b"+0200",}, + { + "timestamp": {"seconds": 12345, "microseconds": 0}, + "offset_bytes": b"+0200", + }, ), ( {"timestamp": 12345, "offset_bytes": b"-0200"}, - {"timestamp": {"seconds": 12345, "microseconds": 0}, "offset_bytes": b"-0200",}, + { + "timestamp": {"seconds": 12345, "microseconds": 0}, + "offset_bytes": b"-0200", + }, ), ( {"timestamp": 12345, "offset_bytes": b"--700"}, - {"timestamp": {"seconds": 12345, "microseconds": 0}, "offset_bytes": b"--700",}, + { + "timestamp": {"seconds": 12345, "microseconds": 0}, + "offset_bytes": b"--700", + }, ), ( {"timestamp": 12345, "offset_bytes": b"1234567"}, @@ -1063,23 +1191,38 @@ TS_DICTS = [ # with old-style input dicts (numeric offset + optional negative_utc): ( {"timestamp": 12345, "offset": 0}, - {"timestamp": {"seconds": 12345, "microseconds": 0}, "offset_bytes": b"+0000",}, + { + "timestamp": {"seconds": 12345, "microseconds": 0}, + "offset_bytes": b"+0000", + }, ), ( {"timestamp": 12345, "offset": 0, "negative_utc": False}, - {"timestamp": {"seconds": 12345, "microseconds": 0}, "offset_bytes": b"+0000",}, + { + "timestamp": {"seconds": 12345, "microseconds": 0}, + "offset_bytes": b"+0000", + }, ), ( {"timestamp": 12345, "offset": 0, "negative_utc": False}, - {"timestamp": {"seconds": 12345, "microseconds": 0}, "offset_bytes": b"+0000",}, + { + "timestamp": {"seconds": 12345, "microseconds": 0}, + "offset_bytes": b"+0000", + }, ), ( {"timestamp": 12345, "offset": 0, "negative_utc": None}, - {"timestamp": {"seconds": 12345, "microseconds": 0}, "offset_bytes": b"+0000",}, + { + "timestamp": {"seconds": 12345, "microseconds": 0}, + "offset_bytes": b"+0000", + }, ), ( {"timestamp": {"seconds": 12345}, "offset": 0, "negative_utc": None}, - {"timestamp": {"seconds": 12345, "microseconds": 0}, "offset_bytes": b"+0000",}, + { + "timestamp": {"seconds": 12345, "microseconds": 0}, + "offset_bytes": b"+0000", + }, ), ( { @@ -1087,7 +1230,10 @@ TS_DICTS = [ "offset": 0, "negative_utc": None, }, - {"timestamp": {"seconds": 12345, "microseconds": 0}, "offset_bytes": b"+0000",}, + { + "timestamp": {"seconds": 12345, "microseconds": 0}, + "offset_bytes": b"+0000", + }, ), ( { @@ -1102,11 +1248,17 @@ TS_DICTS = [ ), ( {"timestamp": 12345, "offset": 0, "negative_utc": True}, - {"timestamp": {"seconds": 12345, "microseconds": 0}, "offset_bytes": b"-0000",}, + { + "timestamp": {"seconds": 12345, "microseconds": 0}, + "offset_bytes": b"-0000", + }, ), ( {"timestamp": 12345, "offset": 0, "negative_utc": None}, - {"timestamp": {"seconds": 12345, "microseconds": 0}, "offset_bytes": b"+0000",}, + { + "timestamp": {"seconds": 12345, "microseconds": 0}, + "offset_bytes": b"+0000", + }, ), ] diff --git a/swh/model/tests/test_merkle.py b/swh/model/tests/test_merkle.py index 32de872592dbee4df54a82da4302cb87a31e2611..52edb2c1d8424263199b28323f601ffa1b8c234b 100644 --- a/swh/model/tests/test_merkle.py +++ b/swh/model/tests/test_merkle.py @@ -96,17 +96,29 @@ class TestMerkleNode(unittest.TestCase): self.nodes = {b"root": self.root} for i in (b"a", b"b", b"c"): value = b"root/" + i - node = MerkleTestNode({"value": value,}) + node = MerkleTestNode( + { + "value": value, + } + ) self.root[i] = node self.nodes[value] = node for j in (b"a", b"b", b"c"): value2 = value + b"/" + j - node2 = MerkleTestNode({"value": value2,}) + node2 = MerkleTestNode( + { + "value": value2, + } + ) node[j] = node2 self.nodes[value2] = node2 for k in (b"a", b"b", b"c"): value3 = value2 + b"/" + j - node3 = MerkleTestNode({"value": value3,}) + node3 = MerkleTestNode( + { + "value": value3, + } + ) node2[j] = node3 self.nodes[value3] = node3 diff --git a/swh/model/tests/test_model.py b/swh/model/tests/test_model.py index 2e7fa7746bf1a06c82452a10350e125c1e24c94e..8c058b91541d75fc302c48108133470e8c46ac32 100644 --- a/swh/model/tests/test_model.py +++ b/swh/model/tests/test_model.py @@ -215,8 +215,16 @@ _TYPE_VALIDATOR_PARAMETERS: List[Tuple[Any, List[Any], List[Any]]] = [ [ImmutableDict({"foo": "bar"}), ImmutableDict({42: 123})], ), # Any: - (object, [-1, 0, 1, 42, 1000, None, "123", 0.0, (), ImmutableDict()], [],), - (Any, [-1, 0, 1, 42, 1000, None, "123", 0.0, (), ImmutableDict()], [],), + ( + object, + [-1, 0, 1, 42, 1000, None, "123", 0.0, (), ImmutableDict()], + [], + ), + ( + Any, + [-1, 0, 1, 42, 1000, None, "123", 0.0, (), ImmutableDict()], + [], + ), ( ImmutableDict[Any, int], [ @@ -240,10 +248,16 @@ _TYPE_VALIDATOR_PARAMETERS: List[Tuple[Any, List[Any], List[Any]]] = [ # attr objects: ( Timestamp, - [Timestamp(seconds=123, microseconds=0),], + [ + Timestamp(seconds=123, microseconds=0), + ], [None, "2021-09-28T11:27:59", 123], ), - (Cls1, [Cls1(), Cls2()], [None, b"abcd"],), + ( + Cls1, + [Cls1(), Cls2()], + [None, b"abcd"], + ), # enums: ( TargetType, @@ -300,7 +314,11 @@ def test_unique_key(): } assert OriginVisitStatus( origin=url, visit=42, date=date, status="created", snapshot=None - ).unique_key() == {"origin": url, "visit": "42", "date": str(date),} + ).unique_key() == { + "origin": url, + "visit": "42", + "date": str(date), + } assert Snapshot.from_dict({**snapshot_example, "id": id_}).unique_key() == id_ assert Release.from_dict({**release_example, "id": id_}).unique_key() == id_ @@ -372,7 +390,9 @@ def test_todict_origin_visits(origin_visit): def test_origin_visit_naive_datetime(): with pytest.raises(ValueError, match="must be a timezone-aware datetime"): OriginVisit( - origin="http://foo/", date=datetime.datetime.now(), type="git", + origin="http://foo/", + date=datetime.datetime.now(), + type="git", ) @@ -407,13 +427,13 @@ def test_timestamp_seconds(): with pytest.raises(AttributeTypeError): Timestamp(seconds="0", microseconds=0) - attr.validate(Timestamp(seconds=2 ** 63 - 1, microseconds=0)) + attr.validate(Timestamp(seconds=2**63 - 1, microseconds=0)) with pytest.raises(ValueError): - Timestamp(seconds=2 ** 63, microseconds=0) + Timestamp(seconds=2**63, microseconds=0) - attr.validate(Timestamp(seconds=-(2 ** 63), microseconds=0)) + attr.validate(Timestamp(seconds=-(2**63), microseconds=0)) with pytest.raises(ValueError): - Timestamp(seconds=-(2 ** 63) - 1, microseconds=0) + Timestamp(seconds=-(2**63) - 1, microseconds=0) def test_timestamp_microseconds(): @@ -421,9 +441,9 @@ def test_timestamp_microseconds(): with pytest.raises(AttributeTypeError): Timestamp(seconds=0, microseconds="0") - attr.validate(Timestamp(seconds=0, microseconds=10 ** 6 - 1)) + attr.validate(Timestamp(seconds=0, microseconds=10**6 - 1)) with pytest.raises(ValueError): - Timestamp(seconds=0, microseconds=10 ** 6) + Timestamp(seconds=0, microseconds=10**6) with pytest.raises(ValueError): Timestamp(seconds=0, microseconds=-1) @@ -440,9 +460,9 @@ def test_timestamp_from_dict(): with pytest.raises(ValueError): Timestamp.from_dict({"seconds": 0, "microseconds": -1}) - Timestamp.from_dict({"seconds": 0, "microseconds": 10 ** 6 - 1}) + Timestamp.from_dict({"seconds": 0, "microseconds": 10**6 - 1}) with pytest.raises(ValueError): - Timestamp.from_dict({"seconds": 0, "microseconds": 10 ** 6}) + Timestamp.from_dict({"seconds": 0, "microseconds": 10**6}) # TimestampWithTimezone @@ -508,7 +528,11 @@ def test_timestampwithtimezone_from_datetime(): date = datetime.datetime(2020, 2, 27, 14, 39, 19, tzinfo=tz) tstz = TimestampWithTimezone.from_datetime(date) assert tstz == TimestampWithTimezone( - timestamp=Timestamp(seconds=1582810759, microseconds=0,), offset_bytes=b"+0100" + timestamp=Timestamp( + seconds=1582810759, + microseconds=0, + ), + offset_bytes=b"+0100", ) # Typical case (close to epoch) @@ -516,7 +540,11 @@ def test_timestampwithtimezone_from_datetime(): date = datetime.datetime(1970, 1, 1, 1, 0, 5, tzinfo=tz) tstz = TimestampWithTimezone.from_datetime(date) assert tstz == TimestampWithTimezone( - timestamp=Timestamp(seconds=5, microseconds=0,), offset_bytes=b"+0100" + timestamp=Timestamp( + seconds=5, + microseconds=0, + ), + offset_bytes=b"+0100", ) # non-integer number of seconds before UNIX epoch @@ -525,7 +553,11 @@ def test_timestampwithtimezone_from_datetime(): ) tstz = TimestampWithTimezone.from_datetime(date) assert tstz == TimestampWithTimezone( - timestamp=Timestamp(seconds=-1, microseconds=100000,), offset_bytes=b"+0000" + timestamp=Timestamp( + seconds=-1, + microseconds=100000, + ), + offset_bytes=b"+0000", ) # non-integer number of seconds in both the timestamp and the offset @@ -533,7 +565,11 @@ def test_timestampwithtimezone_from_datetime(): date = datetime.datetime(1969, 12, 31, 23, 59, 59, 600000, tzinfo=tz) tstz = TimestampWithTimezone.from_datetime(date) assert tstz == TimestampWithTimezone( - timestamp=Timestamp(seconds=0, microseconds=200000,), offset_bytes=b"+0000" + timestamp=Timestamp( + seconds=0, + microseconds=200000, + ), + offset_bytes=b"+0000", ) # timezone offset with non-integer number of seconds, for dates before epoch @@ -543,7 +579,11 @@ def test_timestampwithtimezone_from_datetime(): date = datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=tz) tstz = TimestampWithTimezone.from_datetime(date) assert tstz == TimestampWithTimezone( - timestamp=Timestamp(seconds=-1, microseconds=100000,), offset_bytes=b"+0000" + timestamp=Timestamp( + seconds=-1, + microseconds=100000, + ), + offset_bytes=b"+0000", ) @@ -560,7 +600,10 @@ def test_timestampwithtimezone_from_iso8601(): tstz = TimestampWithTimezone.from_iso8601(date) assert tstz == TimestampWithTimezone( - timestamp=Timestamp(seconds=1582810759, microseconds=123456,), + timestamp=Timestamp( + seconds=1582810759, + microseconds=123456, + ), offset_bytes=b"+0100", ) @@ -571,7 +614,11 @@ def test_timestampwithtimezone_from_iso8601_negative_utc(): tstz = TimestampWithTimezone.from_iso8601(date) assert tstz == TimestampWithTimezone( - timestamp=Timestamp(seconds=1582810759, microseconds=0,), offset_bytes=b"-0000" + timestamp=Timestamp( + seconds=1582810759, + microseconds=0, + ), + offset_bytes=b"-0000", ) @@ -587,21 +634,23 @@ def test_timestampwithtimezone_to_datetime(date, tz, microsecond): def test_person_from_fullname(): - """The author should have name, email and fullname filled. - - """ + """The author should have name, email and fullname filled.""" actual_person = Person.from_fullname(b"tony <ynot@dagobah>") assert actual_person == Person( - fullname=b"tony <ynot@dagobah>", name=b"tony", email=b"ynot@dagobah", + fullname=b"tony <ynot@dagobah>", + name=b"tony", + email=b"ynot@dagobah", ) def test_person_from_fullname_no_email(): - """The author and fullname should be the same as the input (author). - - """ + """The author and fullname should be the same as the input (author).""" actual_person = Person.from_fullname(b"tony") - assert actual_person == Person(fullname=b"tony", name=b"tony", email=None,) + assert actual_person == Person( + fullname=b"tony", + name=b"tony", + email=None, + ) def test_person_from_fullname_empty_person(): @@ -610,7 +659,11 @@ def test_person_from_fullname_empty_person(): """ actual_person = Person.from_fullname(b"") - assert actual_person == Person(fullname=b"", name=None, email=None,) + assert actual_person == Person( + fullname=b"", + name=None, + email=None, + ) def test_git_author_line_to_author(): @@ -619,9 +672,15 @@ def test_git_author_line_to_author(): Person.from_fullname(None) tests = { - b"a <b@c.com>": Person(name=b"a", email=b"b@c.com", fullname=b"a <b@c.com>",), + b"a <b@c.com>": Person( + name=b"a", + email=b"b@c.com", + fullname=b"a <b@c.com>", + ), b"<foo@bar.com>": Person( - name=None, email=b"foo@bar.com", fullname=b"<foo@bar.com>", + name=None, + email=b"foo@bar.com", + fullname=b"<foo@bar.com>", ), b"malformed <email": Person( name=b"malformed", email=b"email", fullname=b"malformed <email" @@ -632,13 +691,25 @@ def test_git_author_line_to_author(): fullname=b'malformed <"<br"@ckets>', ), b"trailing <sp@c.e> ": Person( - name=b"trailing", email=b"sp@c.e", fullname=b"trailing <sp@c.e> ", + name=b"trailing", + email=b"sp@c.e", + fullname=b"trailing <sp@c.e> ", + ), + b"no<sp@c.e>": Person( + name=b"no", + email=b"sp@c.e", + fullname=b"no<sp@c.e>", ), - b"no<sp@c.e>": Person(name=b"no", email=b"sp@c.e", fullname=b"no<sp@c.e>",), b" more <sp@c.es>": Person( - name=b"more", email=b"sp@c.es", fullname=b" more <sp@c.es>", + name=b"more", + email=b"sp@c.es", + fullname=b" more <sp@c.es>", + ), + b" <>": Person( + name=None, + email=None, + fullname=b" <>", ), - b" <>": Person(name=None, email=None, fullname=b" <>",), } for person in sorted(tests): @@ -647,9 +718,7 @@ def test_git_author_line_to_author(): def test_person_comparison(): - """Check only the fullname attribute is used to compare Person objects - - """ + """Check only the fullname attribute is used to compare Person objects""" person = Person(fullname=b"p1", name=None, email=None) assert attr.evolve(person, name=b"toto") == person assert attr.evolve(person, email=b"toto@example.com") == person @@ -767,7 +836,8 @@ def test_content_naive_datetime(): c = Content.from_data(b"foo") with pytest.raises(ValueError, match="must be a timezone-aware datetime"): Content( - **c.to_dict(), ctime=datetime.datetime.now(), + **c.to_dict(), + ctime=datetime.datetime.now(), ) @@ -800,7 +870,8 @@ def test_skipped_content_naive_datetime(): c = SkippedContent.from_data(b"foo", reason="reason") with pytest.raises(ValueError, match="must be a timezone-aware datetime"): SkippedContent( - **c.to_dict(), ctime=datetime.datetime.now(), + **c.to_dict(), + ctime=datetime.datetime.now(), ) @@ -1173,9 +1244,13 @@ def test_object_type_is_final(): _metadata_authority = MetadataAuthority( - type=MetadataAuthorityType.FORGE, url="https://forge.softwareheritage.org", + type=MetadataAuthorityType.FORGE, + url="https://forge.softwareheritage.org", +) +_metadata_fetcher = MetadataFetcher( + name="test-fetcher", + version="0.0.1", ) -_metadata_fetcher = MetadataFetcher(name="test-fetcher", version="0.0.1",) _content_swhid = ExtendedSWHID.from_string( "swh:1:cnt:94a9ed024d3859793618152ea559a168bbcbb5e2" ) @@ -1203,7 +1278,8 @@ def test_metadata_valid(): # Object with an SWHID RawExtrinsicMetadata( - target=_content_swhid, **_common_metadata_fields, + target=_content_swhid, + **_common_metadata_fields, ) @@ -1212,13 +1288,19 @@ def test_metadata_to_dict(): common_fields = { "authority": {"type": "forge", "url": "https://forge.softwareheritage.org"}, - "fetcher": {"name": "test-fetcher", "version": "0.0.1",}, + "fetcher": { + "name": "test-fetcher", + "version": "0.0.1", + }, "discovery_date": _common_metadata_fields["discovery_date"], "format": "json", "metadata": b'{"origin": "https://example.com", "lines": "42"}', } - m = RawExtrinsicMetadata(target=_origin_swhid, **_common_metadata_fields,) + m = RawExtrinsicMetadata( + target=_origin_swhid, + **_common_metadata_fields, + ) assert m.to_dict() == { "target": str(_origin_swhid), "id": b"@j\xc9\x01\xbc\x1e#p*\xf3q9\xa7u\x97\x00\x14\x02xa", @@ -1226,7 +1308,10 @@ def test_metadata_to_dict(): } assert RawExtrinsicMetadata.from_dict(m.to_dict()) == m - m = RawExtrinsicMetadata(target=_content_swhid, **_common_metadata_fields,) + m = RawExtrinsicMetadata( + target=_content_swhid, + **_common_metadata_fields, + ) assert m.to_dict() == { "target": "swh:1:cnt:94a9ed024d3859793618152ea559a168bbcbb5e2", "id": b"\xbc\xa3U\xddf\x19U\xc5\xd2\xd7\xdfK\xd7c\x1f\xa8\xfeh\x992", @@ -1286,12 +1371,16 @@ def test_metadata_validate_context_origin(): ValueError, match="Unexpected 'origin' context for origin object" ): RawExtrinsicMetadata( - target=_origin_swhid, origin=_origin_url, **_common_metadata_fields, + target=_origin_swhid, + origin=_origin_url, + **_common_metadata_fields, ) # but all other types can RawExtrinsicMetadata( - target=_content_swhid, origin=_origin_url, **_common_metadata_fields, + target=_content_swhid, + origin=_origin_url, + **_common_metadata_fields, ) # SWHIDs aren't valid origin URLs @@ -1311,18 +1400,25 @@ def test_metadata_validate_context_visit(): ValueError, match="Unexpected 'visit' context for origin object" ): RawExtrinsicMetadata( - target=_origin_swhid, visit=42, **_common_metadata_fields, + target=_origin_swhid, + visit=42, + **_common_metadata_fields, ) # but all other types can RawExtrinsicMetadata( - target=_content_swhid, origin=_origin_url, visit=42, **_common_metadata_fields, + target=_content_swhid, + origin=_origin_url, + visit=42, + **_common_metadata_fields, ) # Missing 'origin' with pytest.raises(ValueError, match="'origin' context must be set if 'visit' is"): RawExtrinsicMetadata( - target=_content_swhid, visit=42, **_common_metadata_fields, + target=_content_swhid, + visit=42, + **_common_metadata_fields, ) # visit id must be positive @@ -1345,7 +1441,8 @@ def test_metadata_validate_context_snapshot(): RawExtrinsicMetadata( target=_origin_swhid, snapshot=CoreSWHID( - object_type=ObjectType.SNAPSHOT, object_id=EXAMPLE_HASH, + object_type=ObjectType.SNAPSHOT, + object_id=EXAMPLE_HASH, ), **_common_metadata_fields, ) @@ -1363,7 +1460,10 @@ def test_metadata_validate_context_snapshot(): ): RawExtrinsicMetadata( target=_content_swhid, - snapshot=CoreSWHID(object_type=ObjectType.CONTENT, object_id=EXAMPLE_HASH,), + snapshot=CoreSWHID( + object_type=ObjectType.CONTENT, + object_id=EXAMPLE_HASH, + ), **_common_metadata_fields, ) @@ -1377,7 +1477,10 @@ def test_metadata_validate_context_release(): ): RawExtrinsicMetadata( target=_origin_swhid, - release=CoreSWHID(object_type=ObjectType.RELEASE, object_id=EXAMPLE_HASH,), + release=CoreSWHID( + object_type=ObjectType.RELEASE, + object_id=EXAMPLE_HASH, + ), **_common_metadata_fields, ) @@ -1394,7 +1497,10 @@ def test_metadata_validate_context_release(): ): RawExtrinsicMetadata( target=_content_swhid, - release=CoreSWHID(object_type=ObjectType.CONTENT, object_id=EXAMPLE_HASH,), + release=CoreSWHID( + object_type=ObjectType.CONTENT, + object_id=EXAMPLE_HASH, + ), **_common_metadata_fields, ) @@ -1409,7 +1515,8 @@ def test_metadata_validate_context_revision(): RawExtrinsicMetadata( target=_origin_swhid, revision=CoreSWHID( - object_type=ObjectType.REVISION, object_id=EXAMPLE_HASH, + object_type=ObjectType.REVISION, + object_id=EXAMPLE_HASH, ), **_common_metadata_fields, ) @@ -1427,7 +1534,10 @@ def test_metadata_validate_context_revision(): ): RawExtrinsicMetadata( target=_content_swhid, - revision=CoreSWHID(object_type=ObjectType.CONTENT, object_id=EXAMPLE_HASH,), + revision=CoreSWHID( + object_type=ObjectType.CONTENT, + object_id=EXAMPLE_HASH, + ), **_common_metadata_fields, ) @@ -1438,12 +1548,16 @@ def test_metadata_validate_context_path(): # Origins can't have a 'path' context with pytest.raises(ValueError, match="Unexpected 'path' context for origin object"): RawExtrinsicMetadata( - target=_origin_swhid, path=b"/foo/bar", **_common_metadata_fields, + target=_origin_swhid, + path=b"/foo/bar", + **_common_metadata_fields, ) # but content can RawExtrinsicMetadata( - target=_content_swhid, path=b"/foo/bar", **_common_metadata_fields, + target=_content_swhid, + path=b"/foo/bar", + **_common_metadata_fields, ) @@ -1457,7 +1571,8 @@ def test_metadata_validate_context_directory(): RawExtrinsicMetadata( target=_origin_swhid, directory=CoreSWHID( - object_type=ObjectType.DIRECTORY, object_id=EXAMPLE_HASH, + object_type=ObjectType.DIRECTORY, + object_id=EXAMPLE_HASH, ), **_common_metadata_fields, ) @@ -1465,7 +1580,10 @@ def test_metadata_validate_context_directory(): # but content can RawExtrinsicMetadata( target=_content_swhid, - directory=CoreSWHID(object_type=ObjectType.DIRECTORY, object_id=EXAMPLE_HASH,), + directory=CoreSWHID( + object_type=ObjectType.DIRECTORY, + object_id=EXAMPLE_HASH, + ), **_common_metadata_fields, ) @@ -1476,7 +1594,8 @@ def test_metadata_validate_context_directory(): RawExtrinsicMetadata( target=_content_swhid, directory=CoreSWHID( - object_type=ObjectType.CONTENT, object_id=EXAMPLE_HASH, + object_type=ObjectType.CONTENT, + object_id=EXAMPLE_HASH, ), **_common_metadata_fields, ) @@ -1497,7 +1616,9 @@ def test_metadata_normalize_discovery_date(): # Check for truncation to integral second date_with_us = truncated_date.replace(microsecond=42) md = RawExtrinsicMetadata( - target=_content_swhid, discovery_date=date_with_us, **fields_copy, + target=_content_swhid, + discovery_date=date_with_us, + **fields_copy, ) assert md.discovery_date == truncated_date @@ -1511,7 +1632,9 @@ def test_metadata_normalize_discovery_date(): assert date_with_tz.tzinfo != datetime.timezone.utc md = RawExtrinsicMetadata( - target=_content_swhid, discovery_date=date_with_tz, **fields_copy, + target=_content_swhid, + discovery_date=date_with_tz, + **fields_copy, ) assert md.discovery_date == truncated_date diff --git a/swh/model/tests/test_swh_model_data.py b/swh/model/tests/test_swh_model_data.py index 5e2521dfabfe15d544e3a9c25392a31d4c922a1b..e9d7374c8c3b329eba1750d17ffb1edbee42b11a 100644 --- a/swh/model/tests/test_swh_model_data.py +++ b/swh/model/tests/test_swh_model_data.py @@ -19,7 +19,8 @@ def test_swh_model_data(object_type, objects): @pytest.mark.parametrize( - "object_type", ("directory", "revision", "release", "snapshot"), + "object_type", + ("directory", "revision", "release", "snapshot"), ) def test_swh_model_data_hash(object_type): for obj in TEST_OBJECTS[object_type]: @@ -46,8 +47,7 @@ def test_ensure_visit_status_date_consistency(): def test_ensure_visit_status_snapshot_consistency(): - """ensure origin-visit-status snapshots exist in the test dataset - """ + """ensure origin-visit-status snapshots exist in the test dataset""" snapshots = [snp.id for snp in TEST_OBJECTS["snapshot"]] for visit_status in TEST_OBJECTS["origin_visit_status"]: if visit_status.snapshot: diff --git a/swh/model/tests/test_swhids.py b/swh/model/tests/test_swhids.py index 34a55f640dfbcdf2ed22c9837c582635a39bc7d1..5c3cab22ee2cbeab65958ee230562dfab1ed3d58 100644 --- a/swh/model/tests/test_swhids.py +++ b/swh/model/tests/test_swhids.py @@ -82,33 +82,78 @@ HASH = "94a9ed024d3859793618152ea559a168bbcbb5e2" VALID_SWHIDS = [ ( f"swh:1:cnt:{HASH}", - CoreSWHID(object_type=ObjectType.CONTENT, object_id=_x(HASH),), - QualifiedSWHID(object_type=ObjectType.CONTENT, object_id=_x(HASH),), - ExtendedSWHID(object_type=ExtendedObjectType.CONTENT, object_id=_x(HASH),), + CoreSWHID( + object_type=ObjectType.CONTENT, + object_id=_x(HASH), + ), + QualifiedSWHID( + object_type=ObjectType.CONTENT, + object_id=_x(HASH), + ), + ExtendedSWHID( + object_type=ExtendedObjectType.CONTENT, + object_id=_x(HASH), + ), ), ( f"swh:1:dir:{HASH}", - CoreSWHID(object_type=ObjectType.DIRECTORY, object_id=_x(HASH),), - QualifiedSWHID(object_type=ObjectType.DIRECTORY, object_id=_x(HASH),), - ExtendedSWHID(object_type=ExtendedObjectType.DIRECTORY, object_id=_x(HASH),), + CoreSWHID( + object_type=ObjectType.DIRECTORY, + object_id=_x(HASH), + ), + QualifiedSWHID( + object_type=ObjectType.DIRECTORY, + object_id=_x(HASH), + ), + ExtendedSWHID( + object_type=ExtendedObjectType.DIRECTORY, + object_id=_x(HASH), + ), ), ( f"swh:1:rev:{HASH}", - CoreSWHID(object_type=ObjectType.REVISION, object_id=_x(HASH),), - QualifiedSWHID(object_type=ObjectType.REVISION, object_id=_x(HASH),), - ExtendedSWHID(object_type=ExtendedObjectType.REVISION, object_id=_x(HASH),), + CoreSWHID( + object_type=ObjectType.REVISION, + object_id=_x(HASH), + ), + QualifiedSWHID( + object_type=ObjectType.REVISION, + object_id=_x(HASH), + ), + ExtendedSWHID( + object_type=ExtendedObjectType.REVISION, + object_id=_x(HASH), + ), ), ( f"swh:1:rel:{HASH}", - CoreSWHID(object_type=ObjectType.RELEASE, object_id=_x(HASH),), - QualifiedSWHID(object_type=ObjectType.RELEASE, object_id=_x(HASH),), - ExtendedSWHID(object_type=ExtendedObjectType.RELEASE, object_id=_x(HASH),), + CoreSWHID( + object_type=ObjectType.RELEASE, + object_id=_x(HASH), + ), + QualifiedSWHID( + object_type=ObjectType.RELEASE, + object_id=_x(HASH), + ), + ExtendedSWHID( + object_type=ExtendedObjectType.RELEASE, + object_id=_x(HASH), + ), ), ( f"swh:1:snp:{HASH}", - CoreSWHID(object_type=ObjectType.SNAPSHOT, object_id=_x(HASH),), - QualifiedSWHID(object_type=ObjectType.SNAPSHOT, object_id=_x(HASH),), - ExtendedSWHID(object_type=ExtendedObjectType.SNAPSHOT, object_id=_x(HASH),), + CoreSWHID( + object_type=ObjectType.SNAPSHOT, + object_id=_x(HASH), + ), + QualifiedSWHID( + object_type=ObjectType.SNAPSHOT, + object_id=_x(HASH), + ), + ExtendedSWHID( + object_type=ExtendedObjectType.SNAPSHOT, + object_id=_x(HASH), + ), ), ( f"swh:1:cnt:{HASH};origin=https://github.com/python/cpython;lines=1-18", @@ -152,14 +197,18 @@ VALID_SWHIDS = [ f"swh:1:ori:{HASH}", None, # CoreSWHID does not allow origin pseudo-SWHIDs None, # Neither does QualifiedSWHID - ExtendedSWHID(object_type=ExtendedObjectType.ORIGIN, object_id=_x(HASH),), + ExtendedSWHID( + object_type=ExtendedObjectType.ORIGIN, + object_id=_x(HASH), + ), ), ( f"swh:1:emd:{HASH}", None, # likewise for metadata pseudo-SWHIDs None, # Neither does QualifiedSWHID ExtendedSWHID( - object_type=ExtendedObjectType.RAW_EXTRINSIC_METADATA, object_id=_x(HASH), + object_type=ExtendedObjectType.RAW_EXTRINSIC_METADATA, + object_id=_x(HASH), ), ), ( @@ -247,7 +296,11 @@ def test_QualifiedSWHID_validation_error(ns, version, type, id, qualifiers): f"swh:1:cnt:{HASH};visit=swh:1:snp:{HASH}", ), (ObjectType.CONTENT, {"visit": 42}, TypeError), - (ObjectType.CONTENT, {"visit": f"swh:1:rel:{HASH}"}, ValidationError,), + ( + ObjectType.CONTENT, + {"visit": f"swh:1:rel:{HASH}"}, + ValidationError, + ), ( ObjectType.CONTENT, {"visit": CoreSWHID(object_type=ObjectType.RELEASE, object_id=_x(HASH))}, @@ -275,20 +328,32 @@ def test_QualifiedSWHID_validation_error(ns, version, type, id, qualifiers): f"swh:1:cnt:{HASH};anchor=swh:1:dir:{HASH}", ), (ObjectType.CONTENT, {"anchor": 42}, TypeError), - (ObjectType.CONTENT, {"anchor": f"swh:1:cnt:{HASH}"}, ValidationError,), + ( + ObjectType.CONTENT, + {"anchor": f"swh:1:cnt:{HASH}"}, + ValidationError, + ), ( ObjectType.CONTENT, {"anchor": CoreSWHID(object_type=ObjectType.CONTENT, object_id=_x(HASH))}, ValidationError, ), # path: - (ObjectType.CONTENT, {"path": b"/foo"}, f"swh:1:cnt:{HASH};path=/foo",), + ( + ObjectType.CONTENT, + {"path": b"/foo"}, + f"swh:1:cnt:{HASH};path=/foo", + ), ( ObjectType.CONTENT, {"path": b"/foo;bar"}, f"swh:1:cnt:{HASH};path=/foo%3Bbar", ), - (ObjectType.CONTENT, {"path": "/foo"}, f"swh:1:cnt:{HASH};path=/foo",), + ( + ObjectType.CONTENT, + {"path": "/foo"}, + f"swh:1:cnt:{HASH};path=/foo", + ), ( ObjectType.CONTENT, {"path": "/foo;bar"}, @@ -296,11 +361,31 @@ def test_QualifiedSWHID_validation_error(ns, version, type, id, qualifiers): ), (ObjectType.CONTENT, {"path": 42}, Exception), # lines: - (ObjectType.CONTENT, {"lines": (42, None)}, f"swh:1:cnt:{HASH};lines=42",), - (ObjectType.CONTENT, {"lines": (21, 42)}, f"swh:1:cnt:{HASH};lines=21-42",), - (ObjectType.CONTENT, {"lines": 42}, TypeError,), - (ObjectType.CONTENT, {"lines": (None, 42)}, ValueError,), - (ObjectType.CONTENT, {"lines": ("42", None)}, ValueError,), + ( + ObjectType.CONTENT, + {"lines": (42, None)}, + f"swh:1:cnt:{HASH};lines=42", + ), + ( + ObjectType.CONTENT, + {"lines": (21, 42)}, + f"swh:1:cnt:{HASH};lines=21-42", + ), + ( + ObjectType.CONTENT, + {"lines": 42}, + TypeError, + ), + ( + ObjectType.CONTENT, + {"lines": (None, 42)}, + ValueError, + ), + ( + ObjectType.CONTENT, + {"lines": ("42", None)}, + ValueError, + ), ], ) def test_QualifiedSWHID_init(object_type, qualifiers, expected): @@ -331,11 +416,15 @@ def test_QualifiedSWHID_hash(): assert hash( QualifiedSWHID( - object_type=ObjectType.DIRECTORY, object_id=object_id, **dummy_qualifiers, + object_type=ObjectType.DIRECTORY, + object_id=object_id, + **dummy_qualifiers, ) ) == hash( QualifiedSWHID( - object_type=ObjectType.DIRECTORY, object_id=object_id, **dummy_qualifiers, + object_type=ObjectType.DIRECTORY, + object_id=object_id, + **dummy_qualifiers, ) ) @@ -366,15 +455,23 @@ def test_QualifiedSWHID_eq(): ) == QualifiedSWHID(object_type=ObjectType.DIRECTORY, object_id=object_id) assert QualifiedSWHID( - object_type=ObjectType.DIRECTORY, object_id=object_id, **dummy_qualifiers, + object_type=ObjectType.DIRECTORY, + object_id=object_id, + **dummy_qualifiers, ) == QualifiedSWHID( - object_type=ObjectType.DIRECTORY, object_id=object_id, **dummy_qualifiers, + object_type=ObjectType.DIRECTORY, + object_id=object_id, + **dummy_qualifiers, ) assert QualifiedSWHID( - object_type=ObjectType.DIRECTORY, object_id=object_id, **dummy_qualifiers, + object_type=ObjectType.DIRECTORY, + object_id=object_id, + **dummy_qualifiers, ) == QualifiedSWHID( - object_type=ObjectType.DIRECTORY, object_id=object_id, **dummy_qualifiers, + object_type=ObjectType.DIRECTORY, + object_id=object_id, + **dummy_qualifiers, ) @@ -413,7 +510,10 @@ QUALIFIED_SWHIDS = [ visit=CoreSWHID(object_type=ObjectType.SNAPSHOT, object_id=_x(HASH)), ), ), - (f"swh:1:cnt:{HASH};visit=swh:1:rel:{HASH}", None,), + ( + f"swh:1:cnt:{HASH};visit=swh:1:rel:{HASH}", + None, + ), # anchor: ( f"swh:1:cnt:{HASH};anchor=swh:1:dir:{HASH}", @@ -468,18 +568,31 @@ QUALIFIED_SWHIDS = [ ( f"swh:1:cnt:{HASH};lines=1-18", QualifiedSWHID( - object_type=ObjectType.CONTENT, object_id=_x(HASH), lines=(1, 18), + object_type=ObjectType.CONTENT, + object_id=_x(HASH), + lines=(1, 18), ), ), ( f"swh:1:cnt:{HASH};lines=18", QualifiedSWHID( - object_type=ObjectType.CONTENT, object_id=_x(HASH), lines=(18, None), + object_type=ObjectType.CONTENT, + object_id=_x(HASH), + lines=(18, None), ), ), - (f"swh:1:cnt:{HASH};lines=", None,), - (f"swh:1:cnt:{HASH};lines=aa", None,), - (f"swh:1:cnt:{HASH};lines=18-aa", None,), + ( + f"swh:1:cnt:{HASH};lines=", + None, + ), + ( + f"swh:1:cnt:{HASH};lines=aa", + None, + ), + ( + f"swh:1:cnt:{HASH};lines=18-aa", + None, + ), ] @@ -529,7 +642,10 @@ def test_QualifiedSWHID_attributes(): def test_CoreSWHID_validation_error(ns, version, type, id): with pytest.raises(ValidationError): CoreSWHID( - namespace=ns, scheme_version=version, object_type=type, object_id=_x(id), + namespace=ns, + scheme_version=version, + object_type=type, + object_id=_x(id), ) @@ -541,14 +657,30 @@ def test_CoreSWHID_hash(): ) == hash(CoreSWHID(object_type=ObjectType.DIRECTORY, object_id=object_id)) assert hash( - CoreSWHID(object_type=ObjectType.DIRECTORY, object_id=object_id,) - ) == hash(CoreSWHID(object_type=ObjectType.DIRECTORY, object_id=object_id,)) + CoreSWHID( + object_type=ObjectType.DIRECTORY, + object_id=object_id, + ) + ) == hash( + CoreSWHID( + object_type=ObjectType.DIRECTORY, + object_id=object_id, + ) + ) # Different order of the dictionary, so the underlying order of the tuple in # ImmutableDict is different. assert hash( - CoreSWHID(object_type=ObjectType.DIRECTORY, object_id=object_id,) - ) == hash(CoreSWHID(object_type=ObjectType.DIRECTORY, object_id=object_id,)) + CoreSWHID( + object_type=ObjectType.DIRECTORY, + object_id=object_id, + ) + ) == hash( + CoreSWHID( + object_type=ObjectType.DIRECTORY, + object_id=object_id, + ) + ) def test_CoreSWHID_eq(): @@ -559,12 +691,20 @@ def test_CoreSWHID_eq(): ) == CoreSWHID(object_type=ObjectType.DIRECTORY, object_id=object_id) assert CoreSWHID( - object_type=ObjectType.DIRECTORY, object_id=object_id, - ) == CoreSWHID(object_type=ObjectType.DIRECTORY, object_id=object_id,) + object_type=ObjectType.DIRECTORY, + object_id=object_id, + ) == CoreSWHID( + object_type=ObjectType.DIRECTORY, + object_id=object_id, + ) assert CoreSWHID( - object_type=ObjectType.DIRECTORY, object_id=object_id, - ) == CoreSWHID(object_type=ObjectType.DIRECTORY, object_id=object_id,) + object_type=ObjectType.DIRECTORY, + object_id=object_id, + ) == CoreSWHID( + object_type=ObjectType.DIRECTORY, + object_id=object_id, + ) @pytest.mark.parametrize( @@ -588,7 +728,10 @@ def test_CoreSWHID_eq(): def test_ExtendedSWHID_validation_error(ns, version, type, id): with pytest.raises(ValidationError): ExtendedSWHID( - namespace=ns, scheme_version=version, object_type=type, object_id=_x(id), + namespace=ns, + scheme_version=version, + object_type=type, + object_id=_x(id), ) @@ -602,17 +745,29 @@ def test_ExtendedSWHID_hash(): ) assert hash( - ExtendedSWHID(object_type=ExtendedObjectType.DIRECTORY, object_id=object_id,) + ExtendedSWHID( + object_type=ExtendedObjectType.DIRECTORY, + object_id=object_id, + ) ) == hash( - ExtendedSWHID(object_type=ExtendedObjectType.DIRECTORY, object_id=object_id,) + ExtendedSWHID( + object_type=ExtendedObjectType.DIRECTORY, + object_id=object_id, + ) ) # Different order of the dictionary, so the underlying order of the tuple in # ImmutableDict is different. assert hash( - ExtendedSWHID(object_type=ExtendedObjectType.DIRECTORY, object_id=object_id,) + ExtendedSWHID( + object_type=ExtendedObjectType.DIRECTORY, + object_id=object_id, + ) ) == hash( - ExtendedSWHID(object_type=ExtendedObjectType.DIRECTORY, object_id=object_id,) + ExtendedSWHID( + object_type=ExtendedObjectType.DIRECTORY, + object_id=object_id, + ) ) @@ -624,12 +779,20 @@ def test_ExtendedSWHID_eq(): ) == ExtendedSWHID(object_type=ExtendedObjectType.DIRECTORY, object_id=object_id) assert ExtendedSWHID( - object_type=ExtendedObjectType.DIRECTORY, object_id=object_id, - ) == ExtendedSWHID(object_type=ExtendedObjectType.DIRECTORY, object_id=object_id,) + object_type=ExtendedObjectType.DIRECTORY, + object_id=object_id, + ) == ExtendedSWHID( + object_type=ExtendedObjectType.DIRECTORY, + object_id=object_id, + ) assert ExtendedSWHID( - object_type=ExtendedObjectType.DIRECTORY, object_id=object_id, - ) == ExtendedSWHID(object_type=ExtendedObjectType.DIRECTORY, object_id=object_id,) + object_type=ExtendedObjectType.DIRECTORY, + object_id=object_id, + ) == ExtendedSWHID( + object_type=ExtendedObjectType.DIRECTORY, + object_id=object_id, + ) def test_object_types():