From 1d0c321275d27b6d194e3768990f4a983fbe6360 Mon Sep 17 00:00:00 2001
From: Valentin Lorentz <vlorentz@softwareheritage.org>
Date: Tue, 12 Jan 2021 12:24:35 +0100
Subject: [PATCH] test_identifiers: Reorder SWHID tests.

They were mixed in with snapshot tests.
---
 swh/model/tests/test_identifiers.py | 238 ++++++++++++++--------------
 1 file changed, 120 insertions(+), 118 deletions(-)

diff --git a/swh/model/tests/test_identifiers.py b/swh/model/tests/test_identifiers.py
index 889fc9fa..470f8ed9 100644
--- a/swh/model/tests/test_identifiers.py
+++ b/swh/model/tests/test_identifiers.py
@@ -763,6 +763,126 @@ class SnapshotIdentifier(unittest.TestCase):
             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 SnapshotIdentifier(unittest.TestCase):
             )
 
 
-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",
     [
-- 
GitLab