summaryrefslogtreecommitdiff
path: root/tests/test_profile.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_profile.py')
-rw-r--r--tests/test_profile.py510
1 files changed, 276 insertions, 234 deletions
diff --git a/tests/test_profile.py b/tests/test_profile.py
index 2b26114..0c17049 100644
--- a/tests/test_profile.py
+++ b/tests/test_profile.py
@@ -1,61 +1,60 @@
# gemato: Profile behavior tests
# vim:fileencoding=utf-8
-# (c) 2017 Michał Górny
+# (c) 2017-2020 Michał Górny
# Licensed under the terms of 2-clause BSD license
+import itertools
+import os
import os.path
+import pytest
+
import gemato.cli
-import gemato.profile
-import gemato.recursiveloader
-
-from tests.testutil import TempDirTestCase
-
-
-class EbuildRepositoryTests(TempDirTestCase):
- """
- Tests for ebuild repository profiles.
- """
-
- PROFILE = gemato.profile.EbuildRepositoryProfile
- PROFILE_NAME = 'ebuild'
- DIRS = [
- 'dev-foo',
- 'dev-foo/bar',
- 'dev-foo/bar/files',
- 'eclass',
- 'eclass/tests',
- 'licenses',
- 'metadata',
- 'metadata/dtd',
- 'metadata/glsa',
- 'metadata/install-qa-check.d',
- 'metadata/md5-cache',
- 'metadata/md5-cache/dev-foo',
- 'metadata/news',
- 'metadata/news/2020-01-01-foo',
- 'metadata/xml-schema',
- 'profiles',
- 'profiles/arch',
- 'profiles/arch/foo',
- 'profiles/desc',
- 'profiles/updates',
- ]
- EXPECTED_MANIFESTS = [
- 'dev-foo/Manifest',
- 'dev-foo/bar/Manifest',
- 'eclass/Manifest',
- 'licenses/Manifest',
- 'metadata/Manifest',
- 'metadata/dtd/Manifest',
- 'metadata/glsa/Manifest',
- 'metadata/md5-cache/Manifest',
- 'metadata/md5-cache/dev-foo/Manifest',
- 'metadata/news/Manifest',
- 'metadata/xml-schema/Manifest',
- 'profiles/Manifest',
- ]
- EXPECTED_TYPES = {
+from gemato.profile import (
+ EbuildRepositoryProfile,
+ BackwardsCompatEbuildRepositoryProfile,
+ )
+from gemato.recursiveloader import ManifestRecursiveLoader
+
+
+DIRS = [
+ 'dev-foo',
+ 'dev-foo/bar',
+ 'dev-foo/bar/files',
+ 'eclass',
+ 'eclass/tests',
+ 'licenses',
+ 'metadata',
+ 'metadata/dtd',
+ 'metadata/glsa',
+ 'metadata/install-qa-check.d',
+ 'metadata/md5-cache',
+ 'metadata/md5-cache/dev-foo',
+ 'metadata/news',
+ 'metadata/news/2020-01-01-foo',
+ 'metadata/xml-schema',
+ 'profiles',
+ 'profiles/arch',
+ 'profiles/arch/foo',
+ 'profiles/desc',
+ 'profiles/updates',
+]
+PACKAGE_MANIFESTS = ['dev-foo/bar/Manifest']
+EXPECTED_MANIFESTS = PACKAGE_MANIFESTS + [
+ 'dev-foo/Manifest',
+ 'eclass/Manifest',
+ 'licenses/Manifest',
+ 'metadata/Manifest',
+ 'metadata/dtd/Manifest',
+ 'metadata/glsa/Manifest',
+ 'metadata/md5-cache/Manifest',
+ 'metadata/md5-cache/dev-foo/Manifest',
+ 'metadata/news/Manifest',
+ 'metadata/xml-schema/Manifest',
+ 'profiles/Manifest',
+]
+EXPECTED_TYPES = {
+ EbuildRepositoryProfile: {
'header.txt': 'DATA',
'skel.ebuild': 'DATA',
'skel.metadata.xml': 'DATA',
@@ -92,187 +91,230 @@ class EbuildRepositoryTests(TempDirTestCase):
'profiles/arch/foo/parent': 'DATA',
'profiles/desc/foo.desc': 'DATA',
'profiles/updates/1Q-2020': 'DATA',
+ },
+}
+FILES = list(EXPECTED_TYPES[EbuildRepositoryProfile]) + [
+ 'metadata/timestamp',
+ 'metadata/timestamp.chk',
+ 'metadata/timestamp.commit',
+ 'metadata/timestamp.x',
+]
+EXPECTED_IGNORE = [
+ 'distfiles',
+ 'local',
+ 'lost+found',
+ 'packages',
+ 'metadata/timestamp',
+ 'metadata/timestamp.chk',
+ 'metadata/timestamp.commit',
+ 'metadata/timestamp.x',
+ 'metadata/dtd/timestamp.chk',
+ 'metadata/dtd/timestamp.commit',
+ 'metadata/glsa/timestamp.chk',
+ 'metadata/glsa/timestamp.commit',
+ 'metadata/news/timestamp.chk',
+ 'metadata/news/timestamp.commit',
+ 'metadata/xml-schema/timestamp.chk',
+ 'metadata/xml-schema/timestamp.commit',
+]
+
+EXPECTED_TYPES[BackwardsCompatEbuildRepositoryProfile] = (
+ dict(EXPECTED_TYPES[EbuildRepositoryProfile]))
+EXPECTED_TYPES[BackwardsCompatEbuildRepositoryProfile].update({
+ 'dev-foo/bar/bar-1.ebuild': 'EBUILD',
+ 'dev-foo/bar/metadata.xml': 'MISC',
+ 'dev-foo/bar/files/test.patch': 'AUX',
+})
+
+ALL_PROFILES = [
+ EbuildRepositoryProfile,
+ BackwardsCompatEbuildRepositoryProfile,
+]
+
+
+@pytest.fixture
+def test_repo(tmp_path_factory):
+ tmp_path = tmp_path_factory.mktemp('profile-')
+ for d in DIRS:
+ os.mkdir(tmp_path / d)
+ for f in FILES:
+ with open(tmp_path / f, 'w'):
+ pass
+ yield tmp_path
+
+
+@pytest.mark.parametrize(
+ 'profile,path,expected',
+ [(profile, path, EXPECTED_TYPES[profile][path])
+ for profile in ALL_PROFILES
+ for path in EXPECTED_TYPES[profile]])
+def test_get_entry_type_for_path(profile, path, expected):
+ assert profile().get_entry_type_for_path(path) == expected
+
+
+def make_entry_match(manifest_loader, path):
+ entry = manifest_loader.find_path_entry(path)
+ if entry is not None:
+ if entry.tag == 'MANIFEST':
+ return (entry.tag,
+ os.path.exists(
+ os.path.join(manifest_loader.root_directory,
+ path)))
+ elif entry.tag == 'AUX':
+ return (entry.tag, entry.path, entry.aux_path)
+ return (entry.tag,)
+
+
+def make_expect_match(path, entry_type, manifests_exist=True):
+ if entry_type == 'MANIFEST':
+ return (entry_type, manifests_exist)
+ elif entry_type == 'AUX':
+ return (entry_type,
+ os.path.join('files', os.path.basename(path)),
+ os.path.basename(path))
+ return (entry_type,)
+
+
+@pytest.mark.parametrize('profile', ALL_PROFILES)
+def test_update_entries_for_directory(test_repo, profile):
+ m = ManifestRecursiveLoader(
+ test_repo / 'Manifest',
+ hashes=['SHA256', 'SHA512'],
+ allow_create=True,
+ profile=profile())
+ m.update_entries_for_directory('')
+
+ expected = dict(
+ [(path, make_expect_match(path, entry_type))
+ for path, entry_type in EXPECTED_TYPES[profile].items()] +
+ [(path, make_expect_match(path, 'MANIFEST', manifests_exist=False))
+ for path in EXPECTED_MANIFESTS] +
+ [(path, make_expect_match(path, 'IGNORE'))
+ for path in EXPECTED_IGNORE])
+ found = dict((path, make_entry_match(m, path))
+ for path in expected)
+ assert found == expected
+
+ m.save_manifests()
+ manifests_expected = dict(
+ (path, make_expect_match(path, 'MANIFEST'))
+ for path in EXPECTED_MANIFESTS)
+ manifests_found = dict((path, make_entry_match(m, path))
+ for path in manifests_expected)
+ assert manifests_found == manifests_expected
+
+ m.assert_directory_verifies('')
+
+
+@pytest.mark.parametrize('profile', ALL_PROFILES)
+def test_cli_update(test_repo, profile):
+ assert gemato.cli.main(['gemato', 'create',
+ '--profile', profile.name,
+ str(test_repo)]) == 0
+
+ m = ManifestRecursiveLoader(test_repo / 'Manifest')
+ expected = dict(
+ [(path, make_expect_match(path, entry_type))
+ for path, entry_type in EXPECTED_TYPES[profile].items()] +
+ [(path, make_expect_match(path, 'MANIFEST'))
+ for path in EXPECTED_MANIFESTS] +
+ [(path, make_expect_match(path, 'IGNORE'))
+ for path in EXPECTED_IGNORE])
+ found = dict((path, make_entry_match(m, path))
+ for path in expected)
+ assert found == expected
+
+ assert gemato.cli.main(['gemato', 'verify', str(test_repo)]) == 0
+
+
+@pytest.mark.parametrize('profile', ALL_PROFILES)
+def test_set_loader_options(test_repo, profile):
+ m = ManifestRecursiveLoader(
+ test_repo / 'Manifest',
+ profile=profile(),
+ allow_create=True)
+ assert m.hashes is not None
+ assert m.sort
+ assert m.compress_watermark is not None
+ assert m.compress_format is not None
+
+
+@pytest.mark.parametrize('profile', ALL_PROFILES)
+def test_regression_top_level_ignore_in_all_manifests(test_repo, profile):
+ """Regression test for IGNORE wrongly applying to all Manifests"""
+ m = ManifestRecursiveLoader(
+ test_repo / 'Manifest',
+ hashes=['SHA256', 'SHA512'],
+ allow_create=True,
+ profile=profile())
+ m.update_entries_for_directory('')
+
+ expected = {
+ 'distfiles': ('IGNORE',),
+ 'dev-foo/Manifest': ('MANIFEST', False),
+ 'dev-foo/distfiles': None,
}
- FILES = dict.fromkeys(list(EXPECTED_TYPES) + [
- 'metadata/timestamp',
- 'metadata/timestamp.chk',
- 'metadata/timestamp.commit',
- 'metadata/timestamp.x',
- ], u'')
-
- EXPECTED_IGNORE = [
- 'distfiles',
- 'local',
- 'lost+found',
- 'packages',
- 'metadata/timestamp',
- 'metadata/timestamp.chk',
- 'metadata/timestamp.commit',
- 'metadata/timestamp.x',
- 'metadata/dtd/timestamp.chk',
- 'metadata/dtd/timestamp.commit',
- 'metadata/glsa/timestamp.chk',
- 'metadata/glsa/timestamp.commit',
- 'metadata/news/timestamp.chk',
- 'metadata/news/timestamp.commit',
- 'metadata/xml-schema/timestamp.chk',
- 'metadata/xml-schema/timestamp.commit',
- ]
-
- def test_get_entry_type_for_path(self):
- p = self.PROFILE()
- for f, expt in self.EXPECTED_TYPES.items():
- self.assertEqual(
- p.get_entry_type_for_path(f),
- expt,
- "type mismatch for {}".format(f))
-
- def test_update_entries_for_directory(self):
- m = gemato.recursiveloader.ManifestRecursiveLoader(
- os.path.join(self.dir, 'Manifest'),
- hashes=['SHA256', 'SHA512'],
- allow_create=True,
- profile=self.PROFILE())
- m.update_entries_for_directory('')
- for f, expt in self.EXPECTED_TYPES.items():
- self.assertEqual(
- m.find_path_entry(f).tag,
- expt,
- "type mismatch for {}".format(f))
- for f in self.EXPECTED_MANIFESTS:
- self.assertEqual(m.find_path_entry(f).tag, 'MANIFEST',
- "type mismatch for {}".format(f))
- for f in self.EXPECTED_IGNORE:
- self.assertIsNotNone(m.find_path_entry(f),
- "missing IGNORE entry for {}".format(f))
- self.assertEqual(m.find_path_entry(f).tag, 'IGNORE',
- "type mismatch for {}".format(f))
- m.save_manifests()
- m.assert_directory_verifies('')
- return m
-
- def test_regression_top_level_ignore_in_all_manifests(self):
- assert 'distfiles' in self.EXPECTED_IGNORE[0]
- assert 'dev-foo/Manifest' in self.EXPECTED_MANIFESTS
-
- m = gemato.recursiveloader.ManifestRecursiveLoader(
- os.path.join(self.dir, 'Manifest'),
- hashes=['SHA256', 'SHA512'],
- allow_create=True,
- profile=self.PROFILE())
- m.update_entries_for_directory('')
-
- self.assertIsNone(m.find_path_entry('dev-foo/distfiles'))
-
- def test_set_loader_options(self):
- m = gemato.recursiveloader.ManifestRecursiveLoader(
- os.path.join(self.dir, 'Manifest'),
- profile=self.PROFILE(),
- allow_create=True)
- self.assertIsNotNone(m.hashes)
- self.assertTrue(m.sort)
- self.assertIsNotNone(m.compress_watermark)
- self.assertIsNotNone(m.compress_format)
-
- def test_cli_update(self):
- self.assertEqual(
- gemato.cli.main(['gemato', 'create',
- '--profile', self.PROFILE_NAME,
- self.dir]),
- 0)
-
- m = gemato.recursiveloader.ManifestRecursiveLoader(
- os.path.join(self.dir, 'Manifest'))
- for f, expt in self.EXPECTED_TYPES.items():
- self.assertEqual(
- m.find_path_entry(f).tag,
- expt,
- "type mismatch for {}".format(f))
- for f in self.EXPECTED_MANIFESTS:
- self.assertEqual(m.find_path_entry(f).tag, 'MANIFEST',
- "type mismatch for {}".format(f))
-
- self.assertEqual(
- gemato.cli.main(['gemato', 'verify', self.dir]),
- 0)
-
- return m
-
-
-class BackwardsCompatEbuildRepositoryTests(EbuildRepositoryTests):
- PROFILE = gemato.profile.BackwardsCompatEbuildRepositoryProfile
- PROFILE_NAME = 'old-ebuild'
-
- def __init__(self, *args, **kwargs):
- self.EXPECTED_TYPES = self.EXPECTED_TYPES.copy()
- self.EXPECTED_TYPES.update({
- 'dev-foo/bar/bar-1.ebuild': 'EBUILD',
- 'dev-foo/bar/metadata.xml': 'MISC',
- 'dev-foo/bar/files/test.patch': 'AUX',
- })
- super(BackwardsCompatEbuildRepositoryTests, self).__init__(
- *args, **kwargs)
-
- def test_update_entries_for_directory(self):
- m = (super(BackwardsCompatEbuildRepositoryTests, self)
- .test_update_entries_for_directory())
- self.assertEqual(
- m.find_path_entry('dev-foo/bar/files/test.patch').path,
- 'files/test.patch')
- self.assertEqual(
- m.find_path_entry('dev-foo/bar/files/test.patch').aux_path,
- 'test.patch')
-
- def test_cli_update(self):
- m = (super(BackwardsCompatEbuildRepositoryTests, self)
- .test_cli_update())
- self.assertEqual(
- m.find_path_entry('dev-foo/bar/files/test.patch').path,
- 'files/test.patch')
- self.assertEqual(
- m.find_path_entry('dev-foo/bar/files/test.patch').aux_path,
- 'test.patch')
-
- def test_compression(self):
- """
- Test that package directory Manifests are not compressed.
- """
-
- m = gemato.recursiveloader.ManifestRecursiveLoader(
- os.path.join(self.dir, 'Manifest'),
- hashes=['SHA256', 'SHA512'],
- compress_watermark=0,
- allow_create=True,
- profile=self.PROFILE())
- m.update_entries_for_directory('')
- m.save_manifests()
-
- for mpath in self.EXPECTED_MANIFESTS:
- # package manifest should be left uncompressed
- if mpath == 'dev-foo/bar/Manifest':
- self.assertTrue(os.path.exists(os.path.join(
- self.dir, mpath)))
- else:
- self.assertTrue(os.path.exists(os.path.join(
- self.dir, mpath + '.gz')))
- self.assertFalse(os.path.exists(os.path.join(
- self.dir, mpath)))
-
- def test_cli_compression(self):
- self.assertEqual(
- gemato.cli.main(['gemato', 'create',
- '--profile', self.PROFILE_NAME,
- '--compress-watermark=0',
- self.dir]),
- 0)
-
- for mpath in self.EXPECTED_MANIFESTS:
- # package manifest should be left uncompressed
- if mpath == 'dev-foo/bar/Manifest':
- self.assertTrue(os.path.exists(os.path.join(
- self.dir, mpath)))
- else:
- self.assertTrue(os.path.exists(os.path.join(
- self.dir, mpath + '.gz')))
- self.assertFalse(os.path.exists(os.path.join(
- self.dir, mpath)))
+ found = dict((path, make_entry_match(m, path))
+ for path in expected)
+ assert found == expected
+
+
+def test_no_compress_compat(test_repo):
+ """Verify that package directory Manifests are not compressed"""
+ profile = BackwardsCompatEbuildRepositoryProfile
+
+ m = ManifestRecursiveLoader(
+ test_repo / 'Manifest',
+ hashes=['SHA256', 'SHA512'],
+ compress_watermark=0,
+ allow_create=True,
+ profile=profile())
+ m.update_entries_for_directory('')
+ m.save_manifests()
+
+ expected = dict(
+ itertools.chain.from_iterable(
+ [(path, None),
+ (path + '.gz', make_expect_match(path, 'MANIFEST')),
+ ]
+ for path in EXPECTED_MANIFESTS
+ if path not in PACKAGE_MANIFESTS))
+ expected.update(
+ itertools.chain.from_iterable(
+ [(path, make_expect_match(path, 'MANIFEST')),
+ (path + '.gz', None),
+ ]
+ for path in EXPECTED_MANIFESTS
+ if path in PACKAGE_MANIFESTS))
+ found = dict((path, make_entry_match(m, path))
+ for path in expected)
+ assert found == expected
+
+
+def test_no_compress_compat_cli(test_repo):
+ """Verify that package directory Manifests are not compressed (CLI)"""
+ profile = BackwardsCompatEbuildRepositoryProfile
+
+ assert gemato.cli.main(['gemato', 'create',
+ '--profile', profile.name,
+ '--compress-watermark=0',
+ str(test_repo)]) == 0
+
+ m = ManifestRecursiveLoader(test_repo / 'Manifest')
+ expected = dict(
+ itertools.chain.from_iterable(
+ [(path, None),
+ (path + '.gz', make_expect_match(path, 'MANIFEST')),
+ ]
+ for path in EXPECTED_MANIFESTS
+ if path not in PACKAGE_MANIFESTS))
+ expected.update(
+ itertools.chain.from_iterable(
+ [(path, make_expect_match(path, 'MANIFEST')),
+ (path + '.gz', None),
+ ]
+ for path in EXPECTED_MANIFESTS
+ if path in PACKAGE_MANIFESTS))
+ found = dict((path, make_entry_match(m, path))
+ for path in expected)
+ assert found == expected