diff options
author | 2013-07-04 23:27:30 +0200 | |
---|---|---|
committer | 2013-07-04 23:27:30 +0200 | |
commit | 3981c9bea9b4ddb464051e50f4d5357d0159072e (patch) | |
tree | 56421debbdf77a88461480619a4d2cfef43746f0 /tests | |
parent | g_elpa/elpa_db: variables necessary for ebuild generation (diff) | |
download | g-sorcery-3981c9bea9b4ddb464051e50f4d5357d0159072e.tar.gz g-sorcery-3981c9bea9b4ddb464051e50f4d5357d0159072e.tar.bz2 g-sorcery-3981c9bea9b4ddb464051e50f4d5357d0159072e.zip |
ebuild generation for ELPA backend added, different fixes in ebuild generator
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_ebuild.py | 5 | ||||
-rw-r--r-- | tests/test_elpa_db.py | 160 | ||||
-rw-r--r-- | tests/test_elpa_ebuild.py | 58 |
3 files changed, 151 insertions, 72 deletions
diff --git a/tests/test_ebuild.py b/tests/test_ebuild.py index 6a97249..47c4e40 100644 --- a/tests/test_ebuild.py +++ b/tests/test_ebuild.py @@ -89,8 +89,9 @@ class TestSubstituteList(BaseTest): desc = {'depend' : ['app-test/test1', 'app-test/test2'], 'iuse' : ['test', 'check']} result = ['a', 'test', 'DEPEND="app-test/test1\napp-test/test2"', 'IUSE="test check"'] - self.assertEqual(ebuild.substitute_list(text, desc), result) - self.assertRaises(exceptions.DescriptionError, ebuild.substitute_list, text, {}) + 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(): diff --git a/tests/test_elpa_db.py b/tests/test_elpa_db.py index 1ba99c7..ec50b14 100644 --- a/tests/test_elpa_db.py +++ b/tests/test_elpa_db.py @@ -11,7 +11,9 @@ :license: GPL-2, see LICENSE for more details. """ -import os, unittest +import os + +import unittest from g_elpa import elpa_db @@ -21,76 +23,90 @@ from tests.server import Server from tests.base import BaseTest +def generate_archive_contents(packages): + archive_contents = "(1" + for pkg in packages: + archive_contents += "\n(" + pkg[0] + ' . [(' + for v in pkg[1]: + archive_contents += ' ' + str(v) + archive_contents += ')\n' + if pkg[4]: + archive_contents += '(' + for p in pkg[4]: + archive_contents += '(' + p[0] + ' (' + for v in p[1]: + archive_contents += ' ' + str(v) + archive_contents += '))\n' + archive_contents += ')' + else: + archive_contents += 'nil' + archive_contents += '\n "' + pkg[2] + '" ' + pkg[3] + '])' + archive_contents += ')' + return archive_contents + +packages = [['ack', [1, 2], + "Interface to ack-like source code search tools", + "tar", + [] + ], + ['dict-tree', [0, 12, 8], + "Dictionary data structure", + "tar", + [['trie', [0, 2, 5]], + ['tNFA', [0, 1, 1]], + ['heap', [0, 3]]] + ], + ['tNFA', [0, 1, 1], + "Tagged non-deterministic finite-state automata", + "single", + [['queue', [0, 1]]] + ], + ['trie', [0, 2, 6], + "Trie data structure", + "single", + [['tNFA', [0, 1, 1]], + ['queue', [0, 1]]] + ], + ['heap', [0, 3], + "Heap (a.k.a. priority queue) data structure", + "single", + [] + ], + ['queue', [0, 1], + "Queue data structure", + "single", + [] + ] + ] + +def fill_database(database, packages, tempdir): + prev = os.getcwd() + os.chdir(tempdir) + + archive_contents = generate_archive_contents(packages) + + with open(os.path.join(tempdir, 'archive-contents'), 'w') as f: + f.write(archive_contents) + + server = Server() + server.start() + + database.generate() + + server.shutdown() + server.join() + + os.chdir(prev) + + class TestElpaDB(BaseTest): def test_generate(self): - prev = os.getcwd() - os.chdir(self.tempdir.name) edb = elpa_db.ElpaDB(os.path.join(self.tempdir.name, 'db'), repo_uri = 'http://127.0.0.1:8080') self.assertRaises(exceptions.SyncError, edb.generate) - packages = [['ack', [1, 2], - "Interface to ack-like source code search tools", - "tar", - [] - ], - ['dict-tree', [0, 12, 8], - "Dictionary data structure", - "tar", - [['trie', [0, 2, 5]], - ['tNFA', [0, 1, 1]], - ['heap', [0, 3]]] - ], - ['tNFA', [0, 1, 1], - "Tagged non-deterministic finite-state automata", - "single", - [['queue', [0, 1]]] - ], - ['trie', [0, 2, 6], - "Trie data structure", - "single", - [['tNFA', [0, 1, 1]], - ['queue', [0, 1]]] - ], - ['heap', [0, 3], - "Heap (a.k.a. priority queue) data structure", - "single", - [] - ], - ['queue', [0, 1], - "Queue data structure", - "single", - [] - ] - ] - - archive_contents = "(1" - for pkg in packages: - archive_contents += "\n(" + pkg[0] + ' . [(' - for v in pkg[1]: - archive_contents += ' ' + str(v) - archive_contents += ')\n' - if pkg[4]: - archive_contents += '(' - for p in pkg[4]: - archive_contents += '(' + p[0] + ' (' - for v in p[1]: - archive_contents += ' ' + str(v) - archive_contents += '))\n' - archive_contents += ')' - else: - archive_contents += 'nil' - archive_contents += '\n "' + pkg[2] + '" ' + pkg[3] + '])' - archive_contents += ')' - - with open(os.path.join(self.tempdir.name, 'archive-contents'), 'w') as f: - f.write(archive_contents) - - server = Server() - server.start() - - edb.generate() + fill_database(edb, packages, self.tempdir.name) for pkg in packages: package = package_db.Package('app-emacs', @@ -100,21 +116,25 @@ class TestElpaDB(BaseTest): self.assertEqual(description['source_type'], pkg[3]) self.assertEqual(description['description'], pkg[2]) deps = [] + depend=[] for d in pkg[4]: 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]))) + + dependencies = description['dependencies'] + for d in dependencies: + self.assertTrue(d in deps) + for d in deps: + self.assertTrue(d in dependencies) for ds in (description['depend'], description['rdepend']): for d in ds: - self.assertTrue(d in deps) - for d in deps: + self.assertTrue(d in depend) + for d in depend: self.assertTrue(d in ds) - - server.shutdown() - server.join() - os.chdir(prev) def suite(): suite = unittest.TestSuite() diff --git a/tests/test_elpa_ebuild.py b/tests/test_elpa_ebuild.py new file mode 100644 index 0000000..2c7cdf5 --- /dev/null +++ b/tests/test_elpa_ebuild.py @@ -0,0 +1,58 @@ +#!/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(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', '', '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=""', '', 'REPO_URI="http://127.0.0.1:8080"', + 'PKG_TYPE="tar"', 'REALNAME="ack"', '', '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', '', + '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=""', '', + 'REPO_URI="http://127.0.0.1:8080"', 'PKG_TYPE="tar"', + 'REALNAME="dict-tree"', '', + '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')) + return suite |