diff options
author | Jauhien Piatlicki (jauhien) <piatlicki@gmail.com> | 2013-07-01 02:06:52 +0200 |
---|---|---|
committer | Jauhien Piatlicki (jauhien) <piatlicki@gmail.com> | 2013-07-01 02:06:52 +0200 |
commit | e34a7a1d98b0a3b1ff1a8ea35d1a70134989e555 (patch) | |
tree | 3023d2534fd3b6c1379861a906102628b049da3d /tests | |
parent | g_sorcery/metadata: MetadataGenerator, generate (diff) | |
download | g-sorcery-e34a7a1d98b0a3b1ff1a8ea35d1a70134989e555.tar.gz g-sorcery-e34a7a1d98b0a3b1ff1a8ea35d1a70134989e555.tar.bz2 g-sorcery-e34a7a1d98b0a3b1ff1a8ea35d1a70134989e555.zip |
g_sorcery/backend: generate_metadata
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_backend.py | 23 | ||||
-rw-r--r-- | tests/test_metadata.py | 26 | ||||
-rw-r--r-- | tests/test_package_db.py | 6 |
3 files changed, 39 insertions, 16 deletions
diff --git a/tests/test_backend.py b/tests/test_backend.py index 027f4a8..65e136d 100644 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -13,14 +13,14 @@ import os, tempfile, unittest -from g_sorcery import backend, ebuild, package_db +from g_sorcery import backend, ebuild, metadata, package_db -from tests import test_ebuild +from tests import test_ebuild, test_metadata class DummyBackend(backend.Backend): - def __init__(self, PackageDB, EbuildGenrator, directory, + def __init__(self, PackageDB, EbuildGenrator, MetadataGenerator, directory, sync_db=True, eclass_dir=""): - super().__init__(PackageDB, EbuildGenrator, directory, + super().__init__(PackageDB, EbuildGenrator, MetadataGenerator, directory, sync_db=sync_db, eclass_dir=eclass_dir) @@ -34,6 +34,7 @@ class TestBackend(unittest.TestCase): def test_list_eclasses(self): backend = DummyBackend(package_db.PackageDB, ebuild.EbuildGenerator, + metadata.MetadataGenerator, self.tempdir.name, eclass_dir = self.tempdir.name) self.assertEqual(backend.list_eclasses(), []) lst = ['test', 'supertest', 'anothertest'] @@ -44,6 +45,7 @@ class TestBackend(unittest.TestCase): def test_generate_eclass(self): backend = DummyBackend(package_db.PackageDB, ebuild.EbuildGenerator, + metadata.MetadataGenerator, self.tempdir.name, eclass_dir = self.tempdir.name) eclass = ["testing eclass", "nothing interesting here"] eclass_name = "test" @@ -55,6 +57,7 @@ class TestBackend(unittest.TestCase): def test_list_ebuilds(self): backend = DummyBackend(test_ebuild.DummyDB, test_ebuild.DummyEbuildGenerator, + metadata.MetadataGenerator, self.tempdir.name, eclass_dir = self.tempdir.name, sync_db = False) backend.sync() ebuilds = backend.list_ebuilds() @@ -62,16 +65,28 @@ class TestBackend(unittest.TestCase): def test_generate_ebuild(self): backend = DummyBackend(test_ebuild.DummyDB, test_ebuild.DummyEbuildGenerator, + metadata.MetadataGenerator, self.tempdir.name, eclass_dir = self.tempdir.name, sync_db = False) backend.sync() ebuild = backend.generate_ebuild(test_ebuild.package) self.assertEqual(ebuild, ['test', 'author: jauhien', 'homepage: 127.0.0.1', 'var: $var']) + def test_generate_metadata(self): + backend = DummyBackend(test_metadata.DummyDB, ebuild.EbuildGenerator, + metadata.MetadataGenerator, + self.tempdir.name, eclass_dir = self.tempdir.name, sync_db = False) + backend.sync() + self.assertEqual(backend.generate_metadata("app-test", "test"), + test_metadata.resulting_metadata) + + + def suite(): suite = unittest.TestSuite() suite.addTest(TestBackend('test_list_eclasses')) suite.addTest(TestBackend('test_generate_eclass')) suite.addTest(TestBackend('test_list_ebuilds')) suite.addTest(TestBackend('test_generate_ebuild')) + suite.addTest(TestBackend('test_generate_metadata')) return suite diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 2398733..9bb1f43 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -87,6 +87,18 @@ description = {'herd' : ['test'], 'use' : {'flag' : [('flag1', 'test flag1'), ('flag2', 'test flag2')]}, 'upstream' : {'maintainer' : [{'name' : 'TEST'}], 'remote-id' : '001'}} +resulting_metadata = ['<?xml version="1.0" encoding="utf-8"?>', + '<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">', + '<pkgmetadata>', '\t<herd>test</herd>', + '\t<maintainer>', '\t\t<email>test@example.com</email>', + '\t\t<name>testor</name>', '\t</maintainer>', + '\t<longdescription>test metadata</longdescription>', + '\t<use>', '\t\t<flag name="flag1">test flag1</flag>', + '\t\t<flag name="flag2">test flag2</flag>', '\t</use>', + '\t<upstream>', '\t\t<maintainer>', '\t\t\t<name>TEST</name>', + '\t\t</maintainer>', '\t\t<remote-id>001</remote-id>', + '\t</upstream>', '</pkgmetadata>'] + class DummyDB(package_db.PackageDB): def __init__(self, directory, repo_uri="", db_uri=""): super().__init__(directory, repo_uri, db_uri) @@ -116,19 +128,9 @@ class TestMetadataGenerator(unittest.TestCase): db.generate() mg = DummyMetadataGenerator(db) metadata = mg.generate(package) - self.assertEqual(metadata, - ['<?xml version="1.0" encoding="utf-8"?>', - '<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">', - '<pkgmetadata>', '\t<herd>test</herd>', - '\t<maintainer>', '\t\t<email>test@example.com</email>', - '\t\t<name>testor</name>', '\t</maintainer>', - '\t<longdescription>test metadata</longdescription>', - '\t<use>', '\t\t<flag name="flag1">test flag1</flag>', - '\t\t<flag name="flag2">test flag2</flag>', '\t</use>', - '\t<upstream>', '\t\t<maintainer>', '\t\t\t<name>TEST</name>', - '\t\t</maintainer>', '\t\t<remote-id>001</remote-id>', - '\t</upstream>', '</pkgmetadata>']) + self.assertEqual(metadata, resulting_metadata) + def suite(): suite = unittest.TestSuite() suite.addTest(TestXMLGenerator('test_generate')) diff --git a/tests/test_package_db.py b/tests/test_package_db.py index 2b8c482..c5d7074 100644 --- a/tests/test_package_db.py +++ b/tests/test_package_db.py @@ -219,6 +219,11 @@ class TestDummyDB(unittest.TestCase): db = DummyDB(os.path.join(self.tempdir.name, 'testdb'), self.packages) self.assertRaises(exceptions.SyncError, db.sync, db_uri='127.0.0.1:8080') + def test_get_max_version(self): + db = DummyDB(os.path.join(self.tempdir.name, 'testdb'), self.packages) + db.generate() + self.assertEqual(db.get_max_version('dev-test', 'test'), '0.2') + def suite(): suite = unittest.TestSuite() @@ -237,4 +242,5 @@ def suite(): suite.addTest(TestDummyDB('test_list_package_versions')) suite.addTest(TestDummyDB('test_sync')) suite.addTest(TestDummyDB('test_sync_fail')) + suite.addTest(TestDummyDB('test_get_max_version')) return suite |