Page MenuHomeSoftware Heritage

D6279.diff
No OneTemporary

D6279.diff

diff --git a/swh/loader/git/tests/test_converters.py b/swh/loader/git/tests/test_converters.py
--- a/swh/loader/git/tests/test_converters.py
+++ b/swh/loader/git/tests/test_converters.py
@@ -7,7 +7,6 @@
import shutil
import subprocess
import tempfile
-import unittest
import dulwich.repo
import pytest
@@ -117,10 +116,9 @@
@pytest.mark.fs
-class TestConverters(unittest.TestCase):
+class TestConverters:
@classmethod
- def setUpClass(cls):
- super().setUpClass()
+ def setup_class(cls):
cls.repo_path = tempfile.mkdtemp()
bundle = os.path.join(TEST_DATA, "git-repos", "example-submodule.bundle")
@@ -161,7 +159,7 @@
length=124,
status="visible",
)
- self.assertEqual(content, expected_content)
+ assert content == expected_content
def test_convertion_wrong_input(self):
class Something:
@@ -176,7 +174,7 @@
}
for _callable in m.values():
- with self.assertRaises(ValueError):
+ with pytest.raises(ValueError):
_callable(Something())
def test_commit_to_revision(self):
@@ -214,7 +212,7 @@
synthetic=False,
)
- self.assertEqual(revision, expected_revision)
+ assert revision == expected_revision
def test_commit_to_revision_with_extra_headers(self):
sha1 = b"322f5bc915e50fc25e85226b5a182bded0e98e4b"
@@ -295,7 +293,7 @@
def test_author_line_to_author(self):
# edge case out of the way
- with self.assertRaises(TypeError):
+ with pytest.raises(TypeError):
converters.parse_author(None)
tests = {
@@ -318,7 +316,7 @@
for author in sorted(tests):
parsed_author = tests[author]
- self.assertEqual(parsed_author, converters.parse_author(author))
+ assert parsed_author == converters.parse_author(author)
def test_dulwich_tag_to_release_no_author_no_date(self):
target = b"641fb6e08ddb2e4fd096dcf18e80b894bf"
@@ -351,7 +349,7 @@
target_type=ObjectType.REVISION,
)
- self.assertEqual(actual_release, expected_release)
+ assert actual_release == expected_release
def test_dulwich_tag_to_release_author_and_date(self):
tagger = b"hey dude <hello@mail.org>"
@@ -398,7 +396,7 @@
target_type=ObjectType.REVISION,
)
- self.assertEqual(actual_release, expected_release)
+ assert actual_release == expected_release
def test_dulwich_tag_to_release_author_no_date(self):
# to reproduce bug T815 (fixed)
@@ -437,7 +435,7 @@
target_type=ObjectType.REVISION,
)
- self.assertEqual(actual_release, expected_release)
+ assert actual_release == expected_release
def test_dulwich_tag_to_release_signature(self):
target = b"641fb6e08ddb2e4fd096dcf18e80b894bf"
@@ -470,4 +468,4 @@
target_type=ObjectType.REVISION,
)
- self.assertEqual(actual_release, expected_release)
+ assert actual_release == expected_release
diff --git a/swh/loader/git/tests/test_from_disk.py b/swh/loader/git/tests/test_from_disk.py
--- a/swh/loader/git/tests/test_from_disk.py
+++ b/swh/loader/git/tests/test_from_disk.py
@@ -6,7 +6,6 @@
import copy
import datetime
import os.path
-from unittest import TestCase
import dulwich.objects
import dulwich.porcelain
@@ -500,7 +499,7 @@
)
-class GitLoaderFromDiskTest(TestCase, FullGitLoaderTests):
+class TestGitLoaderFromDisk(FullGitLoaderTests):
"""Prepare a git directory repository to be loaded through a GitLoaderFromDisk.
This tests all git loader scenario.
@@ -526,7 +525,7 @@
self.repo = dulwich.repo.Repo(self.destination_path)
-class GitLoaderFromArchiveTest(TestCase, CommonGitLoaderTests):
+class TestGitLoaderFromArchive(CommonGitLoaderTests):
"""Tests for GitLoaderFromArchive. Only tests common scenario."""
@pytest.fixture(autouse=True)
diff --git a/swh/loader/git/tests/test_loader.py b/swh/loader/git/tests/test_loader.py
--- a/swh/loader/git/tests/test_loader.py
+++ b/swh/loader/git/tests/test_loader.py
@@ -4,7 +4,6 @@
# See top-level LICENSE file for more information
import os
-from unittest import TestCase
from dulwich.errors import GitProtocolError, NotGitRepository, ObjectFormatException
import dulwich.repo
@@ -23,67 +22,65 @@
"""
self.mocker = mocker
- def test_load_visit_not_found(self):
- """Ingesting an unknown url result in a visit with not_found status
-
- """
- for failure_exception in [
+ @pytest.mark.parametrize(
+ "failure_exception",
+ [
GitProtocolError("Repository unavailable"), # e.g DMCA takedown
GitProtocolError("Repository not found"),
GitProtocolError("unexpected http resp 401"),
NotGitRepository("not a git repo"),
- ]:
- with self.subTest(failure_exception=failure_exception):
- # simulate an initial communication error (e.g no repository found, ...)
- mock = self.mocker.patch(
- "swh.loader.git.loader.GitLoader.fetch_pack_from_origin"
- )
- mock.side_effect = failure_exception
-
- res = self.loader.load()
- assert res == {"status": "uneventful"}
-
- assert_last_visit_matches(
- self.loader.storage,
- self.repo_url,
- status="not_found",
- type="git",
- snapshot=None,
- )
-
- def test_load_visit_failure(self):
+ ],
+ )
+ def test_load_visit_not_found(self, failure_exception):
+ """Ingesting an unknown url result in a visit with not_found status
+
+ """
+ # simulate an initial communication error (e.g no repository found, ...)
+ mock = self.mocker.patch(
+ "swh.loader.git.loader.GitLoader.fetch_pack_from_origin"
+ )
+ mock.side_effect = failure_exception
+
+ res = self.loader.load()
+ assert res == {"status": "uneventful"}
+
+ assert_last_visit_matches(
+ self.loader.storage,
+ self.repo_url,
+ status="not_found",
+ type="git",
+ snapshot=None,
+ )
+
+ @pytest.mark.parametrize(
+ "failure_exception",
+ [IOError, ObjectFormatException, OSError, ValueError, GitProtocolError,],
+ )
+ def test_load_visit_failure(self, failure_exception):
"""Failing during the fetch pack step result in failing visit
"""
- for failure_exception in [
- IOError,
- ObjectFormatException,
- OSError,
- ValueError,
- GitProtocolError,
- ]:
- with self.subTest(failure_exception=failure_exception):
- # simulate a fetch communication error after the initial connection
- # server error (e.g IOError, ObjectFormatException, ...)
- mock = self.mocker.patch(
- "swh.loader.git.loader.GitLoader.fetch_pack_from_origin"
- )
-
- mock.side_effect = failure_exception("failure")
-
- res = self.loader.load()
- assert res == {"status": "failed"}
-
- assert_last_visit_matches(
- self.loader.storage,
- self.repo_url,
- status="failed",
- type="git",
- snapshot=None,
- )
-
-
-class GitLoaderTest(TestCase, FullGitLoaderTests, CommonGitLoaderNotFound):
+ # simulate a fetch communication error after the initial connection
+ # server error (e.g IOError, ObjectFormatException, ...)
+ mock = self.mocker.patch(
+ "swh.loader.git.loader.GitLoader.fetch_pack_from_origin"
+ )
+
+ mock.side_effect = failure_exception("failure")
+
+ res = self.loader.load()
+ assert res == {"status": "failed"}
+
+ assert_last_visit_matches(
+ self.loader.storage,
+ self.repo_url,
+ status="failed",
+ type="git",
+ snapshot=None,
+ )
+
+
+class TestGitLoader(FullGitLoaderTests, CommonGitLoaderNotFound):
"""Prepare a git directory repository to be loaded through a GitLoader.
This tests all git loader scenario.
@@ -91,7 +88,6 @@
@pytest.fixture(autouse=True)
def init(self, swh_storage, datadir, tmp_path):
- super().setUp()
archive_name = "testrepo"
archive_path = os.path.join(datadir, f"{archive_name}.tgz")
tmp_path = str(tmp_path)
@@ -103,7 +99,7 @@
self.repo = dulwich.repo.Repo(self.destination_path)
-class GitLoader2Test(TestCase, FullGitLoaderTests, CommonGitLoaderNotFound):
+class TestGitLoader2(FullGitLoaderTests, CommonGitLoaderNotFound):
"""Mostly the same loading scenario but with a base-url different than the repo-url.
To walk slightly different paths, the end result should stay the same.
@@ -111,7 +107,6 @@
@pytest.fixture(autouse=True)
def init(self, swh_storage, datadir, tmp_path):
- super().setUp()
archive_name = "testrepo"
archive_path = os.path.join(datadir, f"{archive_name}.tgz")
tmp_path = str(tmp_path)
diff --git a/swh/loader/git/tests/test_utils.py b/swh/loader/git/tests/test_utils.py
--- a/swh/loader/git/tests/test_utils.py
+++ b/swh/loader/git/tests/test_utils.py
@@ -3,12 +3,12 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
-import unittest
+import pytest
from swh.loader.git import utils
-class TestUtils(unittest.TestCase):
+class TestUtils:
def test_check_date_time(self):
"""A long as datetime is fine, date time check does not raise
@@ -18,7 +18,7 @@
utils.check_date_time(ts)
def test_check_date_time_empty_value(self):
- self.assertIsNone(utils.check_date_time(None))
+ assert utils.check_date_time(None) is None
def test_check_date_time_raises(self):
"""From a give threshold, check will no longer works.
@@ -26,5 +26,5 @@
"""
exp = 38
timestamp = 2 ** exp
- with self.assertRaisesRegex(ValueError, "is out of range"):
+ with pytest.raises(ValueError, match=".*is out of range.*"):
utils.check_date_time(timestamp)

File Metadata

Mime Type
text/plain
Expires
Thu, Jul 3, 3:46 PM (2 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3224235

Event Timeline