Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9749581
D772.id2422.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Subscribers
None
D772.id2422.diff
View Options
diff --git a/swh/loader/core/tests/__init__.py b/swh/loader/core/tests/__init__.py
--- a/swh/loader/core/tests/__init__.py
+++ b/swh/loader/core/tests/__init__.py
@@ -3,11 +3,13 @@
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
+import functools
import os
import pytest
import shutil
import subprocess
import tempfile
+import warnings
from unittest import TestCase
@@ -15,8 +17,28 @@
from swh.model.hashutil import hash_to_bytes
+def alias(new_method):
+ @functools.wraps(new_method)
+ def newf(self, *args, **kwargs):
+ # Find which method is myself, to infer my own name
+ for attr_name in dir(self.__class__):
+ if getattr(self.__class__, attr_name) is newf:
+ old_name = attr_name
+ break
+ else:
+ assert False, 'Result of alias() was not bound to a class.'
+
+ message = '{old_name} is deprecated, please use {new_name} instead' \
+ .format(old_name=old_name, new_name=new_method.__name__)
+ warnings.warn(message, DeprecationWarning, stacklevel=2)
+
+ return new_method(self, *args, **kwargs)
+
+ return newf
+
+
class BaseLoaderStorageTest:
- def _assertCountOk(self, type, expected_length, msg=None):
+ def _assertCountEqual(self, type, expected_length, msg=None):
"""Check typed 'type' state to have the same expected length.
"""
@@ -25,47 +47,62 @@
expected_length, msg=msg)
def assertCountContents(self, len_expected_contents, msg=None):
- self._assertCountOk('content', len_expected_contents, msg=msg)
+ self._assertCountEqual('content', len_expected_contents, msg=msg)
def assertCountDirectories(self, len_expected_directories, msg=None):
- self._assertCountOk('directory', len_expected_directories, msg=msg)
+ self._assertCountEqual('directory', len_expected_directories,
+ msg=msg)
def assertCountReleases(self, len_expected_releases, msg=None):
- self._assertCountOk('release', len_expected_releases, msg=msg)
+ self._assertCountEqual('release', len_expected_releases, msg=msg)
def assertCountRevisions(self, len_expected_revisions, msg=None):
- self._assertCountOk('revision', len_expected_revisions, msg=msg)
+ self._assertCountEqual('revision', len_expected_revisions, msg=msg)
def assertCountSnapshots(self, len_expected_snapshot, msg=None):
- self._assertCountOk('snapshot', len_expected_snapshot, msg=msg)
+ self._assertCountEqual('snapshot', len_expected_snapshot, msg=msg)
- def assertContentsOk(self, expected_contents):
- self._assertCountOk('content', len(expected_contents))
+ def assertContentsContain(self, expected_contents):
+ """Checks the provided content are a subset of the stored ones.
+
+ Args:
+ expected_contents ([sha1]): List of content ids"""
+ self._assertCountEqual('content', len(expected_contents))
missing = list(self.storage.content_missing(
{'sha1': hash_to_bytes(content_hash)}
for content_hash in expected_contents))
self.assertEqual(missing, [])
- def assertDirectoriesOk(self, expected_directories):
- self._assertCountOk('directory', len(expected_directories))
+ assertContentsOk = alias(assertContentsContain)
+
+ def assertDirectoriesContain(self, expected_directories):
+ """Checks the provided directories are a subset of the stored ones.
+
+ Args:
+ expected_directories ([sha1]): List of directory ids."""
+ self._assertCountEqual('directory', len(expected_directories))
missing = list(self.storage.directory_missing(
dir_['id'] for dir_ in expected_directories))
self.assertEqual(missing, [])
- def assertReleasesOk(self, expected_releases):
- """Check the loader's releases match the expected releases.
+ assertDirectoriesOk = alias(assertDirectoriesContain)
+
+ def assertReleasesContain(self, expected_releases):
+ """Checks the provided releases are a subset of the stored ones.
Args:
releases ([dict]): List of dictionaries representing swh releases.
"""
- self._assertCountOk('release', len(expected_releases))
+ self._assertCountEqual('release', len(expected_releases))
missing = list(self.storage.releases_missing(
rel['id'] for rel in expected_releases))
self.assertEqual(missing, [])
- def assertRevisionsOk(self, expected_revisions):
- """Check the loader's revisions match the expected revisions.
+ assertReleasesOk = alias(assertReleasesContain)
+
+ def assertRevisionsContain(self, expected_revisions):
+ """Checks the provided revisions are a subset of the stored ones.
Expects self.loader to be instantiated and ready to be
inspected (meaning the loading took place).
@@ -75,7 +112,7 @@
value the targeted directory id.
"""
- self._assertCountOk('revision', len(expected_revisions))
+ self._assertCountEqual('revision', len(expected_revisions))
revs = list(self.storage.revision_get(
hashutil.hash_to_bytes(rev_id) for rev_id in expected_revisions))
@@ -85,7 +122,9 @@
{hash_to_bytes(rev_id): hash_to_bytes(rev_dir)
for (rev_id, rev_dir) in expected_revisions.items()})
- def assertSnapshotOk(self, expected_snapshot, expected_branches=[]):
+ assertRevisionsOk = alias(assertRevisionsContain)
+
+ def assertSnapshotEqual(self, expected_snapshot, expected_branches=[]):
"""Check for snapshot match.
Provide the hashes as hexadecimal, the conversion is done
@@ -106,7 +145,7 @@
else:
expected_snapshot_id = expected_snapshot
- self._assertCountOk('snapshot', 1)
+ self._assertCountEqual('snapshot', 1)
snap = self.storage.snapshot_get(hash_to_bytes(expected_snapshot_id))
self.assertIsNotNone(snap)
@@ -132,6 +171,8 @@
}
self.assertEqual(expected_branches, branches)
+ assertSnapshotOk = alias(assertSnapshotEqual)
+
@pytest.mark.fs
class BaseLoaderTest(TestCase, BaseLoaderStorageTest):
diff --git a/swh/loader/core/tests/test_compatibility.py b/swh/loader/core/tests/test_compatibility.py
new file mode 100644
--- /dev/null
+++ b/swh/loader/core/tests/test_compatibility.py
@@ -0,0 +1,22 @@
+# Copyright (C) 2018 The Software Heritage developers
+# See the AUTHORS file at the top-level directory of this distribution
+# License: GNU General Public License version 3, or any later version
+# See top-level LICENSE file for more information
+
+from unittest import TestCase
+import warnings
+
+from . import BaseLoaderStorageTest
+from swh.storage.in_memory import Storage
+
+
+class DeprecatedAliasesTest(BaseLoaderStorageTest, TestCase):
+ def test_deprecated_aliases(self):
+ self.storage = Storage()
+ with warnings.catch_warnings(record=True) as w:
+ self.assertContentsOk([])
+
+ self.assertEqual(len(w), 1, w)
+ self.assertTrue(issubclass(w[0].category, DeprecationWarning))
+ self.assertIn('use assertContentsContain instead',
+ str(w[0].message))
diff --git a/swh/loader/core/tests/test_loader.py b/swh/loader/core/tests/test_loader.py
--- a/swh/loader/core/tests/test_loader.py
+++ b/swh/loader/core/tests/test_loader.py
@@ -122,7 +122,7 @@
"""
self.storage.content_add(self.in_contents)
self.assertCountContents(len(self.expected_contents))
- self.assertContentsOk(self.expected_contents)
+ self.assertContentsContain(self.expected_contents)
def test_failing(self):
"""Comparing wrong snapshot should fail.
@@ -130,7 +130,7 @@
"""
self.storage.content_add(self.in_contents)
with self.assertRaises(AssertionError):
- self.assertContentsOk([])
+ self.assertContentsContain([])
class LoadTestDirectory(DummyBaseLoaderTest):
@@ -140,7 +140,7 @@
"""
self.storage.directory_add(self.in_directories)
self.assertCountDirectories(len(self.in_directories))
- self.assertDirectoriesOk(self.in_directories)
+ self.assertDirectoriesContain(self.in_directories)
def test_failing(self):
"""Comparing wrong snapshot should fail.
@@ -148,4 +148,4 @@
"""
self.storage.directory_add(self.in_directories)
with self.assertRaises(AssertionError):
- self.assertDirectoriesOk([])
+ self.assertDirectoriesContain([])
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Aug 24, 5:59 PM (5 d, 2 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3225712
Attached To
D772: Rename equality test methods.
Event Timeline
Log In to Comment