diff --git a/swh/loader/dir/tests/test_converters.py b/swh/loader/dir/tests/test_converters.py index 888cbc2..198681a 100644 --- a/swh/loader/dir/tests/test_converters.py +++ b/swh/loader/dir/tests/test_converters.py @@ -1,167 +1,161 @@ # Copyright (C) 2015-2017 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 shutil import tempfile import unittest -from nose.tools import istest - -from swh.model import hashutil from swh.loader.dir import converters +from swh.model import hashutil def tmpfile_with_content(fromdir, contentfile): """Create a temporary file with content contentfile in directory fromdir. """ tmpfilepath = tempfile.mktemp( suffix='.swh', prefix='tmp-file-for-test', dir=fromdir) with open(tmpfilepath, 'wb') as f: f.write(contentfile) return tmpfilepath class TestConverters(unittest.TestCase): @classmethod def setUpClass(cls): super().setUpClass() cls.tmpdir = tempfile.mkdtemp(prefix='test-swh-loader-dir.') @classmethod def tearDownClass(cls): shutil.rmtree(cls.tmpdir) super().tearDownClass() - @istest - def format_to_minutes(self): + def test_format_to_minutes(self): self.assertEquals(converters.format_to_minutes('+0100'), 60) self.assertEquals(converters.format_to_minutes('-0200'), -120) self.assertEquals(converters.format_to_minutes('+1250'), 12*60+50) self.assertEquals(converters.format_to_minutes('+0000'), 0) self.assertEquals(converters.format_to_minutes('-0000'), 0) - @istest - def annotated_tag_to_release(self): + def test_annotated_tag_to_release(self): # given release = { 'name': 'v0.0.1', 'message': 'synthetic-message-input', 'author': {'name': 'author-name', 'email': 'author-email', 'fullname': 'fullname'}, } expected_release = { 'name': b'v0.0.1', 'message': b'synthetic-message-input', 'author': {'name': b'author-name', 'email': b'author-email', 'fullname': b'fullname'}, 'synthetic': True, } # when actual_release = converters.annotated_tag_to_release(release) # then self.assertDictEqual(actual_release, expected_release) - @istest - def commit_to_revision(self): + def test_commit_to_revision(self): # given commit = { 'sha1_git': 'commit-git-sha1', 'directory': 'targeted-tree-sha1', 'date': {'timestamp': 1444054085, 'offset': '+0000'}, 'committer_date': {'timestamp': 1444054085, 'offset': '+0000'}, 'type': 'tar', 'message': 'synthetic-message-input', 'author': {'name': 'author-name', 'email': 'author-email', 'fullname': 'fullname'}, 'committer': {'name': 'author-name', 'email': 'author-email', 'fullname': 'fullname'}, 'directory': 'targeted-tree-sha1', } expected_revision = { 'sha1_git': 'commit-git-sha1', 'directory': 'targeted-tree-sha1', 'date': {'timestamp': 1444054085, 'offset': '+0000'}, 'committer_date': {'timestamp': 1444054085, 'offset': '+0000'}, 'type': 'tar', 'message': b'synthetic-message-input', 'author': {'name': b'author-name', 'email': b'author-email', 'fullname': b'fullname'}, 'committer': {'name': b'author-name', 'email': b'author-email', 'fullname': b'fullname'}, 'directory': 'targeted-tree-sha1', 'synthetic': True, 'parents': [] } # when actual_revision = converters.commit_to_revision(commit) # then self.assertEquals(actual_revision, expected_revision) - @istest - def commit_to_revision_with_parents(self): + def test_commit_to_revision_with_parents(self): """Commit with existing parents should not lose information """ h = '10041ddb6cbc154c24227b1e8759b81dcd99ea3e' # given commit = { 'sha1_git': 'commit-git-sha1', 'directory': 'targeted-tree-sha1', 'date': {'timestamp': 1444054085, 'offset': '+0000'}, 'committer_date': {'timestamp': 1444054085, 'offset': '+0000'}, 'type': 'tar', 'message': 'synthetic-message-input', 'author': {'name': 'author-name', 'email': 'author-email', 'fullname': 'fullname'}, 'committer': {'name': 'author-name', 'email': 'author-email', 'fullname': 'fullname'}, 'directory': 'targeted-tree-sha1', 'parents': [h], } expected_revision = { 'sha1_git': 'commit-git-sha1', 'directory': 'targeted-tree-sha1', 'date': {'timestamp': 1444054085, 'offset': '+0000'}, 'committer_date': {'timestamp': 1444054085, 'offset': '+0000'}, 'type': 'tar', 'message': b'synthetic-message-input', 'author': {'name': b'author-name', 'email': b'author-email', 'fullname': b'fullname'}, 'committer': {'name': b'author-name', 'email': b'author-email', 'fullname': b'fullname'}, 'directory': 'targeted-tree-sha1', 'synthetic': True, 'parents': [hashutil.hash_to_bytes(h)] } # when actual_revision = converters.commit_to_revision(commit) # then self.assertEquals(actual_revision, expected_revision) diff --git a/swh/loader/dir/tests/test_loader.py b/swh/loader/dir/tests/test_loader.py index 03e919c..fc95a74 100644 --- a/swh/loader/dir/tests/test_loader.py +++ b/swh/loader/dir/tests/test_loader.py @@ -1,235 +1,232 @@ # Copyright (C) 2015-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 -from nose.tools import istest from nose.plugins.attrib import attr +from swh.loader.core.tests import BaseLoaderTest, LoaderNoStorage from swh.loader.dir.loader import DirLoader -from swh.loader.core.tests import LoaderNoStorage, BaseLoaderTest @attr('fs') class BaseDirLoaderTest(BaseLoaderTest): def setUp(self, archive_name='sample-folder.tgz'): super().setUp(archive_name=archive_name, prefix_tmp_folder_name='swh.loader.dir.', start_path=os.path.dirname(__file__)) class DirLoaderNoStorage(LoaderNoStorage, DirLoader): """A DirLoader with no persistence. Context: Load a tarball with a persistent-less tarball loader """ def __init__(self, config={}): super().__init__(config=config) self.origin_id = 1 self.visit = 1 class DirLoaderListRepoObject(BaseDirLoaderTest): def setUp(self): super().setUp() self.info = { 'storage': { 'cls': 'remote', 'args': { 'url': 'http://localhost:5002/', } }, 'content_size_limit': 104857600, 'log_db': 'dbname=softwareheritage-log', 'directory_packet_size': 25000, 'content_packet_size': 10000, 'send_contents': True, 'send_directories': True, 'content_packet_size_bytes': 1073741824, 'send_revisions': True, 'revision_packet_size': 100000, 'content_packet_block_size_bytes': 104857600, 'send_snaphot': True, 'release_packet_size': 100000, 'send_releases': True } self.origin = { 'url': 'file:///dev/null', 'type': 'dir', } self.revision = { 'author': { 'name': 'swh author', 'email': 'swh@inria.fr', 'fullname': 'swh' }, 'date': { 'timestamp': 1444054085, 'offset': 0 }, 'committer': { 'name': 'swh committer', 'email': 'swh@inria.fr', 'fullname': 'swh' }, 'committer_date': { 'timestamp': 1444054085, 'offset': 0, }, 'type': 'tar', 'message': 'synthetic revision', 'metadata': {'foo': 'bar'}, } self.release = { 'name': 'v0.0.1', 'date': { 'timestamp': 1444054085, 'offset': 0, }, 'author': { 'name': 'swh author', 'fullname': 'swh', 'email': 'swh@inria.fr', }, 'message': 'synthetic release', } self.dirloader = DirLoaderNoStorage(config=self.info) - @istest - def load_without_storage(self): + def test_load_without_storage(self): """List directory objects without loading should be ok""" # when dir_path = self.destination_path if isinstance(dir_path, str): dir_path = dir_path.encode('utf-8') objects = self.dirloader.list_objs( dir_path=dir_path, revision=self.revision, release=self.release, branch_name=b'master') # then self.assertEquals(len(objects), 5, "5 obj types: con, dir, rev, rel, snap") self.assertEquals(len(objects['content']), 8, "8 contents: 3 files + 5 links") self.assertEquals(len(objects['directory']), 6, "6 directories: 5 subdirs + 1 empty") self.assertEquals(len(objects['revision']), 1, "synthetic revision") self.assertEquals(len(objects['release']), 1, "synthetic release") self.assertEquals(len(objects['snapshot']), 1, "snapshot") TEST_CONFIG = { 'extraction_dir': '/tmp/tests/loader-tar/', # where to extract the tarball 'storage': { # we instantiate it but we don't use it in test context 'cls': 'remote', 'args': { 'url': 'http://127.0.0.1:9999', # somewhere that does not exist } }, 'send_contents': False, 'send_directories': False, 'send_revisions': False, 'send_releases': False, 'send_snapshot': False, 'content_packet_size': 100, 'content_packet_block_size_bytes': 104857600, 'content_packet_size_bytes': 1073741824, 'directory_packet_size': 250, 'revision_packet_size': 100, 'release_packet_size': 100, } def parse_config_file(base_filename=None, config_filename=None, additional_configs=None, global_config=True): return TEST_CONFIG # Inhibit side-effect loading configuration from disk DirLoader.parse_config_file = parse_config_file class SWHDirLoaderITTest(BaseDirLoaderTest): def setUp(self): super().setUp() self.loader = DirLoaderNoStorage() - @istest - def load(self): + def test_load(self): """Process a new tarball should be ok """ # given origin = { 'url': 'file:///tmp/sample-folder', 'type': 'dir' } visit_date = 'Tue, 3 May 2016 17:16:32 +0200' import datetime commit_time = int(datetime.datetime.now( tz=datetime.timezone.utc).timestamp() ) swh_person = { 'name': 'Software Heritage', 'fullname': 'Software Heritage', 'email': 'robot@softwareheritage.org' } revision_message = 'swh-loader-dir: synthetic revision message' revision_type = 'tar' revision = { 'date': { 'timestamp': commit_time, 'offset': 0, }, 'committer_date': { 'timestamp': commit_time, 'offset': 0, }, 'author': swh_person, 'committer': swh_person, 'type': revision_type, 'message': revision_message, 'metadata': {}, 'synthetic': True, } branch = os.path.basename(self.destination_path) # when self.loader.load( dir_path=self.destination_path, origin=origin, visit_date=visit_date, revision=revision, release=None, branch_name=branch) # then self.assertCountContents(8) self.assertCountDirectories(6) self.assertCountRevisions(1) actual_revision = self.state('revision')[0] self.assertEquals(actual_revision['synthetic'], True) self.assertEquals(actual_revision['parents'], []) self.assertEquals(actual_revision['type'], 'tar') self.assertEquals(actual_revision['message'], b'swh-loader-dir: synthetic revision message') self.assertCountReleases(0) self.assertCountSnapshots(1)