Page MenuHomeSoftware Heritage

D4840.diff
No OneTemporary

D4840.diff

diff --git a/swh/model/tests/test_identifiers.py b/swh/model/tests/test_identifiers.py
--- a/swh/model/tests/test_identifiers.py
+++ b/swh/model/tests/test_identifiers.py
@@ -763,6 +763,126 @@
identifiers.identifier_to_str(self.all_types["id"]),
)
+
+class OriginIdentifier(unittest.TestCase):
+ def setUp(self):
+ self.origin = {
+ "url": "https://github.com/torvalds/linux",
+ }
+
+ def test_content_identifier(self):
+ self.assertEqual(
+ identifiers.origin_identifier(self.origin),
+ "b63a575fe3faab7692c9f38fb09d4bb45651bb0f",
+ )
+
+
+TS_DICTS = [
+ (
+ {"timestamp": 12345, "offset": 0},
+ {
+ "timestamp": {"seconds": 12345, "microseconds": 0},
+ "offset": 0,
+ "negative_utc": False,
+ },
+ ),
+ (
+ {"timestamp": 12345, "offset": 0, "negative_utc": False},
+ {
+ "timestamp": {"seconds": 12345, "microseconds": 0},
+ "offset": 0,
+ "negative_utc": False,
+ },
+ ),
+ (
+ {"timestamp": 12345, "offset": 0, "negative_utc": False},
+ {
+ "timestamp": {"seconds": 12345, "microseconds": 0},
+ "offset": 0,
+ "negative_utc": False,
+ },
+ ),
+ (
+ {"timestamp": 12345, "offset": 0, "negative_utc": None},
+ {
+ "timestamp": {"seconds": 12345, "microseconds": 0},
+ "offset": 0,
+ "negative_utc": False,
+ },
+ ),
+ (
+ {"timestamp": {"seconds": 12345}, "offset": 0, "negative_utc": None},
+ {
+ "timestamp": {"seconds": 12345, "microseconds": 0},
+ "offset": 0,
+ "negative_utc": False,
+ },
+ ),
+ (
+ {
+ "timestamp": {"seconds": 12345, "microseconds": 0},
+ "offset": 0,
+ "negative_utc": None,
+ },
+ {
+ "timestamp": {"seconds": 12345, "microseconds": 0},
+ "offset": 0,
+ "negative_utc": False,
+ },
+ ),
+ (
+ {
+ "timestamp": {"seconds": 12345, "microseconds": 100},
+ "offset": 0,
+ "negative_utc": None,
+ },
+ {
+ "timestamp": {"seconds": 12345, "microseconds": 100},
+ "offset": 0,
+ "negative_utc": False,
+ },
+ ),
+ (
+ {"timestamp": 12345, "offset": 0, "negative_utc": True},
+ {
+ "timestamp": {"seconds": 12345, "microseconds": 0},
+ "offset": 0,
+ "negative_utc": True,
+ },
+ ),
+ (
+ {"timestamp": 12345, "offset": 0, "negative_utc": None},
+ {
+ "timestamp": {"seconds": 12345, "microseconds": 0},
+ "offset": 0,
+ "negative_utc": False,
+ },
+ ),
+]
+
+
+@pytest.mark.parametrize("dict_input,expected", TS_DICTS)
+def test_normalize_timestamp_dict(dict_input, expected):
+ assert normalize_timestamp(dict_input) == expected
+
+
+TS_DICTS_INVALID_TIMESTAMP = [
+ {"timestamp": 1.2, "offset": 0},
+ {"timestamp": "1", "offset": 0},
+ # these below should really also trigger a ValueError...
+ # {"timestamp": {"seconds": "1"}, "offset": 0},
+ # {"timestamp": {"seconds": 1.2}, "offset": 0},
+ # {"timestamp": {"seconds": 1.2}, "offset": 0},
+]
+
+
+@pytest.mark.parametrize("dict_input", TS_DICTS_INVALID_TIMESTAMP)
+def test_normalize_timestamp_dict_invalid_timestamp(dict_input):
+ with pytest.raises(ValueError, match="non-integer timestamp"):
+ normalize_timestamp(dict_input)
+
+
+class TestSwhid(unittest.TestCase):
def test_swhid(self):
_snapshot_id = _x("c7c108084bc0bf3d81436bf980b46e98bd338453")
_release_id = "22ece559cc7cc2364edc5e5593d63ae8bd229f9f"
@@ -955,124 +1075,6 @@
)
-class OriginIdentifier(unittest.TestCase):
- def setUp(self):
- self.origin = {
- "url": "https://github.com/torvalds/linux",
- }
-
- def test_content_identifier(self):
- self.assertEqual(
- identifiers.origin_identifier(self.origin),
- "b63a575fe3faab7692c9f38fb09d4bb45651bb0f",
- )
-
-
-TS_DICTS = [
- (
- {"timestamp": 12345, "offset": 0},
- {
- "timestamp": {"seconds": 12345, "microseconds": 0},
- "offset": 0,
- "negative_utc": False,
- },
- ),
- (
- {"timestamp": 12345, "offset": 0, "negative_utc": False},
- {
- "timestamp": {"seconds": 12345, "microseconds": 0},
- "offset": 0,
- "negative_utc": False,
- },
- ),
- (
- {"timestamp": 12345, "offset": 0, "negative_utc": False},
- {
- "timestamp": {"seconds": 12345, "microseconds": 0},
- "offset": 0,
- "negative_utc": False,
- },
- ),
- (
- {"timestamp": 12345, "offset": 0, "negative_utc": None},
- {
- "timestamp": {"seconds": 12345, "microseconds": 0},
- "offset": 0,
- "negative_utc": False,
- },
- ),
- (
- {"timestamp": {"seconds": 12345}, "offset": 0, "negative_utc": None},
- {
- "timestamp": {"seconds": 12345, "microseconds": 0},
- "offset": 0,
- "negative_utc": False,
- },
- ),
- (
- {
- "timestamp": {"seconds": 12345, "microseconds": 0},
- "offset": 0,
- "negative_utc": None,
- },
- {
- "timestamp": {"seconds": 12345, "microseconds": 0},
- "offset": 0,
- "negative_utc": False,
- },
- ),
- (
- {
- "timestamp": {"seconds": 12345, "microseconds": 100},
- "offset": 0,
- "negative_utc": None,
- },
- {
- "timestamp": {"seconds": 12345, "microseconds": 100},
- "offset": 0,
- "negative_utc": False,
- },
- ),
- (
- {"timestamp": 12345, "offset": 0, "negative_utc": True},
- {
- "timestamp": {"seconds": 12345, "microseconds": 0},
- "offset": 0,
- "negative_utc": True,
- },
- ),
- (
- {"timestamp": 12345, "offset": 0, "negative_utc": None},
- {
- "timestamp": {"seconds": 12345, "microseconds": 0},
- "offset": 0,
- "negative_utc": False,
- },
- ),
-]
-
-
-@pytest.mark.parametrize("dict_input,expected", TS_DICTS)
-def test_normalize_timestamp_dict(dict_input, expected):
- assert normalize_timestamp(dict_input) == expected
-
-
-TS_DICTS_INVALID_TIMESTAMP = [
- {"timestamp": 1.2, "offset": 0},
- {"timestamp": "1", "offset": 0},
- # these below should really also trigger a ValueError...
- # {"timestamp": {"seconds": "1"}, "offset": 0},
- # {"timestamp": {"seconds": 1.2}, "offset": 0},
- # {"timestamp": {"seconds": 1.2}, "offset": 0},
-]
-
-
-@pytest.mark.parametrize("dict_input", TS_DICTS_INVALID_TIMESTAMP)
-def test_normalize_timestamp_dict_invalid_timestamp(dict_input):
- with pytest.raises(ValueError, match="non-integer timestamp"):
- normalize_timestamp(dict_input)
-
-
@pytest.mark.parametrize(
"invalid_swhid",
[

File Metadata

Mime Type
text/plain
Expires
Dec 20 2024, 7:21 PM (11 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3219443

Event Timeline