Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/mercurial/tests/test_loader.py
# Copyright (C) 2018 The Software Heritage developers | # Copyright (C) 2018 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 os | import os | ||||
from swh.loader.core.tests import BaseLoaderTest | from unittest.mock import patch | ||||
from swh.loader.mercurial.loader import HgBundle20Loader | |||||
_LOADER_TEST_CONFIG = { | |||||
'bundle_filename': 'HG20_none_bundle', | |||||
'cache1_size': 838860800, | |||||
'cache2_size': 838860800, | |||||
'content_packet_size': 100000, | |||||
'content_packet_size_bytes': 1073741824, | |||||
'content_size_limit': 104857600, | |||||
'directory_packet_size': 25000, | |||||
'log_db': 'dbname=softwareheritage-log', | |||||
'occurrence_packet_size': 100000, | |||||
'reduce_effort': False, | |||||
'release_packet_size': 100000, | |||||
'revision_packet_size': 100000, | |||||
'save_data': False, | |||||
'save_data_path': '', | |||||
'send_contents': True, | |||||
'send_directories': True, | |||||
'send_occurrences': True, | |||||
'send_releases': True, | |||||
'send_revisions': True, | |||||
'send_snapshot': True, | |||||
'storage': {'args': {}, 'cls': 'memory'}, | |||||
'temp_directory': '/tmp/swh.loader.mercurial' | |||||
} | |||||
class HgLoaderMemoryStorage(HgBundle20Loader): | from swh.loader.core.tests import BaseLoaderTest | ||||
"""The mercurial loader to test. | from .common import HgLoaderMemoryStorage, HgArchiveLoaderMemoryStorage | ||||
Its behavior has been changed to: | |||||
- not use any persistence (no storage, or for now a passthrough | |||||
storage with no filtering) | |||||
- not use the default configuration loading | |||||
At the end of the tests, you can make sure you have the rights | |||||
objects. | |||||
""" | |||||
def __init__(self): | |||||
super().__init__() | |||||
self.origin_id = 1 | |||||
self.visit = 1 | |||||
def parse_config_file(self, *args, **kwargs): | |||||
return _LOADER_TEST_CONFIG | |||||
class BaseHgLoaderTest(BaseLoaderTest): | class BaseHgLoaderTest(BaseLoaderTest): | ||||
"""Mixin base loader test to prepare the mercurial | """Mixin base loader test to prepare the mercurial | ||||
repository to uncompress, load and test the results. | repository to uncompress, load and test the results. | ||||
This sets up | This sets up | ||||
""" | """ | ||||
def setUp(self, archive_name='the-sandbox.tgz', filename='the-sandbox'): | def setUp(self, loader=HgLoaderMemoryStorage, | ||||
archive_name='the-sandbox.tgz', filename='the-sandbox', | |||||
uncompress_archive=True): | |||||
super().setUp(archive_name=archive_name, filename=filename, | super().setUp(archive_name=archive_name, filename=filename, | ||||
prefix_tmp_folder_name='swh.loader.mercurial.', | prefix_tmp_folder_name='swh.loader.mercurial.', | ||||
start_path=os.path.dirname(__file__)) | start_path=os.path.dirname(__file__), | ||||
self.loader = HgLoaderMemoryStorage() | uncompress_archive=uncompress_archive) | ||||
self.loader = loader() | |||||
self.storage = self.loader.storage | self.storage = self.loader.storage | ||||
class LoaderITest1(BaseHgLoaderTest): | class LoaderITest1(BaseHgLoaderTest): | ||||
"""Load a mercurial repository without release | """Load a mercurial repository without release | ||||
""" | """ | ||||
def test_load(self): | def test_load(self): | ||||
"""Load a repository with multiple branches results in 1 snapshot | """Load a repository with multiple branches results in 1 snapshot | ||||
""" | """ | ||||
# when | # when | ||||
self.loader.load( | self.loader.load( | ||||
origin_url=self.repo_url, | origin_url=self.repo_url, | ||||
visit_date='2016-05-03 15:16:32+00', | visit_date='2016-05-03 15:16:32+00', | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | def test_load(self): | ||||
} | } | ||||
} | } | ||||
self.assertSnapshotEqual(expected_snapshot) | self.assertSnapshotEqual(expected_snapshot) | ||||
self.assertEqual(self.loader.load_status(), {'status': 'eventful'}) | self.assertEqual(self.loader.load_status(), {'status': 'eventful'}) | ||||
self.assertEqual(self.loader.visit_status(), 'full') | self.assertEqual(self.loader.visit_status(), 'full') | ||||
class LoaderITest2(BaseHgLoaderTest): | class CommonHgLoaderData: | ||||
"""Load a mercurial repository with release | def assert_data_ok(self): | ||||
""" | |||||
def setUp(self): | |||||
super().setUp(archive_name='hello.tgz', filename='hello') | |||||
def test_load(self): | |||||
"""Load a repository with tags results in 1 snapshot | |||||
""" | |||||
# when | |||||
self.loader.load( | |||||
origin_url=self.repo_url, | |||||
visit_date='2016-05-03 15:16:32+00', | |||||
directory=self.destination_path) | |||||
# then | # then | ||||
self.assertCountContents(3) | self.assertCountContents(3) | ||||
self.assertCountDirectories(3) | self.assertCountDirectories(3) | ||||
self.assertCountReleases(1) | self.assertCountReleases(1) | ||||
self.assertCountRevisions(3) | self.assertCountRevisions(3) | ||||
tip_release = '515c4d72e089404356d0f4b39d60f948b8999140' | tip_release = '515c4d72e089404356d0f4b39d60f948b8999140' | ||||
self.assertReleasesContain([tip_release]) | self.assertReleasesContain([tip_release]) | ||||
Show All 27 Lines | def assert_data_ok(self): | ||||
'target_type': 'alias', | 'target_type': 'alias', | ||||
} | } | ||||
} | } | ||||
} | } | ||||
self.assertSnapshotEqual(expected_snapshot) | self.assertSnapshotEqual(expected_snapshot) | ||||
self.assertEqual(self.loader.load_status(), {'status': 'eventful'}) | self.assertEqual(self.loader.load_status(), {'status': 'eventful'}) | ||||
self.assertEqual(self.loader.visit_status(), 'full') | self.assertEqual(self.loader.visit_status(), 'full') | ||||
class LoaderITest2(BaseHgLoaderTest, CommonHgLoaderData): | |||||
anlambert: Small nitpick, I would rename 'LoaderITest2' into 'LoaderTest2' here and do the same for all… | |||||
ardumontAuthorUnsubmitted Done Inline ActionsRight. The I stands for integration. ardumont: Right.
The I stands for integration. | |||||
"""Load a mercurial repository with release | |||||
""" | |||||
def setUp(self): | |||||
super().setUp(archive_name='hello.tgz', filename='hello') | |||||
def test_load(self): | |||||
"""Load a repository with tags results in 1 snapshot | |||||
""" | |||||
# when | |||||
self.loader.load( | |||||
origin_url=self.repo_url, | |||||
visit_date='2016-05-03 15:16:32+00', | |||||
directory=self.destination_path) | |||||
self.assert_data_ok() | |||||
class ArchiveLoaderITest(BaseHgLoaderTest, CommonHgLoaderData): | |||||
"""Load a mercurial repository archive with release | |||||
""" | |||||
def setUp(self): | |||||
super().setUp(loader=HgArchiveLoaderMemoryStorage, | |||||
archive_name='hello.tgz', filename='hello', | |||||
uncompress_archive=False) | |||||
def test_load(self): | |||||
"""Load a mercurial repository archive with tags results in 1 snapshot | |||||
""" | |||||
# when | |||||
self.loader.load( | |||||
origin_url=self.repo_url, | |||||
visit_date='2016-05-03 15:16:32+00', | |||||
archive_path=self.destination_path) | |||||
self.assert_data_ok() | |||||
@patch('swh.loader.mercurial.archive_extract.patoolib') | |||||
def test_load_with_failure(self, mock_patoo): | |||||
mock_patoo.side_effect = ValueError | |||||
# when | |||||
r = self.loader.load( | |||||
origin_url=self.repo_url, | |||||
visit_date='2016-05-03 15:16:32+00', | |||||
archive_path=self.destination_path) | |||||
self.assertEqual(r, {'status': 'failed'}) | |||||
self.assertCountContents(0) | |||||
self.assertCountDirectories(0) | |||||
self.assertCountRevisions(0) | |||||
self.assertCountReleases(0) | |||||
self.assertCountSnapshots(0) |
Small nitpick, I would rename 'LoaderITest2' into 'LoaderTest2' here and do the same for all test class names.
I don't see the point of that extra 'I' character.