aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJauhien Piatlicki (jauhien) <piatlicki@gmail.com>2013-07-15 01:39:58 +0200
committerJauhien Piatlicki (jauhien) <piatlicki@gmail.com>2013-07-15 01:39:58 +0200
commit81fa1eb9662c77bb0cdae8efa1d62874e03ae62f (patch)
tree334fcf5483f93d0e43177073195d3266f083e4c4 /tests
parentg-elpa-overlays.xml (diff)
downloadg-sorcery-81fa1eb9662c77bb0cdae8efa1d62874e03ae62f.tar.gz
g-sorcery-81fa1eb9662c77bb0cdae8efa1d62874e03ae62f.tar.bz2
g-sorcery-81fa1eb9662c77bb0cdae8efa1d62874e03ae62f.zip
tests fixed
Diffstat (limited to 'tests')
-rw-r--r--tests/test_backend.py88
-rw-r--r--tests/test_dispatcher.py29
-rw-r--r--tests/test_ebuild.py25
-rw-r--r--tests/test_elpa_db.py2
-rw-r--r--tests/test_elpa_ebuild.py89
-rw-r--r--tests/test_g_sorcery.py70
6 files changed, 7 insertions, 296 deletions
diff --git a/tests/test_backend.py b/tests/test_backend.py
deleted file mode 100644
index 0ed5ff2..0000000
--- a/tests/test_backend.py
+++ /dev/null
@@ -1,88 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
- test_backend.py
- ~~~~~~~~~~~~~~~
-
- backend test suite
-
- :copyright: (c) 2013 by Jauhien Piatlicki
- :license: GPL-2, see LICENSE for more details.
-"""
-
-import os, tempfile, unittest
-
-from g_sorcery import backend, ebuild, metadata, package_db
-
-from tests import test_ebuild, test_metadata
-
-from tests.base import BaseTest
-
-class DummyBackend(backend.Backend):
- def __init__(self, PackageDB, EbuildGenrator, MetadataGenerator, directory,
- sync_db=True, eclass_dir=""):
- super(DummyBackend, self).__init__(PackageDB, EbuildGenrator, MetadataGenerator, directory,
- sync_db=sync_db, eclass_dir=eclass_dir)
-
-
-class TestBackend(BaseTest):
-
- 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']
- for f_name in lst:
- with open(os.path.join(self.tempdir.name, f_name + '.eclass'), 'w') as f:
- f.write("test")
- self.assertEqual(set(backend.list_eclasses()), set(lst))
-
- 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"
- with open(os.path.join(self.tempdir.name, eclass_name + '.eclass'), 'w') as f:
- for line in eclass:
- f.write(line + '\n')
- g_eclass = backend.generate_eclass(eclass_name)
- self.assertEqual(eclass, g_eclass)
-
- 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()
- self.assertEqual(set(ebuilds), set([test_ebuild.package, test_ebuild.package2]))
-
- 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_dispatcher.py b/tests/test_dispatcher.py
deleted file mode 100644
index 517158d..0000000
--- a/tests/test_dispatcher.py
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
- test_dispatcher.py
- ~~~~~~~~~~~~~~~~~~
-
- backend dispatcher test suite
-
- :copyright: (c) 2013 by Jauhien Piatlicki
- :license: GPL-2, see LICENSE for more details.
-"""
-
-import unittest
-
-from g_sorcery import dispatcher
-
-from tests.base import BaseTest
-
-class TestDispatcher(BaseTest):
-
- def test_dispatcher(self):
- pass
-
-
-def suite():
- suite = unittest.TestSuite()
- suite.addTest(TestDispatcher('test_dispatcher'))
- return suite
diff --git a/tests/test_ebuild.py b/tests/test_ebuild.py
index 47c4e40..7488152 100644
--- a/tests/test_ebuild.py
+++ b/tests/test_ebuild.py
@@ -13,7 +13,7 @@
import os, tempfile, unittest
-from g_sorcery import ebuild, package_db, exceptions
+from g_sorcery import ebuild, package_db, exceptions, g_collections
from tests.base import BaseTest
@@ -34,7 +34,7 @@ class DummyDB(package_db.PackageDB):
class DummyEbuildGenerator(ebuild.EbuildGenerator):
def get_template(self, ebuild, description):
- tmpl = ["test", "author: $author", "homepage: $homepage", "var: $$var"]
+ tmpl = ["test", "author: %(author)s", "homepage: %(homepage)s", "var: $var"]
return tmpl
@@ -43,7 +43,7 @@ class TestEbuildGenerator(BaseTest):
def test_process(self):
eg = DummyEbuildGenerator(None)
tst_dict = {"a" : "d", "b" : "e", "c" : "f"}
- ebuild = ["$a", "$b", "$c"]
+ ebuild = ["%(a)s", "%(b)s", "%(c)s"]
ebuild = eg.process(ebuild, tst_dict)
self.assertEqual(ebuild, ["d", "e", "f"])
@@ -73,31 +73,18 @@ class TestEbuildGeneratorFromFile(BaseTest):
tmpl = os.path.join(self.tempdir.name, 'tst.tmpl')
with open(tmpl, 'w') as f:
f.write("""test
-author: $author
-homepage: $homepage
-var: $$var""")
+author: %(author)s
+homepage: %(homepage)s
+var: $var""")
eg = DummyEbuildGeneratorFromFile(db, tmpl)
ebuild = eg.generate(package)
self.assertEqual(ebuild, ['test', 'author: jauhien',
'homepage: 127.0.0.1', 'var: $var'])
-
-class TestSubstituteList(BaseTest):
-
- def test_substitute_list(self):
- text = ['a', 'test', 'DEPEND="#n#depend#"', 'IUSE="# #iuse#"']
- desc = {'depend' : ['app-test/test1', 'app-test/test2'],
- 'iuse' : ['test', 'check']}
- result = ['a', 'test', 'DEPEND="app-test/test1\napp-test/test2"', 'IUSE="test check"']
- for idx, string in enumerate(text):
- self.assertEqual(ebuild.substitute_list(string, desc), result[idx])
- self.assertRaises(exceptions.DescriptionError, ebuild.substitute_list, text[2], {})
-
def suite():
suite = unittest.TestSuite()
suite.addTest(TestEbuildGenerator('test_process'))
suite.addTest(TestEbuildGenerator('test_generate'))
suite.addTest(TestEbuildGeneratorFromFile('test_generate'))
- suite.addTest(TestSubstituteList('test_substitute_list'))
return suite
diff --git a/tests/test_elpa_db.py b/tests/test_elpa_db.py
index ec50b14..3df86e1 100644
--- a/tests/test_elpa_db.py
+++ b/tests/test_elpa_db.py
@@ -121,7 +121,7 @@ class TestElpaDB(BaseTest):
deps.append(package_db.Package('app-emacs',
d[0],
'.'.join(map(str, d[1]))))
- depend.append('app-emacs' + '/' + d[0] + '-' + '.'.join(map(str, d[1])))
+ depend.append('app-emacs' + '/' + d[0])
dependencies = description['dependencies']
for d in dependencies:
diff --git a/tests/test_elpa_ebuild.py b/tests/test_elpa_ebuild.py
deleted file mode 100644
index 1895340..0000000
--- a/tests/test_elpa_ebuild.py
+++ /dev/null
@@ -1,89 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
- test_elpa_ebuild.py
- ~~~~~~~~~~~~~~~~~~~
-
- ELPA ebuild generator test suite
-
- :copyright: (c) 2013 by Jauhien Piatlicki
- :license: GPL-2, see LICENSE for more details.
-"""
-
-import os, unittest
-
-from g_sorcery import package_db
-
-from g_elpa import elpa_db, ebuild
-
-from tests.base import BaseTest
-
-from tests.test_elpa_db import fill_database, packages
-
-class TestElpaEbuildGenerator(BaseTest):
-
- def test_generate_without_digest(self):
- edb = elpa_db.ElpaDB(os.path.join(self.tempdir.name, 'db'),
- repo_uri = 'http://127.0.0.1:8080')
- fill_database(edb, packages, self.tempdir.name)
- ebuild_generator = ebuild.ElpaEbuildWithoutDigestGenerator(edb)
- src = ebuild_generator.generate(package_db.Package('app-emacs', 'ack', '1.2'))
- self.assertEqual(src,
- ['# automatically generated by g-elpa',
- '# please do not edit this file', '',
- 'EAPI=5', '', 'REPO_URI="http://127.0.0.1:8080"',
- 'PKG_TYPE="tar"', 'REALNAME="ack"', '', 'inherit g-elpa', '',
- 'DESCRIPTION="Interface to ack-like source code search tools"',
- 'HOMEPAGE="http://127.0.0.1:8080"', 'SRC_URI=""',
- 'LICENSE="GPL-2"', '', 'SLOT="0"', 'KEYWORDS="~amd64 ~x86"',
- 'IUSE=""', '', 'DEPEND=""', 'RDEPEND=""'])
- src = ebuild_generator.generate(package_db.Package('app-emacs', 'dict-tree', '0.12.8'))
- self.assertEqual(src,
- ['# automatically generated by g-elpa',
- '# please do not edit this file', '', 'EAPI=5', '',
- 'REPO_URI="http://127.0.0.1:8080"', 'PKG_TYPE="tar"',
- 'REALNAME="dict-tree"', '',
- 'inherit g-elpa', '', 'DESCRIPTION="Dictionary data structure"',
- 'HOMEPAGE="http://127.0.0.1:8080"', 'SRC_URI=""',
- 'LICENSE="GPL-2"', '', 'SLOT="0"',
- 'KEYWORDS="~amd64 ~x86"', 'IUSE=""', '',
- 'DEPEND="app-emacs/trie-0.2.5\napp-emacs/tNFA-0.1.1\napp-emacs/heap-0.3"',
- 'RDEPEND="app-emacs/trie-0.2.5\napp-emacs/tNFA-0.1.1\napp-emacs/heap-0.3"'])
-
- def test_generate_with_digest(self):
- edb = elpa_db.ElpaDB(os.path.join(self.tempdir.name, 'db'),
- repo_uri = 'http://127.0.0.1:8080')
- fill_database(edb, packages, self.tempdir.name)
- ebuild_generator = ebuild.ElpaEbuildWithDigestGenerator(edb)
- src = ebuild_generator.generate(package_db.Package('app-emacs', 'ack', '1.2'))
- self.assertEqual(src,
- ['# automatically generated by g-elpa',
- '# please do not edit this file', '',
- 'EAPI=5', '', 'REPO_URI="http://127.0.0.1:8080"',
- 'PKG_TYPE="tar"', 'REALNAME="ack"', '', 'inherit g-elpa', '',
- 'DESCRIPTION="Interface to ack-like source code search tools"',
- 'HOMEPAGE="http://127.0.0.1:8080"',
- 'SRC_URI="${REPO_URI}${REALNAME}-${PV}.${SUFFIX}"',
- 'LICENSE="GPL-2"', '', 'SLOT="0"', 'KEYWORDS="~amd64 ~x86"',
- 'IUSE=""', '', 'DEPEND=""', 'RDEPEND=""'])
- src = ebuild_generator.generate(package_db.Package('app-emacs', 'dict-tree', '0.12.8'))
- self.assertEqual(src,
- ['# automatically generated by g-elpa',
- '# please do not edit this file', '', 'EAPI=5', '',
- 'REPO_URI="http://127.0.0.1:8080"', 'PKG_TYPE="tar"',
- 'REALNAME="dict-tree"', '',
- 'inherit g-elpa', '', 'DESCRIPTION="Dictionary data structure"',
- 'HOMEPAGE="http://127.0.0.1:8080"',
- 'SRC_URI="${REPO_URI}${REALNAME}-${PV}.${SUFFIX}"',
- 'LICENSE="GPL-2"', '', 'SLOT="0"',
- 'KEYWORDS="~amd64 ~x86"', 'IUSE=""', '',
- 'DEPEND="app-emacs/trie-0.2.5\napp-emacs/tNFA-0.1.1\napp-emacs/heap-0.3"',
- 'RDEPEND="app-emacs/trie-0.2.5\napp-emacs/tNFA-0.1.1\napp-emacs/heap-0.3"'])
-
-
-def suite():
- suite = unittest.TestSuite()
- suite.addTest(TestElpaEbuildGenerator('test_generate_without_digest'))
- suite.addTest(TestElpaEbuildGenerator('test_generate_with_digest'))
- return suite
diff --git a/tests/test_g_sorcery.py b/tests/test_g_sorcery.py
deleted file mode 100644
index 2004a9a..0000000
--- a/tests/test_g_sorcery.py
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
- test_g_sorcery.py
- ~~~~~~~~~~~~~~~~~
-
- executable and main module test suite
-
- :copyright: (c) 2013 by Jauhien Piatlicki
- :license: GPL-2, see LICENSE for more details.
-"""
-
-import os, subprocess, tempfile, unittest
-
-from g_sorcery import g_sorcery
-
-from tests.dummy_backend import backend as dummyBackend
-
-from tests.base import BaseTest
-
-class TestBin(BaseTest):
- def setUp(self):
- super(TestBin, self).setUp()
-
- binpath = os.path.join(os.path.dirname(
- os.path.dirname(os.path.realpath(__file__))), 'bin')
- self.binary = os.path.join(binpath, 'g-sorcery')
-
- def test_g_sorcery(self):
- self.assertEqual(subprocess.check_output(self.binary), b'No backend specified\n')
-
- def test_nonexistent_backend(self):
- prev = os.getcwd()
- os.chdir(self.tempdir.name)
- os.system('ln -s ' + self.binary + ' g-nonexistent')
- self.assertRaises(subprocess.CalledProcessError, subprocess.check_output, './g-nonexistent')
- os.chdir(prev)
-
- def test_empty_config(self):
- prev = os.getcwd()
- os.chdir(self.tempdir.name)
- os.system('ln -s ' + self.binary + ' g-empty')
- os.system('echo {} > ./g-empty.json')
- self.assertRaises(subprocess.CalledProcessError, subprocess.check_output, './g-empty')
- os.chdir(prev)
-
- def test_config(self):
- prev = os.getcwd()
- os.chdir(self.tempdir.name)
- os.system('ln -s ' + self.binary + ' g-dummy')
- os.system('echo {\\"package\\": \\"dummy_backend\\"} > ./g-dummy.json')
- self.assertEqual(subprocess.check_output(['./g-dummy', 'test']).decode("utf-8")[:-1],
- 'test')
- os.chdir(prev)
-
-class TestGSorcery(BaseTest):
-
- def test_get_backend(self):
- self.assertEqual(g_sorcery.get_backend('nonexistent_backend'), None)
- self.assertEqual(g_sorcery.get_backend('dummy_backend').dispatcher, dummyBackend.dispatcher)
-
-def suite():
- suite = unittest.TestSuite()
- suite.addTest(TestBin('test_g_sorcery'))
- suite.addTest(TestBin('test_nonexistent_backend'))
- suite.addTest(TestBin('test_empty_config'))
- suite.addTest(TestBin('test_config'))
- suite.addTest(TestGSorcery('test_get_backend'))
- return suite