Changeset View
Standalone View
swh/storage/tests/test_storage.py
Show All 10 Lines | |||||
from collections import defaultdict | from collections import defaultdict | ||||
from unittest.mock import Mock, patch | from unittest.mock import Mock, patch | ||||
import psycopg2 | import psycopg2 | ||||
import pytest | import pytest | ||||
from hypothesis import given, strategies, settings, HealthCheck | from hypothesis import given, strategies, settings, HealthCheck | ||||
from typing import ClassVar, Optional | |||||
from swh.model import from_disk, identifiers | from swh.model import from_disk, identifiers | ||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.hypothesis_strategies import origins, objects | from swh.model.hypothesis_strategies import origins, objects | ||||
from swh.storage.tests.storage_testing import StorageTestFixture | from swh.storage.tests.storage_testing import StorageTestFixture | ||||
from swh.storage import HashCollision | from swh.storage import HashCollision | ||||
from .generate_data_test import gen_contents | from .generate_data_test import gen_contents | ||||
Show All 10 Lines | def setUp(self): | ||||
self.maxDiff = None | self.maxDiff = None | ||||
def tearDown(self): | def tearDown(self): | ||||
self.reset_storage() | self.reset_storage() | ||||
super().tearDown() | super().tearDown() | ||||
class TestStorageData: | class TestStorageData: | ||||
def setUp(self): | def setUp(self, *args, **kwargs): | ||||
super().setUp() | super().setUp(*args, **kwargs) | ||||
vlorentz: why? | |||||
Done Inline Actionsbecause without it:
and mypy is right, as the base class and the original fixture from s.s.t.storage_testing are used together, they should have compatible signatures zack: because without it:
> swh/storage/tests/test_storage.py:3926: error: Definition of "setUp" in… | |||||
Done Inline ActionsYou should remove these arguments to setUp from the parent classes then. I don't think we need it since douardda's refactoring of test classes months ago vlorentz: You should remove these arguments to `setUp` from the parent classes then. I don't think we… | |||||
Done Inline ActionsActually, wrong reference in mu previous message, the *args/**kwargs come from the DbTestFixture class in swh-core, not from swh-storage. I don't mind removing those args from there, but: (1) I cannot do that in this diff; (2) can @douardda confirm they should go? zack: Actually, wrong reference in mu previous message, the `*args/**kwargs` come from the… | |||||
Not Done Inline ActionsI'm ok with adding these generic args here. In fact, I have a WIP to simply remove this 'data class' from the tests, but it's not ready for review yet. So meanwhile, the path of least work is just fine. douardda: I'm ok with adding these generic args here. In fact, I have a WIP to simply remove this 'data… | |||||
self.cont = { | self.cont = { | ||||
'data': b'42\n', | 'data': b'42\n', | ||||
'length': 3, | 'length': 3, | ||||
'sha1': hash_to_bytes( | 'sha1': hash_to_bytes( | ||||
'34973274ccef6ab4dfaaf86599792fa9c3fe4689'), | '34973274ccef6ab4dfaaf86599792fa9c3fe4689'), | ||||
'sha1_git': hash_to_bytes( | 'sha1_git': hash_to_bytes( | ||||
'd81cc0710eb6cf9efd5b920a8453e1e07157b6cd'), | 'd81cc0710eb6cf9efd5b920a8453e1e07157b6cd'), | ||||
'sha256': hash_to_bytes( | 'sha256': hash_to_bytes( | ||||
▲ Show 20 Lines • Show All 492 Lines • ▼ Show 20 Lines | class CommonTestStorage(TestStorageData): | ||||
below) and remote storage (see TestRemoteStorage in | below) and remote storage (see TestRemoteStorage in | ||||
test_remote_storage.py. | test_remote_storage.py. | ||||
We need to have the two classes inherit from this base class | We need to have the two classes inherit from this base class | ||||
separately to avoid nosetests running the tests from the base | separately to avoid nosetests running the tests from the base | ||||
class twice. | class twice. | ||||
""" | """ | ||||
maxDiff = None | maxDiff = None # type: ClassVar[Optional[int]] | ||||
_test_origin_ids = True | _test_origin_ids = True | ||||
@staticmethod | @staticmethod | ||||
def normalize_entity(entity): | def normalize_entity(entity): | ||||
entity = copy.deepcopy(entity) | entity = copy.deepcopy(entity) | ||||
for key in ('date', 'committer_date'): | for key in ('date', 'committer_date'): | ||||
if key in entity: | if key in entity: | ||||
entity[key] = identifiers.normalize_timestamp(entity[key]) | entity[key] = identifiers.normalize_timestamp(entity[key]) | ||||
▲ Show 20 Lines • Show All 3,539 Lines • Show Last 20 Lines |
why?