diff --git a/debian/control b/debian/control --- a/debian/control +++ b/debian/control @@ -12,7 +12,7 @@ python3-setuptools, python3-subvertpy (>= 0.9.4~), python3-swh.core (>= 0.0.19~), - python3-swh.loader.core (>= 0.0.33~), + python3-swh.loader.core (>= 0.0.34~), python3-swh.model (>= 0.0.18~), python3-swh.scheduler (>= 0.0.14~), python3-swh.storage (>= 0.0.83~), @@ -25,7 +25,7 @@ Architecture: all Depends: gzip, python3-swh.core (>= 0.0.19~), - python3-swh.loader.core (>= 0.0.33~), + python3-swh.loader.core (>= 0.0.34~), python3-swh.model (>= 0.0.18~), python3-swh.scheduler (>= 0.0.14~), python3-swh.storage (>= 0.0.83~), diff --git a/requirements-swh.txt b/requirements-swh.txt --- a/requirements-swh.txt +++ b/requirements-swh.txt @@ -2,4 +2,4 @@ swh.storage >= 0.0.83 swh.model >= 0.0.18 swh.scheduler >= 0.0.14 -swh.loader.core >= 0.0.33 +swh.loader.core >= 0.0.34 diff --git a/swh/loader/svn/tests/test_base.py b/swh/loader/svn/tests/test_base.py deleted file mode 100644 --- a/swh/loader/svn/tests/test_base.py +++ /dev/null @@ -1,85 +0,0 @@ -# Copyright (C) 2016-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 - -import os -import shutil -import subprocess -import tempfile -import unittest - -from swh.model import hashutil - - -class BaseSvnLoaderTest(unittest.TestCase): - """Base test loader class. - - In its setup, it's uncompressing a local svn mirror to /tmp. - - """ - def setUp(self, archive_name='pkg-gourmet.tgz', filename='pkg-gourmet'): - self.tmp_root_path = tempfile.mkdtemp( - prefix='swh.loader.svn', suffix='-tests') - - start_path = os.path.dirname(__file__) - svn_mirror_repo = os.path.join(start_path, 'resources', archive_name) - - # uncompress the sample folder - subprocess.check_output( - ['tar', 'xvf', svn_mirror_repo, '-C', self.tmp_root_path], - ) - - self.svn_mirror_url = 'file://' + self.tmp_root_path + '/' + filename - self.destination_path = os.path.join( - self.tmp_root_path, 'working-copy') - - def tearDown(self): - shutil.rmtree(self.tmp_root_path) - - def assertSnapshotOk(self, expected_snapshot, expected_branches): - snapshots = self.loader.all_snapshots - self.assertEqual(len(snapshots), 1) - - snap = snapshots[0] - snap_id = hashutil.hash_to_hex(snap['id']) - self.assertEqual(snap_id, expected_snapshot) - - def decode_target(target): - if not target: - return target - target_type = target['target_type'] - - if target_type == 'alias': - decoded_target = target['target'].decode('utf-8') - else: - decoded_target = hashutil.hash_to_hex(target['target']) - - return { - 'target': decoded_target, - 'target_type': target_type - } - - branches = { - branch.decode('utf-8'): decode_target(target) - for branch, target in snap['branches'].items() - } - self.assertEqual(expected_branches, branches) - - def assertRevisionsOk(self, expected_revisions): # noqa: N802 - """Check the loader's revisions match the expected revisions. - - Expects self.loader to be instantiated and ready to be - inspected (meaning the loading took place). - - Args: - expected_revisions (dict): Dict with key revision id, - value the targeted directory id. - - """ - # The last revision being the one used later to start back from - for rev in self.loader.all_revisions: - rev_id = hashutil.hash_to_hex(rev['id']) - directory_id = hashutil.hash_to_hex(rev['directory']) - - self.assertEquals(expected_revisions[rev_id], directory_id) diff --git a/swh/loader/svn/tests/test_loader.py b/swh/loader/svn/tests/test_loader.py --- a/swh/loader/svn/tests/test_loader.py +++ b/swh/loader/svn/tests/test_loader.py @@ -3,6 +3,8 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information +import os + from nose.tools import istest from unittest import TestCase @@ -10,8 +12,20 @@ from swh.loader.svn.loader import build_swh_snapshot, DEFAULT_BRANCH from swh.loader.svn.loader import SvnLoader, SvnLoaderFromRemoteDump +from swh.loader.core.tests import LoaderNoStorage, BaseLoaderTest + + +class BaseSvnLoaderTest(BaseLoaderTest): + """Base test loader class. + + In its setup, it's uncompressing a local svn mirror to /tmp. -from .test_base import BaseSvnLoaderTest + """ + def setUp(self, archive_name='pkg-gourmet.tgz', filename='pkg-gourmet'): + super().setUp(archive_name=archive_name, filename=filename, + prefix_tmp_folder_name='swh.loader.svn.', + start_path=os.path.dirname(__file__)) + self.svn_mirror_url = self.repo_url class TestSnapshot(TestCase): @@ -30,90 +44,6 @@ }) -# Define loaders with no storage -# They'll just accumulate the data in place -# Only for testing purposes. - - -class LoaderNoStorage: - """Mixin class to inhibit the persistence and keep in memory the data - sent for storage. - - cf. SvnLoaderNoStorage - - """ - def __init__(self): - super().__init__() - self.all_contents = [] - self.all_directories = [] - self.all_revisions = [] - self.all_releases = [] - self.all_snapshots = [] - - # typed data - self.objects = { - 'content': self.all_contents, - 'directory': self.all_directories, - 'revision': self.all_revisions, - 'release': self.all_releases, - 'snapshot': self.all_snapshots, - } - - def _add(self, type, l): - """Add without duplicates and keeping the insertion order. - - Args: - type (str): Type of objects concerned by the action - l ([object]): List of 'type' object - - """ - col = self.objects[type] - for o in l: - if o in col: - continue - col.extend([o]) - - def maybe_load_contents(self, all_contents): - self._add('content', all_contents) - - def maybe_load_directories(self, all_directories): - self._add('directory', all_directories) - - def maybe_load_revisions(self, all_revisions): - self._add('revision', all_revisions) - - def maybe_load_releases(self, releases): - raise ValueError('If called, the test must break.') - - def maybe_load_snapshot(self, snapshot): - self._add('snapshot', [snapshot]) - - def _store_origin_visit(self): - pass - - def open_fetch_history(self): - pass - - def close_fetch_history_success(self, fetch_history_id): - pass - - def close_fetch_history_failure(self, fetch_history_id): - pass - - def update_origin_visit(self, origin_id, visit, status): - pass - - # Override to do nothing at the end - def close_failure(self): - pass - - def close_success(self): - pass - - def pre_cleanup(self): - pass - - class LoaderWithState: """Additional state setup (bypassed by some override for test purposes)