Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/core/tests/test_loader.py
# Copyright (C) 2018 The Software Heritage developers | # Copyright (C) 2018-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import datetime | import datetime | ||||
import hashlib | |||||
import logging | import logging | ||||
import pytest | |||||
from swh.model.hashutil import hash_to_bytes | from swh.model.hashutil import hash_to_bytes | ||||
from swh.loader.core.loader import BufferedLoader, UnbufferedLoader | from swh.loader.core.loader import BufferedLoader, UnbufferedLoader | ||||
from . import BaseLoaderTest | from . import BaseLoaderTest | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | def parse_config_file(self, *args, **kwargs): | ||||
} | } | ||||
class DummyUnbufferedLoader(DummyLoader, UnbufferedLoader): | class DummyUnbufferedLoader(DummyLoader, UnbufferedLoader): | ||||
pass | pass | ||||
class DummyBufferedLoader(DummyLoader, BufferedLoader): | class DummyBufferedLoader(DummyLoader, BufferedLoader): | ||||
pass | def __init__(self, *args, save_data_path=None, **kwargs): | ||||
super().__init__(*args, **kwargs) | |||||
vlorentz: This is a private attribute. It won't be accessed by another other class and this one is empty. | |||||
Not Done Inline Actionsyeah please, don't use 'private' attributes, like ever. This mangling magic stuff is nothing but garbage... douardda: yeah please, don't use 'private' attributes, like ever. This mangling magic stuff is nothing… | |||||
Done Inline ActionsAt the time, it was to make the test pass as this would not otherwise. ardumont: At the time, it was to make the test pass as this would not otherwise.
I'm currently trying to… | |||||
Done Inline ActionsAs it works without those, removed! I must have mis-analyzed the issue at the time. ardumont: As it works without those, removed! I must have mis-analyzed the issue at the time.
Thanks for… | |||||
self.__save_data_path = save_data_path | |||||
class DummyBaseLoaderTest(BaseLoaderTest): | class DummyBaseLoaderTest(BaseLoaderTest): | ||||
def setUp(self): | def setUp(self): | ||||
self.loader = self.loader_class(logging_class='dummyloader') | self.loader = self.loader_class(logging_class='dummyloader') | ||||
self.loader.visit_type = 'git' | self.loader.visit_type = 'git' | ||||
# do not call voluntarily super().setUp() | # do not call voluntarily super().setUp() | ||||
self.storage = self.loader.storage | self.storage = self.loader.storage | ||||
▲ Show 20 Lines • Show All 264 Lines • ▼ Show 20 Lines | assert loader.log.name == \ | ||||
'swh.loader.core.tests.test_loader.DummyUnbufferedLoader' | 'swh.loader.core.tests.test_loader.DummyUnbufferedLoader' | ||||
def test_loader_logger_with_name(): | def test_loader_logger_with_name(): | ||||
loader = DummyBufferedLoader('some.logger.name') | loader = DummyBufferedLoader('some.logger.name') | ||||
assert isinstance(loader.log, logging.Logger) | assert isinstance(loader.log, logging.Logger) | ||||
assert loader.log.name == \ | assert loader.log.name == \ | ||||
'some.logger.name' | 'some.logger.name' | ||||
@pytest.mark.fs | |||||
def test_loader_save_data_path(tmp_path): | |||||
loader = DummyBufferedLoader('some.logger.name.1') | |||||
url = 'http://bitbucket.org/something' | |||||
loader.origin = { | |||||
'url': url, | |||||
} | |||||
loader.visit_date = datetime.datetime(year=2019, month=10, day=1) | |||||
loader.config = { | |||||
'save_data_path': tmp_path, | |||||
} | |||||
Not Done Inline ActionsThis will always be True. Double underscore attributes get a mangled name. In [1]: class Foo: ...: def __init__(self): ...: self.__bla = None ...: In [2]: foo = Foo() In [3]: foo.__dict__ Out[3]: {'_Foo__bla': None} In [4]: hasattr(foo, '__bla') Out[4]: False I'm not sure what you're really asserting here? olasd: This will always be True. Double underscore attributes get a mangled name.
```lang=python
In… | |||||
Done Inline ActionsRemoved. ardumont: Removed. | |||||
hash_url = hashlib.sha1(url.encode('utf-8')).hexdigest() | |||||
expected_save_path = '%s/sha1:%s/%s/2019' % ( | |||||
str(tmp_path), hash_url[0:2], hash_url | |||||
Not Done Inline Actionsthis syntax is so weird... vlorentz: this syntax is so weird... | |||||
Done Inline Actionswell, it wouldn't want me to mix the tuple and the PosixPath "string" so meh... ardumont: well, it wouldn't want me to mix the tuple and the PosixPath "string" so meh... | |||||
) | |||||
save_path = loader.get_save_data_path() | |||||
assert save_path == expected_save_path | |||||
Not Done Inline ActionsUse a finally to remove it even on test failure. Or, even better: pytest's tmp_path fixture: http://doc.pytest.org/en/latest/tmpdir.html vlorentz: Use a finally to remove it even on test failure. Or, even better: pytest's `tmp_path` fixture… | |||||
Done Inline Actionsoh yeah, i remember that now! ardumont: oh yeah, i remember that now! |
This is a private attribute. It won't be accessed by another other class and this one is empty.