* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-06-23 0:44 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-06-23 0:44 UTC (permalink / raw
To: gentoo-commits
commit: c5cc4d64b56c30fdb216d407038f25f01e0b9e5c
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Sat Jun 22 22:57:08 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Sat Jun 22 22:57:08 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=c5cc4d64
tests/test_package_db: fail sync test
---
tests/test_package_db.py | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/tests/test_package_db.py b/tests/test_package_db.py
index 62b073f..0fc3d51 100644
--- a/tests/test_package_db.py
+++ b/tests/test_package_db.py
@@ -211,6 +211,10 @@ class TestDummyDB(unittest.TestCase):
self.assertEqual(src_db.db, db.db)
+ def test_sync_fail(self):
+ db = DummyDB(os.path.join(self.tempdir.name, 'testdb'), self.packages)
+ self.assertRaises(Exception, db.sync, db_uri='127.0.0.1:8080')
+
def suite():
suite = unittest.TestSuite()
@@ -228,4 +232,5 @@ def suite():
suite.addTest(TestDummyDB('test_list_package_names'))
suite.addTest(TestDummyDB('test_list_package_versions'))
suite.addTest(TestDummyDB('test_sync'))
+ suite.addTest(TestDummyDB('test_sync_fail'))
return suite
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-06-23 0:44 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-06-23 0:44 UTC (permalink / raw
To: gentoo-commits
commit: acabc778323fb3cd362716dc1f66c7b4cda217e3
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Sun Jun 23 00:23:09 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Sun Jun 23 00:23:09 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=acabc778
tests/test_package_db: return to the previous dir after test
---
tests/test_package_db.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tests/test_package_db.py b/tests/test_package_db.py
index 0fc3d51..94693d8 100644
--- a/tests/test_package_db.py
+++ b/tests/test_package_db.py
@@ -197,6 +197,7 @@ class TestDummyDB(unittest.TestCase):
src_db = DummyDB(os.path.join(self.tempdir.name, 'src_testdb'), self.packages)
src_db.generate()
+ prev = os.getcwd()
os.chdir(self.tempdir.name)
os.system('tar cvzf dummy.tar.gz src_testdb')
@@ -209,6 +210,8 @@ class TestDummyDB(unittest.TestCase):
server.shutdown()
server.join()
+ os.chdir(prev)
+
self.assertEqual(src_db.db, db.db)
def test_sync_fail(self):
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-07-02 10:21 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-07-02 10:21 UTC (permalink / raw
To: gentoo-commits
commit: 70190446ac3e2be5fc946da165a9eb81d8d6594b
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Tue Jul 2 10:22:15 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Tue Jul 2 10:22:15 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=70190446
tests/server: separate http server
---
tests/server.py | 26 ++++++++++++++++++++++++++
tests/test_package_db.py | 17 ++---------------
2 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/tests/server.py b/tests/server.py
new file mode 100644
index 0000000..ba4ed99
--- /dev/null
+++ b/tests/server.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+ server.py
+ ~~~~~~~~~
+
+ test server
+
+ :copyright: (c) 2013 by Jauhien Piatlicki
+ :license: GPL-2, see LICENSE for more details.
+"""
+
+import http.server, threading
+
+class Server(threading.Thread):
+ def __init__(self):
+ super().__init__()
+ server_address = ('127.0.0.1', 8080)
+ self.httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler)
+
+ def run(self):
+ self.httpd.serve_forever()
+
+ def shutdown(self):
+ self.httpd.shutdown()
diff --git a/tests/test_package_db.py b/tests/test_package_db.py
index 2994157..1433eb7 100644
--- a/tests/test_package_db.py
+++ b/tests/test_package_db.py
@@ -11,24 +11,11 @@
:license: GPL-2, see LICENSE for more details.
"""
-import json, http.server, os, shutil, tempfile, threading, \
- unittest
+import json, os, shutil, tempfile, unittest
from g_sorcery import package_db, exceptions
-
-class Server(threading.Thread):
- def __init__(self):
- super().__init__()
- server_address = ('127.0.0.1', 8080)
- self.httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler)
-
- def run(self):
- self.httpd.serve_forever()
-
- def shutdown(self):
- self.httpd.shutdown()
-
+from tests.server import Server
class DummyDB(package_db.PackageDB):
def __init__(self, directory, packages):
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-07-02 14:48 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-07-02 14:48 UTC (permalink / raw
To: gentoo-commits
commit: ab7e4b9f72ac3fcf90a04d1743a2823e431ed0ef
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Tue Jul 2 14:49:51 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Tue Jul 2 14:49:51 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=ab7e4b9f
py2k: tests/server
---
tests/server.py | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/tests/server.py b/tests/server.py
index ef17849..41767fc 100644
--- a/tests/server.py
+++ b/tests/server.py
@@ -11,13 +11,23 @@
:license: GPL-2, see LICENSE for more details.
"""
-import http.server, threading
+import threading
+
+from g_sorcery.compatibility import py2k
+
+if py2k:
+ from SocketServer import TCPServer as HTTPServer
+ from SimpleHTTPServer import SimpleHTTPRequestHandler
+else:
+ from http.server import HTTPServer
+ from http.server import SimpleHTTPRequestHandler
class Server(threading.Thread):
def __init__(self):
super(Server, self).__init__()
+ HTTPServer.allow_reuse_address = True
server_address = ('127.0.0.1', 8080)
- self.httpd = http.server.HTTPServer(server_address, http.server.SimpleHTTPRequestHandler)
+ self.httpd = HTTPServer(server_address, SimpleHTTPRequestHandler)
def run(self):
self.httpd.serve_forever()
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-07-08 23:53 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-07-08 23:53 UTC (permalink / raw
To: gentoo-commits
commit: 5cec193a5271ef3ca4577390f7aa242df5eb71ea
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Mon Jul 8 23:52:46 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Mon Jul 8 23:52:46 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=5cec193a
tests/test_package_db: sort list
---
tests/test_package_db.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/tests/test_package_db.py b/tests/test_package_db.py
index d491152..b2d51a2 100644
--- a/tests/test_package_db.py
+++ b/tests/test_package_db.py
@@ -72,7 +72,7 @@ class TestDummyDB(BaseTest):
categories = list(set([x.category for x in self.packages]))
for category in categories:
package_names = list(set([x.name for x in self.packages if x.category == category]))
- self.assertEqual(package_names, db.list_package_names(category))
+ self.assertEqual(package_names.sort(), db.list_package_names(category).sort())
self.assertRaises(exceptions.InvalidKeyError, db.list_package_names, 'no_such_category')
def test_list_package_versions(self):
@@ -82,8 +82,9 @@ class TestDummyDB(BaseTest):
for category in categories:
package_names = list(set([x.name for x in self.packages if x.category == category]))
for name in package_names:
- versions = [x.version for x in self.packages if x.category == category and x.name == name]
- self.assertEqual(versions, db.list_package_versions(category, name))
+ versions = [x.version for x in self.packages
+ if x.category == category and x.name == name]
+ self.assertEqual(versions.sort(), db.list_package_versions(category, name).sort())
self.assertRaises(exceptions.InvalidKeyError, db.list_package_versions, 'no_such_category', 'a')
self.assertRaises(exceptions.InvalidKeyError, db.list_package_versions,
categories[0], 'no_such_package')
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-07-14 23:39 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-07-14 23:39 UTC (permalink / raw
To: gentoo-commits
commit: 81fa1eb9662c77bb0cdae8efa1d62874e03ae62f
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Sun Jul 14 23:39:58 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Sun Jul 14 23:39:58 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=81fa1eb9
tests fixed
---
tests/test_backend.py | 88 ----------------------------------------------
tests/test_dispatcher.py | 29 ---------------
tests/test_ebuild.py | 25 ++++---------
tests/test_elpa_db.py | 2 +-
tests/test_elpa_ebuild.py | 89 -----------------------------------------------
tests/test_g_sorcery.py | 70 -------------------------------------
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
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-07-17 15:41 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-07-17 15:41 UTC (permalink / raw
To: gentoo-commits
commit: 2789f0da5f054918b46d1e34b67d7cca77f8ffab
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Wed Jul 17 15:38:10 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Wed Jul 17 15:38:10 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=2789f0da
tests/test_elpa_db: test fixed
---
tests/test_elpa_db.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/test_elpa_db.py b/tests/test_elpa_db.py
index 3df86e1..cd6ebc2 100644
--- a/tests/test_elpa_db.py
+++ b/tests/test_elpa_db.py
@@ -104,7 +104,7 @@ class TestElpaDB(BaseTest):
def test_generate(self):
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)
+ self.assertRaises(exceptions.DownloadingError, edb.generate)
fill_database(edb, packages, self.tempdir.name)
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-09-15 22:38 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-09-15 22:38 UTC (permalink / raw
To: gentoo-commits
commit: 9ee27d984bb6f56e20c937e1436230c2c06e8987
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Sun Sep 15 21:34:10 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Sun Sep 15 21:34:10 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=9ee27d98
add tests for FileJSON with serialization
---
tests/test_FileJSON.py | 112 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 112 insertions(+)
diff --git a/tests/test_FileJSON.py b/tests/test_FileJSON.py
new file mode 100644
index 0000000..5bda353
--- /dev/null
+++ b/tests/test_FileJSON.py
@@ -0,0 +1,112 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+ test_FileJSON.py
+ ~~~~~~~~~~~~~~~~
+
+ FileJSON test suite
+
+ :copyright: (c) 2013 by Jauhien Piatlicki
+ :license: GPL-2, see LICENSE for more details.
+"""
+
+import json
+import os
+import unittest
+
+from g_sorcery.fileutils import FileJSON
+from g_sorcery.exceptions import FileJSONError
+
+from tests.base import BaseTest
+
+
+class NonSerializableClass(object):
+ pass
+
+
+class SerializableClass(object):
+
+ __slots__ = ("field1", "field2")
+
+ def __init__(self, field1, field2):
+ self.field1 = field1
+ self.field2 = field2
+
+ def __eq__(self, other):
+ return self.field1 == other.field1 \
+ and self.field2 == other.field2
+
+ def serialize(self):
+ return {"field1": self.field1, "field2": self.field2}
+
+
+class DeserializableClass(SerializableClass):
+
+ @classmethod
+ def deserialize(cls, value):
+ return DeserializableClass(value["field1"], value["field2"])
+
+
+class TestFileJSON(BaseTest):
+ def setUp(self):
+ super(TestFileJSON, self).setUp()
+ self.directory = os.path.join(self.tempdir.name, 'tst')
+ self.name = 'tst.json'
+ self.path = os.path.join(self.directory, self.name)
+
+ def test_read_nonexistent(self):
+ fj = FileJSON(self.directory, self.name, [])
+ content = fj.read()
+ self.assertEqual(content, {})
+ self.assertTrue(os.path.isfile(self.path))
+
+ def test_read_nonexistent_mandatory_key(self):
+ fj = FileJSON(self.directory, self.name, ["mandatory1", "mandatory2"])
+ content = fj.read()
+ self.assertEqual(content, {"mandatory1":"", "mandatory2":""})
+ self.assertTrue(os.path.isfile(self.path))
+
+ def test_read_luck_of_mandatory_key(self):
+ fj = FileJSON(self.directory, self.name, ["mandatory"])
+ os.makedirs(self.directory)
+ with open(self.path, 'w') as f:
+ json.dump({"test":"test"}, f)
+ self.assertRaises(FileJSONError, fj.read)
+
+ def test_write_luck_of_mandatory_key(self):
+ fj = FileJSON(self.directory, self.name, ["mandatory"])
+ self.assertRaises(FileJSONError, fj.write, {"test":"test"})
+
+ def test_write_read(self):
+ fj = FileJSON(self.directory, self.name, ["mandatory"])
+ content = {"mandatory":"1", "test":"2"}
+ fj.write(content)
+ content_r = fj.read()
+ self.assertEqual(content, content_r)
+
+ def test_serializable(self):
+ fj = FileJSON(self.directory, self.name, [])
+ content = SerializableClass("1", "2")
+ fj.write(content)
+ content_r = fj.read()
+ self.assertEqual(content_r, {"field1":"1", "field2":"2"})
+ self.assertRaises(TypeError, fj.write, NonSerializableClass())
+
+ def test_deserializable(self):
+ fj = FileJSON(self.directory, self.name, [])
+ content = DeserializableClass("1", "2")
+ fj.write(content)
+ content_r = fj.read()
+ self.assertEqual(content, content_r)
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(TestFileJSON('test_read_nonexistent'))
+ suite.addTest(TestFileJSON('test_read_nonexistent_mandatory_key'))
+ suite.addTest(TestFileJSON('test_read_luck_of_mandatory_key'))
+ suite.addTest(TestFileJSON('test_write_luck_of_mandatory_key'))
+ suite.addTest(TestFileJSON('test_write_read'))
+ suite.addTest(TestFileJSON('test_serializable'))
+ suite.addTest(TestFileJSON('test_deserializable'))
+ return suite
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-09-15 22:38 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-09-15 22:38 UTC (permalink / raw
To: gentoo-commits
commit: 78b67e03b3913447dad8a77ca7fc356f15b98485
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Sun Sep 15 21:18:12 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Sun Sep 15 21:18:12 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=78b67e03
remove old tests
---
tests/test_dummy.py | 26 --------
tests/test_ebuild.py | 90 ----------------------------
tests/test_elpa_db.py | 142 --------------------------------------------
tests/test_elpa_metadata.py | 47 ---------------
tests/test_fileutils.py | 119 -------------------------------------
tests/test_metadata.py | 134 -----------------------------------------
tests/test_package_db.py | 133 -----------------------------------------
7 files changed, 691 deletions(-)
diff --git a/tests/test_dummy.py b/tests/test_dummy.py
deleted file mode 100644
index 58df716..0000000
--- a/tests/test_dummy.py
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
- test_dummy.py
- ~~~~~~~~~~~~~
-
- dummy test suite
-
- :copyright: (c) 2013 by Jauhien Piatlicki
- :license: GPL-2, see LICENSE for more details.
-"""
-
-import unittest
-
-from tests.base import BaseTest
-
-class TestDummy(BaseTest):
-
- def test_dummy(self):
- self.assertEqual('works', 'works')
-
-def suite():
- suite = unittest.TestSuite()
- suite.addTest(TestDummy('test_dummy'))
- return suite
diff --git a/tests/test_ebuild.py b/tests/test_ebuild.py
deleted file mode 100644
index 7488152..0000000
--- a/tests/test_ebuild.py
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
- test_ebuild.py
- ~~~~~~~~~~~~~~~~~~
-
- ebuild generator test suite
-
- :copyright: (c) 2013 by Jauhien Piatlicki
- :license: GPL-2, see LICENSE for more details.
-"""
-
-import os, tempfile, unittest
-
-from g_sorcery import ebuild, package_db, exceptions, g_collections
-
-from tests.base import BaseTest
-
-package = package_db.Package("app-test", "test", "0.1")
-package2 = package_db.Package("app-test", "tst", "1")
-
-class DummyDB(package_db.PackageDB):
- def __init__(self, directory, repo_uri="", db_uri=""):
- super(DummyDB, self).__init__(directory, repo_uri, db_uri)
-
- def generate_tree(self):
- self.add_category("app-test")
- self.add_package(package,
- {"author" : "jauhien", "homepage" : "127.0.0.1"})
- self.add_package(package2,
- {"author" : "unknown", "homepage" : "example.com"})
-
-
-class DummyEbuildGenerator(ebuild.EbuildGenerator):
- def get_template(self, ebuild, description):
- tmpl = ["test", "author: %(author)s", "homepage: %(homepage)s", "var: $var"]
- return tmpl
-
-
-class TestEbuildGenerator(BaseTest):
-
- def test_process(self):
- eg = DummyEbuildGenerator(None)
- tst_dict = {"a" : "d", "b" : "e", "c" : "f"}
- ebuild = ["%(a)s", "%(b)s", "%(c)s"]
- ebuild = eg.process(ebuild, tst_dict)
- self.assertEqual(ebuild, ["d", "e", "f"])
-
- def test_generate(self):
- db = DummyDB(self.tempdir.name)
- db.generate()
- eg = DummyEbuildGenerator(db)
- ebuild = eg.generate(package)
- self.assertEqual(ebuild, ['test', 'author: jauhien',
- 'homepage: 127.0.0.1', 'var: $var'])
-
-
-class DummyEbuildGeneratorFromFile(ebuild.EbuildGeneratorFromFile):
- def __init__(self, db, path):
- super(DummyEbuildGeneratorFromFile, self).__init__(db)
- self.path = path
-
- def get_template_file(self, package, description):
- return self.path
-
-
-class TestEbuildGeneratorFromFile(BaseTest):
-
- def test_generate(self):
- db = DummyDB(os.path.join(self.tempdir.name, 'tstdb'))
- db.generate()
- tmpl = os.path.join(self.tempdir.name, 'tst.tmpl')
- with open(tmpl, 'w') as f:
- f.write("""test
-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'])
-
-
-def suite():
- suite = unittest.TestSuite()
- suite.addTest(TestEbuildGenerator('test_process'))
- suite.addTest(TestEbuildGenerator('test_generate'))
- suite.addTest(TestEbuildGeneratorFromFile('test_generate'))
- return suite
diff --git a/tests/test_elpa_db.py b/tests/test_elpa_db.py
deleted file mode 100644
index cd6ebc2..0000000
--- a/tests/test_elpa_db.py
+++ /dev/null
@@ -1,142 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
- test_elpa_db.py
- ~~~~~~~~~~~~~~~
-
- ELPA package database test suite
-
- :copyright: (c) 2013 by Jauhien Piatlicki
- :license: GPL-2, see LICENSE for more details.
-"""
-
-import os
-
-import unittest
-
-from g_elpa import elpa_db
-
-from g_sorcery import exceptions, package_db
-
-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):
- edb = elpa_db.ElpaDB(os.path.join(self.tempdir.name, 'db'),
- repo_uri = 'http://127.0.0.1:8080')
- self.assertRaises(exceptions.DownloadingError, edb.generate)
-
- fill_database(edb, packages, self.tempdir.name)
-
- for pkg in packages:
- package = package_db.Package('app-emacs',
- pkg[0],
- '.'.join(map(str, pkg[1])))
- description = edb.get_package_description(package)
- 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])
-
- 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 depend)
- for d in depend:
- self.assertTrue(d in ds)
-
-
-def suite():
- suite = unittest.TestSuite()
- suite.addTest(TestElpaDB('test_generate'))
- return suite
diff --git a/tests/test_elpa_metadata.py b/tests/test_elpa_metadata.py
deleted file mode 100644
index 8144999..0000000
--- a/tests/test_elpa_metadata.py
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
- test_elpa_metadata.py
- ~~~~~~~~~~~~~~~~~~~~~
-
- ELPA metadata 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, metadata
-
-from g_elpa import elpa_db
-
-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)
- metadata_generator = metadata.MetadataGenerator(edb)
- mdxml = metadata_generator.generate(package_db.Package('app-emacs', 'ack', '1.2'))
- self.assertEqual(mdxml,
- ['<?xml version="1.0" encoding="utf-8"?>',
- '<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">',
- '<pkgmetadata>',
- '\t<maintainer>',
- '\t\t<email>piatlicki@gmail.com</email>',
- '\t\t<name>Jauhien Piatlicki</name>',
- '\t</maintainer>',
- '\t<longdescription>Interface to ack-like source code search tools</longdescription>',
- '</pkgmetadata>'])
-
-
-def suite():
- suite = unittest.TestSuite()
- suite.addTest(TestElpaEbuildGenerator('test_generate'))
- return suite
diff --git a/tests/test_fileutils.py b/tests/test_fileutils.py
deleted file mode 100644
index 4a67712..0000000
--- a/tests/test_fileutils.py
+++ /dev/null
@@ -1,119 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
- fileutils.py
- ~~~~~~~~~~~~
-
- file utilities test suite
-
- :copyright: (c) 2013 by Jauhien Piatlicki
- :license: GPL-2, see LICENSE for more details.
-"""
-
-import json, os, shutil, tempfile, unittest
-
-from g_sorcery import exceptions, fileutils
-
-from tests.base import BaseTest
-
-class TestFileJSON(BaseTest):
-
- def setUp(self):
- super(TestFileJSON, self).setUp()
- self.path = os.path.join(self.tempdir.name, 'tst')
- self.name = 'tst.json'
-
- def do_test_read_ok(self, mandatories, value_suffix=""):
- f = fileutils.FileJSON(self.path, self.name, mandatories)
- content = f.read()
- for key in mandatories:
- self.assertTrue(key in content)
- if value_suffix:
- value = key + value_suffix
- else:
- value = ""
- self.assertEqual(content[key], value)
- self.assertTrue(os.path.isfile(os.path.join(self.path, self.name)))
- with open(os.path.join(self.path, self.name), 'r') as f:
- content_f = json.load(f)
- self.assertEqual(content, content_f)
-
- def test_read_dir_does_not_exist(self):
- mandatories = ['tst1', 'tst2', 'tst3']
- self.do_test_read_ok(mandatories)
-
- def test_read_file_does_not_exist(self):
- os.makedirs(self.path)
- mandatories = ['tst1', 'tst2', 'tst3']
- self.do_test_read_ok(mandatories)
-
- def test_read_all_keys(self):
- os.makedirs(self.path)
- mandatories = ['tst1', 'tst2', 'tst3']
- content = {}
- for key in mandatories:
- content[key] = key + "_v"
- with open(os.path.join(self.path, self.name), 'w') as f:
- json.dump(content, f)
- self.do_test_read_ok(mandatories, "_v")
-
- def test_read_missing_keys(self):
- os.makedirs(self.path)
- mandatories = ['tst1', 'tst2', 'tst3']
- content = {}
- for key in mandatories:
- content[key] = key + "_v"
- with open(os.path.join(self.path, self.name), 'w') as f:
- json.dump(content, f)
- f = fileutils.FileJSON(self.path, self.name, mandatories)
- mandatories.append("tst4")
- self.assertRaises(exceptions.FileJSONError, f.read)
-
- def do_test_write_ok(self):
- mandatories = ['tst1', 'tst2', 'tst3']
- content = {}
- for key in mandatories:
- content[key] = key + '_v'
- f = fileutils.FileJSON(self.path, self.name, mandatories)
- f.write(content)
- self.assertTrue(os.path.isfile(os.path.join(self.path, self.name)))
- with open(os.path.join(self.path, self.name), 'r') as f:
- content_f = json.load(f)
- self.assertEqual(content, content_f)
-
- def test_write_missing_keys(self):
- content = {'tst1' : '', 'tst2' : ''}
- mandatories = ['tst1', 'tst2', 'tst3']
- f = fileutils.FileJSON(self.path, self.name, mandatories)
- self.assertRaises(exceptions.FileJSONError, f.write, content)
-
- def test_write_dir_does_not_exist(self):
- self.do_test_write_ok()
-
- def test_write_file_does_not_exist(self):
- os.makedirs(self.path)
- self.do_test_write_ok()
-
- def test_write_all_keys(self):
- os.makedirs(self.path)
- mandatories = ['tst11', 'tst12']
- content = {}
- for key in mandatories:
- content[key] = key + "_v"
- with open(os.path.join(self.path, self.name), 'w') as f:
- json.dump(content, f)
- self.do_test_write_ok()
-
-
-def suite():
- suite = unittest.TestSuite()
- suite.addTest(TestFileJSON('test_read_dir_does_not_exist'))
- suite.addTest(TestFileJSON('test_read_file_does_not_exist'))
- suite.addTest(TestFileJSON('test_read_all_keys'))
- suite.addTest(TestFileJSON('test_read_missing_keys'))
- suite.addTest(TestFileJSON('test_write_missing_keys'))
- suite.addTest(TestFileJSON('test_write_dir_does_not_exist'))
- suite.addTest(TestFileJSON('test_write_file_does_not_exist'))
- suite.addTest(TestFileJSON('test_write_all_keys'))
- return suite
diff --git a/tests/test_metadata.py b/tests/test_metadata.py
deleted file mode 100644
index 288d8b1..0000000
--- a/tests/test_metadata.py
+++ /dev/null
@@ -1,134 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
- test_metadata.py
- ~~~~~~~~~~~~~~~~
-
- metadata generator test suite
-
- :copyright: (c) 2013 by Jauhien Piatlicki
- :license: GPL-2, see LICENSE for more details.
-"""
-
-import xml.etree.ElementTree as ET
-
-import tempfile, unittest
-
-from g_sorcery import exceptions, metadata, package_db
-
-from tests.base import BaseTest
-
-def tostring(element):
- return ET.tostring(element, encoding='utf-8').decode('utf-8')
-
-class TestXMLGenerator(BaseTest):
-
- def test_generate(self):
- schema = [{'name' : 'desc',
- 'subtags' : [],
- 'multiple' : (False, ""),
- 'required' : True},
- {'name' : 'contact',
- 'multiple' : (False, ""),
- 'required' : False,
- 'subtags' : [
- {'name' : 'email',
- 'subtags' : [],
- 'multiple' : (False, ""),
- 'required' : True},
-
- {'name' : 'phone',
- 'subtags' : [],
- 'multiple' : (False, ""),
- 'required' : False},
- ]},
- {'name' : 'multiple',
- 'subtags' : [],
- 'multiple' : (True, ""),
- 'required' : False},
- {'name' : 'flag',
- 'subtags' : [],
- 'multiple' : (True, "name"),
- 'required' : False},
- ]
- xg = metadata.XMLGenerator('test_ext', schema)
- self.assertRaises(exceptions.XMLGeneratorError, xg.generate, {})
- tree = xg.generate({'desc' : 'test xml'})
- self.assertEqual(tostring(tree),
- '<test_ext><desc>test xml</desc></test_ext>')
- tree = xg.generate({'desc' : 'test xml',
- 'contact' : {'email' : 'test@example.com',
- 'phone' : '00-0'}})
- self.assertEqual(tostring(tree),
- '<test_ext><desc>test xml</desc><contact><email>test@example.com\
-</email><phone>00-0</phone></contact></test_ext>')
- tree = xg.generate({'desc' : 'test xml',
- 'multiple' : ['test1', 'test2', 'test3']})
- self.assertEqual(tostring(tree),
- '<test_ext><desc>test xml</desc><multiple>test1</multiple>\
-<multiple>test2</multiple><multiple>test3</multiple></test_ext>')
- tree = xg.generate({'desc' : 'test xml',
- 'flag' : [('flag1', 'test1'), ('flag2', 'test2')]})
- self.assertEqual(tostring(tree),
- '<test_ext><desc>test xml</desc><flag name="flag1">test1</flag>\
-<flag name="flag2">test2</flag></test_ext>')
-
-
-class DummyMetadataGenerator(metadata.MetadataGenerator):
- def __init__(self, db):
- super(DummyMetadataGenerator, self).__init__(db)
-
-package = package_db.Package("app-test", "test", "0.1")
-
-description = {'herd' : ['test'],
- 'maintainer' : [{'email' : 'test@example.com', 'name' : 'testor'}],
- 'longdescription' : 'test metadata',
- '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(DummyDB, self).__init__(directory, repo_uri, db_uri)
-
- def generate_tree(self):
- self.add_category("app-test")
- self.add_package(package, description)
-
-
-class TestMetadataGenerator(BaseTest):
-
- def test_process(self):
- mg = DummyMetadataGenerator(None)
- self.assertEqual(tostring(mg.process(None, description)),
- '<pkgmetadata><herd>test</herd><maintainer><email>test@example.com</email>\
-<name>testor</name></maintainer><longdescription>test metadata</longdescription><use>\
-<flag name="flag1">test flag1</flag><flag name="flag2">test flag2</flag></use>\
-<upstream><maintainer><name>TEST</name></maintainer><remote-id>001</remote-id></upstream></pkgmetadata>')
-
- def test_generate(self):
- db = DummyDB(self.tempdir.name)
- db.generate()
- mg = DummyMetadataGenerator(db)
- metadata = mg.generate(package)
- self.assertEqual(metadata, resulting_metadata)
-
-
-def suite():
- suite = unittest.TestSuite()
- suite.addTest(TestXMLGenerator('test_generate'))
- suite.addTest(TestMetadataGenerator('test_process'))
- suite.addTest(TestMetadataGenerator('test_generate'))
- return suite
diff --git a/tests/test_package_db.py b/tests/test_package_db.py
deleted file mode 100644
index b2d51a2..0000000
--- a/tests/test_package_db.py
+++ /dev/null
@@ -1,133 +0,0 @@
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-"""
- test_package_db.py
- ~~~~~~~~~~~~~~~~~~
-
- package database test suite
-
- :copyright: (c) 2013 by Jauhien Piatlicki
- :license: GPL-2, see LICENSE for more details.
-"""
-
-import json, os, shutil, tempfile, unittest
-
-from g_sorcery import package_db, exceptions
-
-from tests.server import Server
-
-from tests.base import BaseTest
-
-class DummyDB(package_db.PackageDB):
- def __init__(self, directory, packages):
- super(DummyDB, self).__init__(directory)
- self.packages = packages
-
- def generate_tree(self):
- for category in [x.category for x in self.packages]:
- self.add_category(category)
- for package in self.packages:
- self.add_package(package)
-
- def get_real_db_uri(self):
- print(self.db_uri)
- return self.db_uri + '/dummy.tar.gz'
-
-
-class TestDummyDB(BaseTest):
-
- def setUp(self):
- super(TestDummyDB, self).setUp()
- category1 = 'app-test'
- category2 = 'dev-test'
- self.packages = [package_db.Package(category1, 'test', '0.2'),
- package_db.Package(category1, 'tst', '0.1'),
- package_db.Package(category1, 'dummy', '1'),
- package_db.Package(category2, 'test', '0.1'),
- package_db.Package(category2, 'test', '0.2'),
- package_db.Package(category2, 'tst', '0.1')]
-
- def test_manifest(self):
- db = DummyDB(self.tempdir.name, self.packages)
- db.generate()
- self.assertEqual(db.check_manifest(), (True, []))
-
- def test_read(self):
- db = DummyDB(self.tempdir.name, self.packages)
- db.generate()
- db2 = DummyDB(self.tempdir.name, self.packages)
- db2.read()
- self.assertEqual(db.database, db2.database)
-
- def test_list_categories(self):
- db = DummyDB(self.tempdir.name, self.packages)
- db.generate()
- categories = list(set([x.category for x in self.packages]))
- self.assertEqual(categories, db.list_categories())
-
- def test_list_package_names(self):
- db = DummyDB(self.tempdir.name, self.packages)
- db.generate()
- categories = list(set([x.category for x in self.packages]))
- for category in categories:
- package_names = list(set([x.name for x in self.packages if x.category == category]))
- self.assertEqual(package_names.sort(), db.list_package_names(category).sort())
- self.assertRaises(exceptions.InvalidKeyError, db.list_package_names, 'no_such_category')
-
- def test_list_package_versions(self):
- db = DummyDB(self.tempdir.name, self.packages)
- db.generate()
- categories = list(set([x.category for x in self.packages]))
- for category in categories:
- package_names = list(set([x.name for x in self.packages if x.category == category]))
- for name in package_names:
- versions = [x.version for x in self.packages
- if x.category == category and x.name == name]
- self.assertEqual(versions.sort(), db.list_package_versions(category, name).sort())
- self.assertRaises(exceptions.InvalidKeyError, db.list_package_versions, 'no_such_category', 'a')
- self.assertRaises(exceptions.InvalidKeyError, db.list_package_versions,
- categories[0], 'no_such_package')
-
- def test_sync(self):
- src_db = DummyDB(os.path.join(self.tempdir.name, 'src_testdb'), self.packages)
- src_db.generate()
-
- prev = os.getcwd()
- os.chdir(self.tempdir.name)
- os.system('tar cvzf dummy.tar.gz src_testdb')
-
- server = Server()
- server.start()
-
- db = DummyDB(os.path.join(self.tempdir.name, 'testdb'), self.packages)
- db.sync(db_uri='127.0.0.1:8080')
-
- server.shutdown()
- server.join()
-
- os.chdir(prev)
-
- self.assertEqual(src_db.database, db.database)
-
- def test_sync_fail(self):
- 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()
- suite.addTest(TestDummyDB('test_manifest'))
- suite.addTest(TestDummyDB('test_read'))
- suite.addTest(TestDummyDB('test_list_categories'))
- suite.addTest(TestDummyDB('test_list_package_names'))
- 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
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-09-15 22:38 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-09-15 22:38 UTC (permalink / raw
To: gentoo-commits
commit: fe0840ffb8a3991164bb9aa68bf0a370e1b1e132
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Sun Sep 15 22:38:06 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Sun Sep 15 22:38:06 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=fe0840ff
tests/server: serve files from a given directory
---
tests/server.py | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/tests/server.py b/tests/server.py
index 41767fc..6cb16e6 100644
--- a/tests/server.py
+++ b/tests/server.py
@@ -11,6 +11,7 @@
:license: GPL-2, see LICENSE for more details.
"""
+import os
import threading
from g_sorcery.compatibility import py2k
@@ -22,12 +23,26 @@ else:
from http.server import HTTPServer
from http.server import SimpleHTTPRequestHandler
+def HTTPRequestHandlerGenerator(direct):
+
+ class HTTPRequestHandler(SimpleHTTPRequestHandler):
+ directory = direct
+
+ def __init__(self, request, client_address, server):
+ super(HTTPRequestHandler, self).__init__(request, client_address, server)
+
+ def translate_path(self, path):
+ return os.path.join(self.directory, path[1:])
+
+ return HTTPRequestHandler
+
+
class Server(threading.Thread):
- def __init__(self):
+ def __init__(self, directory):
super(Server, self).__init__()
HTTPServer.allow_reuse_address = True
server_address = ('127.0.0.1', 8080)
- self.httpd = HTTPServer(server_address, SimpleHTTPRequestHandler)
+ self.httpd = HTTPServer(server_address, HTTPRequestHandlerGenerator(directory))
def run(self):
self.httpd.serve_forever()
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-09-16 0:19 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-09-16 0:19 UTC (permalink / raw
To: gentoo-commits
commit: 48941f078effc854651ea5052eea7325343839b7
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Mon Sep 16 00:12:16 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Mon Sep 16 00:12:16 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=48941f07
tests/server: make server work with python2
---
tests/server.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tests/server.py b/tests/server.py
index 6cb16e6..5cb813f 100644
--- a/tests/server.py
+++ b/tests/server.py
@@ -25,7 +25,7 @@ else:
def HTTPRequestHandlerGenerator(direct):
- class HTTPRequestHandler(SimpleHTTPRequestHandler):
+ class HTTPRequestHandler(SimpleHTTPRequestHandler, object):
directory = direct
def __init__(self, request, client_address, server):
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-09-16 14:33 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-09-16 14:33 UTC (permalink / raw
To: gentoo-commits
commit: 8bd3da7ba41e520fb9be3a1f93785a1877fff7bf
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Mon Sep 16 14:32:59 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Mon Sep 16 14:32:59 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=8bd3da7b
tests/test_PackageDB: test database functionality
---
tests/test_PackageDB.py | 40 ++++++++++++++++++++++++++++++++++------
1 file changed, 34 insertions(+), 6 deletions(-)
diff --git a/tests/test_PackageDB.py b/tests/test_PackageDB.py
index 87cf3ea..373fa4b 100644
--- a/tests/test_PackageDB.py
+++ b/tests/test_PackageDB.py
@@ -16,7 +16,7 @@ import time
import unittest
from g_sorcery.compatibility import TemporaryDirectory
-from g_sorcery.exceptions import SyncError
+from g_sorcery.exceptions import IntegrityError, InvalidKeyError, SyncError
from g_sorcery.g_collections import Package
from g_sorcery.package_db import PackageDB
@@ -30,7 +30,7 @@ class TestDB(PackageDB):
class TestPackageDB(BaseTest):
-
+
def test_functionality(self):
orig_tempdir = TemporaryDirectory()
orig_path = os.path.join(orig_tempdir.name, "db")
@@ -39,11 +39,14 @@ class TestPackageDB(BaseTest):
orig_db.add_category("app-test1")
orig_db.add_category("app-test2")
ebuild_data = {"test1": "test1", "test2": "test2"}
- orig_db.add_package(Package("app-test1", "test", "1"), ebuild_data)
- orig_db.add_package(Package("app-test1", "test", "2"))
- orig_db.add_package(Package("app-test1", "test1", "1"), ebuild_data)
- orig_db.add_package(Package("app-test2", "test2", "1"), ebuild_data)
+ packages = [Package("app-test1", "test", "1"), Package("app-test1", "test", "2"),
+ Package("app-test1", "test1", "1"), Package("app-test2", "test2", "1")]
+ for package in packages:
+ orig_db.add_package(package, ebuild_data)
+
orig_db.write_and_manifest()
+ os.system("cd " + orig_tempdir.name + " && tar cvzf good.tar.gz db")
+ os.system("echo invalid >> " + orig_tempdir.name + "/db/app-test1/packages.json")
os.system("cd " + orig_tempdir.name + " && tar cvzf dummy.tar.gz db")
test_db = TestDB(self.tempdir.name)
@@ -51,9 +54,34 @@ class TestPackageDB(BaseTest):
srv = Server(orig_tempdir.name)
srv.start()
+ self.assertRaises(IntegrityError, test_db.sync, "127.0.0.1:8080")
+ os.system("cd " + orig_tempdir.name + " && mv good.tar.gz dummy.tar.gz")
test_db.sync("127.0.0.1:8080")
srv.shutdown()
srv.join()
+ test_db.read()
+ self.assertEqual(orig_db.database, test_db.database)
+ self.assertEqual(set(test_db.list_categories()), set(["app-test1", "app-test2"]))
+ self.assertTrue(test_db.in_category("app-test1", "test"))
+ self.assertFalse(test_db.in_category("app-test2", "test"))
+ self.assertRaises(InvalidKeyError, test_db.in_category, "app-test3", "test")
+ self.assertEqual(set(test_db.list_package_names("app-test1")), set(['test', 'test1']))
+ self.assertEqual(set(test_db.list_catpkg_names()),set(['app-test1/test', 'app-test1/test1', 'app-test2/test2']))
+ self.assertRaises(InvalidKeyError, test_db.list_package_versions, "invalid", "test")
+ self.assertRaises(InvalidKeyError, test_db.list_package_versions, "app-test1", "invalid")
+ self.assertEqual(set(test_db.list_package_versions("app-test1", "test")), set(['1', '2']))
+ self.assertEqual(set(test_db.list_all_packages()), set(packages))
+ self.assertEqual(test_db.get_package_description(packages[0]), ebuild_data)
+ self.assertRaises(KeyError, test_db.get_package_description, Package("invalid", "invalid", "1"))
+ self.assertEqual(test_db.get_max_version("app-test1", "test"), "2")
+ self.assertEqual(test_db.get_max_version("app-test1", "test1"), "1")
+ self.assertRaises(InvalidKeyError, test_db.get_max_version, "invalid", "invalid")
+ pkg_set = set(packages)
+ for package, data in test_db:
+ self.assertTrue(package in pkg_set)
+ self.assertEqual(data, ebuild_data)
+ pkg_set.remove(package)
+ self.assertTrue(not pkg_set)
def suite():
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-09-18 0:57 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-09-18 0:57 UTC (permalink / raw
To: gentoo-commits
commit: b3e47360bd5ccb871e0860c24220259d4fbb3da0
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Wed Sep 18 00:57:12 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Wed Sep 18 00:57:12 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=b3e47360
tests/test_DBGenerator: initial commit
---
tests/test_DBGenerator.py | 110 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 110 insertions(+)
diff --git a/tests/test_DBGenerator.py b/tests/test_DBGenerator.py
new file mode 100644
index 0000000..b5e40f8
--- /dev/null
+++ b/tests/test_DBGenerator.py
@@ -0,0 +1,110 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+ test_DBGenerator.py
+ ~~~~~~~~~~~~~~~~~~~
+
+ DBGenerator test suite
+
+ :copyright: (c) 2013 by Jauhien Piatlicki
+ :license: GPL-2, see LICENSE for more details.
+"""
+
+import os
+import unittest
+
+from g_sorcery.compatibility import TemporaryDirectory
+from g_sorcery.exceptions import InvalidKeyError
+from g_sorcery.g_collections import Package
+from g_sorcery.package_db import DBGenerator
+
+from tests.base import BaseTest
+from tests.server import Server
+
+
+class TestingDBGenerator(DBGenerator):
+ def get_download_uries(self, common_config, config):
+ return [config["repo_uri"] + "/repo.data"]
+
+ def parse_data(self, data_f):
+ content = data_f.read()
+ content = content.split("packages\n")
+ ebuild_data_lines = content[0].split("\n")
+ packages_lines = content[1].split("\n")
+ ebuild_data = {}
+ packages = []
+ for line in ebuild_data_lines:
+ if line:
+ data = line.split(" ")
+ ebuild_data[data[0]] = data[1]
+ for line in packages_lines:
+ if line:
+ data = line.split(" ")
+ packages.append(Package(data[0], data[1], data[2]))
+ return {"ebuild_data": ebuild_data, "packages": packages}
+
+
+ def process_data(self, pkg_db, data, common_config, config):
+ data = data["repo.data"]
+ ebuild_data = data["ebuild_data"]
+ for package in data["packages"]:
+ pkg_db.add_category(package.category)
+ pkg_db.add_package(package, ebuild_data)
+
+
+class TestDBGenerator(BaseTest):
+
+ def test_functionality(self):
+ db_generator = TestingDBGenerator()
+ common_config = {}
+ config = {"repo_uri": "127.0.0.1:8080"}
+
+ packages = [Package("app-test1", "test", "1"), Package("app-test1", "test", "2"),
+ Package("app-test1", "test1", "1"), Package("app-test2", "test2", "1")]
+ ebuild_data = {"test1": "test1", "test2": "test2"}
+
+ orig_tempdir = TemporaryDirectory()
+ with open(os.path.join(orig_tempdir.name, "repo.data"), "w") as f:
+ for key, value in ebuild_data.items():
+ f.write(key + " " + value + "\n")
+ f.write("packages\n")
+ for package in packages:
+ f.write(package.category + " " + package.name + " " + package.version + "\n")
+
+ srv = Server(orig_tempdir.name)
+ srv.start()
+
+ pkg_db = db_generator(self.tempdir.name, "test_repo",
+ common_config = common_config, config = config)
+
+ srv.shutdown()
+ srv.join()
+
+ self.assertEqual(set(pkg_db.list_categories()), set(["app-test1", "app-test2"]))
+ self.assertTrue(pkg_db.in_category("app-test1", "test"))
+ self.assertFalse(pkg_db.in_category("app-test2", "test"))
+ self.assertRaises(InvalidKeyError, pkg_db.in_category, "app-test3", "test")
+ self.assertEqual(set(pkg_db.list_package_names("app-test1")), set(['test', 'test1']))
+ self.assertEqual(set(pkg_db.list_catpkg_names()),set(['app-test1/test', 'app-test1/test1', 'app-test2/test2']))
+ self.assertRaises(InvalidKeyError, pkg_db.list_package_versions, "invalid", "test")
+ self.assertRaises(InvalidKeyError, pkg_db.list_package_versions, "app-test1", "invalid")
+ self.assertEqual(set(pkg_db.list_package_versions("app-test1", "test")), set(['1', '2']))
+ self.assertEqual(set(pkg_db.list_all_packages()), set(packages))
+ self.assertEqual(pkg_db.get_package_description(packages[0]), ebuild_data)
+ self.assertRaises(KeyError, pkg_db.get_package_description, Package("invalid", "invalid", "1"))
+ self.assertEqual(pkg_db.get_max_version("app-test1", "test"), "2")
+ self.assertEqual(pkg_db.get_max_version("app-test1", "test1"), "1")
+ self.assertRaises(InvalidKeyError, pkg_db.get_max_version, "invalid", "invalid")
+ pkg_set = set(packages)
+ for package, data in pkg_db:
+ self.assertTrue(package in pkg_set)
+ self.assertEqual(data, ebuild_data)
+ pkg_set.remove(package)
+ self.assertTrue(not pkg_set)
+
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(TestDBGenerator('test_functionality'))
+ return suite
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-09-18 22:09 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-09-18 22:09 UTC (permalink / raw
To: gentoo-commits
commit: 18f089354e83eae5c98d998894d0f6ca9dd5f981
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Wed Sep 18 20:11:14 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Wed Sep 18 20:11:14 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=18f08935
tests/test_DBGenerator
---
tests/test_DBGenerator.py | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/tests/test_DBGenerator.py b/tests/test_DBGenerator.py
index b5e40f8..9a47c86 100644
--- a/tests/test_DBGenerator.py
+++ b/tests/test_DBGenerator.py
@@ -52,6 +52,12 @@ class TestingDBGenerator(DBGenerator):
pkg_db.add_category(package.category)
pkg_db.add_package(package, ebuild_data)
+ def convert_internal_dependency(self, configs, dependency):
+ return ("internal", dependency)
+
+ def convert_external_dependency(self, configs, dependency):
+ return ("external", dependency)
+
class TestDBGenerator(BaseTest):
@@ -103,6 +109,19 @@ class TestDBGenerator(BaseTest):
pkg_set.remove(package)
self.assertTrue(not pkg_set)
+ orig = "test"
+ converted = "works"
+ internal = "int"
+ configs = [{}, {"converters": {orig:converted}, "external": {orig:converted}, "values": [orig, converted]}]
+
+ self.assertEqual(db_generator.convert(configs, "converters", orig), converted)
+ self.assertNotEqual(db_generator.convert(configs, "converters", "invalid"), converted)
+ self.assertEqual(db_generator.convert_dependency(configs, orig), ("external", converted))
+ self.assertEqual(db_generator.convert_dependency(configs, orig, external = False), None)
+ self.assertEqual(db_generator.convert_dependency(configs, internal), ("internal", internal))
+ self.assertTrue(db_generator.in_config(configs, "values", orig))
+ self.assertFalse(db_generator.in_config(configs, "values", "invalid"))
+
def suite():
suite = unittest.TestSuite()
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-09-18 22:09 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-09-18 22:09 UTC (permalink / raw
To: gentoo-commits
commit: 874f25ca6137c3365af32e5c8531960a883e647f
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Wed Sep 18 22:08:12 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Wed Sep 18 22:08:12 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=874f25ca
tests/test_metadata
---
tests/test_metadata.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/tests/test_metadata.py b/tests/test_metadata.py
new file mode 100644
index 0000000..60d7ea6
--- /dev/null
+++ b/tests/test_metadata.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+ test_metadata.py
+ ~~~~~~~~~~~~~~~~
+
+ metadata test suite
+
+ :copyright: (c) 2013 by Jauhien Piatlicki
+ :license: GPL-2, see LICENSE for more details.
+"""
+
+import os
+import unittest
+
+from g_sorcery.compatibility import TemporaryDirectory
+from g_sorcery.g_collections import Package
+from g_sorcery.metadata import MetadataGenerator
+from g_sorcery.package_db import PackageDB
+
+from tests.base import BaseTest
+
+
+class TestMetadataGenerator(BaseTest):
+
+ def test_metadata(self):
+ pkg_db = PackageDB(self.tempdir.name)
+ pkg_db.add_category("app-test")
+ ebuild_data = {"herd": ["testers", "crackers"],
+ 'maintainer': [{'email': 'test@example.com',
+ 'name': 'tux'}],
+ "longdescription": "very long description here",
+ "use": {"flag": {"use1": "testing use1", "use2": "testing use2"}}}
+ package = Package("app-test", "metadata_tester", "0.1")
+ pkg_db.add_package(package, ebuild_data)
+ metadata_g = MetadataGenerator(pkg_db)
+ metadata = metadata_g.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>testers</herd>', '\t<herd>crackers</herd>',
+ '\t<maintainer>', '\t\t<email>test@example.com</email>', '\t\t<name>tux</name>', '\t</maintainer>',
+ '\t<longdescription>very long description here</longdescription>',
+ '\t<use>', '\t\t<flag name="u">s</flag>', '\t\t<flag name="u">s</flag>', '\t</use>',
+ '</pkgmetadata>'])
+
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(TestMetadataGenerator('test_metadata'))
+ return suite
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-09-18 22:52 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-09-18 22:52 UTC (permalink / raw
To: gentoo-commits
commit: 8a2a0fa3e3fd7f3f7df5dea20d64d005f4521e50
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Wed Sep 18 22:35:45 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Wed Sep 18 22:35:45 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=8a2a0fa3
tests/test_ebuild
---
tests/test_ebuild.py | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 90 insertions(+)
diff --git a/tests/test_ebuild.py b/tests/test_ebuild.py
new file mode 100644
index 0000000..e227c97
--- /dev/null
+++ b/tests/test_ebuild.py
@@ -0,0 +1,90 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+ test_ebuild.py
+ ~~~~~~~~~~~~~~
+
+ ebuild test suite
+
+ :copyright: (c) 2013 by Jauhien Piatlicki
+ :license: GPL-2, see LICENSE for more details.
+"""
+
+import collections
+import os
+import unittest
+
+from g_sorcery.compatibility import TemporaryDirectory
+from g_sorcery.g_collections import Package
+from g_sorcery.ebuild import EbuildGeneratorFromFile, DefaultEbuildGenerator
+from g_sorcery.package_db import PackageDB
+
+from tests.base import BaseTest
+
+
+Layout = collections.namedtuple("Layout",
+ ["vars_before_inherit", "inherit",
+ "vars_after_description", "vars_after_keywords"])
+
+class TestEbuildGenerator(BaseTest):
+
+ ebuild_data = {"herd": ["testers", "crackers"],
+ 'maintainer': [{'email': 'test@example.com',
+ 'name': 'tux'}],
+ "longdescription": "very long description here",
+ "use": {"flag": {"use1": "testing use1", "use2": "testing use2"}},
+ "homepage": "example.com",
+ "description": "testing ebuild",
+ "array": "(a b c d)"}
+ package = Package("app-test", "metadata_tester", "0.1")
+
+ def setUp(self):
+ super(TestEbuildGenerator, self).setUp()
+ self.pkg_db = PackageDB(self.tempdir.name)
+ self.pkg_db.add_category("app-test")
+ self.pkg_db.add_package(self.package, self.ebuild_data)
+
+ def test_ebuild_generator_from_file(self):
+ template = os.path.join(self.tempdir.name, "test.tmpl")
+ os.system("echo 'TEST_SUBST=%(array)s' > " + template)
+
+ ebuild_g = EbuildGeneratorFromFile(self.pkg_db, template)
+ ebuild = ebuild_g.generate(self.package)
+ self.assertEqual(ebuild, ['TEST_SUBST=(a b c d)'])
+
+ def test_default_ebuild_generator(self):
+ vars_before_inherit = \
+ [{"name":"test_raw_value", "value":"raw_value", "raw":True},
+ {"name":"test_value", "value":"value"}]
+
+ inherit = ["g-test"]
+
+ vars_after_description = \
+ ["homepage"]
+
+ vars_after_keywords = \
+ [{"name":"array"},
+ {"name":"array", "raw":True}]
+
+ layout = Layout(vars_before_inherit,
+ inherit, vars_after_description, vars_after_keywords)
+
+ ebuild_g = DefaultEbuildGenerator(self.pkg_db, layout)
+ ebuild = ebuild_g.generate(self.package)
+ self.assertEqual(ebuild, ['# automatically generated by g-sorcery',
+ '# please do not edit this file', '',
+ 'EAPI=5', '',
+ 'TEST_RAW_VALUE=raw_value', 'TEST_VALUE="value"', '',
+ 'inherit g-test', '',
+ 'DESCRIPTION="testing ebuild"', '',
+ 'HOMEPAGE="example.com"', '',
+ 'SLOT="0"', 'KEYWORDS="~amd64 ~x86"', '',
+ 'ARRAY="(a b c d)"', 'ARRAY=(a b c d)', ''])
+
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(TestEbuildGenerator('test_ebuild_generator_from_file'))
+ suite.addTest(TestEbuildGenerator('test_default_ebuild_generator'))
+ return suite
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2013-09-18 22:52 Jauhien Piatlicki
0 siblings, 0 replies; 20+ messages in thread
From: Jauhien Piatlicki @ 2013-09-18 22:52 UTC (permalink / raw
To: gentoo-commits
commit: f83eb1302ee08056a8aa8db6e611b379642043e6
Author: Jauhien Piatlicki (jauhien) <piatlicki <AT> gmail <DOT> com>
AuthorDate: Wed Sep 18 22:47:24 2013 +0000
Commit: Jauhien Piatlicki <piatlicki <AT> gmail <DOT> com>
CommitDate: Wed Sep 18 22:47:24 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/g-sorcery.git;a=commit;h=f83eb130
tests/test_eclass
---
tests/test_eclass.py | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/tests/test_eclass.py b/tests/test_eclass.py
new file mode 100644
index 0000000..f336fcb
--- /dev/null
+++ b/tests/test_eclass.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+ test_eclass.py
+ ~~~~~~~~~~~~~~
+
+ eclass test suite
+
+ :copyright: (c) 2013 by Jauhien Piatlicki
+ :license: GPL-2, see LICENSE for more details.
+"""
+
+import os
+import unittest
+
+from g_sorcery.eclass import EclassGenerator
+
+from tests.base import BaseTest
+
+
+class TestEclassGenerator(BaseTest):
+
+ def test_eclass_generator(self):
+ eclasses = ["test1", "test2"]
+ for eclass in eclasses:
+ os.system("echo 'eclass " + eclass + "' > " + os.path.join(self.tempdir.name, eclass + ".eclass"))
+
+ eclass_g = EclassGenerator(self.tempdir.name)
+ self.assertEqual(set(eclass_g.list()), set(eclasses) | set(["g-sorcery"]))
+
+ for eclass in eclasses:
+ self.assertEqual(eclass_g.generate(eclass), ["eclass " + eclass])
+
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(TestEclassGenerator('test_eclass_generator'))
+ return suite
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2021-05-04 15:50 Ulrich Müller
0 siblings, 0 replies; 20+ messages in thread
From: Ulrich Müller @ 2021-05-04 15:50 UTC (permalink / raw
To: gentoo-commits
commit: 20fe069692a9818c41059c3ebcfef3dce39c258e
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Thu Apr 23 17:39:09 2020 +0000
Commit: Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Tue May 4 15:48:08 2021 +0000
URL: https://gitweb.gentoo.org/proj/g-sorcery.git/commit/?id=20fe0696
tests/server/py: Fix an inheritence error in py 3.7, 3.8
self.directory was being overridden by the super class instance.
Rename this local variable to prevent it being overridden.
Signed-off-by: Brian Dolbec <dolsen <AT> gentoo.org>
Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org>
tests/server.py | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/tests/server.py b/tests/server.py
index 6a32a2d..aa895ea 100644
--- a/tests/server.py
+++ b/tests/server.py
@@ -4,9 +4,9 @@
"""
server.py
~~~~~~~~~
-
+
test server
-
+
:copyright: (c) 2013 by Jauhien Piatlicki
:license: GPL-2, see LICENSE for more details.
"""
@@ -18,7 +18,7 @@ import time
from g_sorcery.compatibility import py2k
if py2k:
- from SocketServer import TCPServer as HTTPServer
+ from SocketServer import TCPServer as HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
else:
from http.server import HTTPServer
@@ -27,24 +27,24 @@ else:
def HTTPRequestHandlerGenerator(direct):
class HTTPRequestHandler(SimpleHTTPRequestHandler, object):
- directory = direct
def __init__(self, request, client_address, server):
+ self.direct = direct
super(HTTPRequestHandler, self).__init__(request, client_address, server)
def translate_path(self, path):
- return os.path.join(self.directory, path[1:])
+ return os.path.join(self.direct, path[1:])
return HTTPRequestHandler
-
+
class Server(threading.Thread):
def __init__(self, directory, port=8080):
super(Server, self).__init__()
HTTPServer.allow_reuse_address = True
server_address = ('127.0.0.1', port)
self.httpd = HTTPServer(server_address, HTTPRequestHandlerGenerator(directory))
-
+
def run(self):
self.httpd.serve_forever()
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2021-05-04 15:50 Ulrich Müller
0 siblings, 0 replies; 20+ messages in thread
From: Ulrich Müller @ 2021-05-04 15:50 UTC (permalink / raw
To: gentoo-commits
commit: 5a2f2b831f4190e74ccd2b6be263370d02fca56a
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Thu Apr 23 17:28:31 2020 +0000
Commit: Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Tue May 4 15:48:07 2021 +0000
URL: https://gitweb.gentoo.org/proj/g-sorcery.git/commit/?id=5a2f2b83
tests/server.py: Add time.sleep() delay after shutdown
This is to help prevent a possible threading lock error if
traceback errors are raised.
I was experiencing this fault while debugging python 3.7 and 3.8 test
errors. It prevented the sys.exit() at the end of the tests.
Signed-off-by: Brian Dolbec <dolsen <AT> gentoo.org>
Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org>
tests/server.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tests/server.py b/tests/server.py
index 51d49b7..6a32a2d 100644
--- a/tests/server.py
+++ b/tests/server.py
@@ -13,6 +13,7 @@
import os
import threading
+import time
from g_sorcery.compatibility import py2k
@@ -49,3 +50,4 @@ class Server(threading.Thread):
def shutdown(self):
self.httpd.shutdown()
+ time.sleep(0.5)
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [gentoo-commits] proj/g-sorcery:master commit in: tests/
@ 2021-05-04 15:50 Ulrich Müller
0 siblings, 0 replies; 20+ messages in thread
From: Ulrich Müller @ 2021-05-04 15:50 UTC (permalink / raw
To: gentoo-commits
commit: d3e5cf43918fd6134ce258683a757d4f9778917b
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Thu Apr 23 17:35:30 2020 +0000
Commit: Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Tue May 4 15:48:08 2021 +0000
URL: https://gitweb.gentoo.org/proj/g-sorcery.git/commit/?id=d3e5cf43
test_DBGenerator.py, test_PackageDB.py: Fix test errors
The http server was not being shutdown when exceptions were raised
This caused other errors in tests run after the failed test.
Signed-off-by: Brian Dolbec <dolsen <AT> gentoo.org>
Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org>
tests/test_DBGenerator.py | 12 +++++++-----
tests/test_PackageDB.py | 12 +++++++-----
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/tests/test_DBGenerator.py b/tests/test_DBGenerator.py
index 9a47c86..3c28278 100644
--- a/tests/test_DBGenerator.py
+++ b/tests/test_DBGenerator.py
@@ -4,9 +4,9 @@
"""
test_DBGenerator.py
~~~~~~~~~~~~~~~~~~~
-
+
DBGenerator test suite
-
+
:copyright: (c) 2013 by Jauhien Piatlicki
:license: GPL-2, see LICENSE for more details.
"""
@@ -81,11 +81,13 @@ class TestDBGenerator(BaseTest):
srv = Server(orig_tempdir.name)
srv.start()
- pkg_db = db_generator(self.tempdir.name, "test_repo",
+ try:
+ pkg_db = db_generator(self.tempdir.name, "test_repo",
common_config = common_config, config = config)
- srv.shutdown()
- srv.join()
+ finally:
+ srv.shutdown()
+ srv.join()
self.assertEqual(set(pkg_db.list_categories()), set(["app-test1", "app-test2"]))
self.assertTrue(pkg_db.in_category("app-test1", "test"))
diff --git a/tests/test_PackageDB.py b/tests/test_PackageDB.py
index 152c605..8be8f8a 100644
--- a/tests/test_PackageDB.py
+++ b/tests/test_PackageDB.py
@@ -70,11 +70,13 @@ class TestPackageDB(BaseTest):
srv = Server(orig_tempdir.name, port=port)
srv.start()
- self.assertRaises(IntegrityError, test_db.sync, sync_address)
- os.system("cd " + orig_tempdir.name + " && mv good.tar.gz dummy.tar.gz")
- test_db.sync(sync_address)
- srv.shutdown()
- srv.join()
+ try:
+ self.assertRaises(IntegrityError, test_db.sync, sync_address)
+ os.system("cd " + orig_tempdir.name + " && mv good.tar.gz dummy.tar.gz")
+ test_db.sync(sync_address)
+ finally:
+ srv.shutdown()
+ srv.join()
test_db.read()
self.assertEqual(orig_db.database, test_db.database)
self.assertEqual(orig_db.get_common_data("app-test1"), test_db.get_common_data("app-test1"))
^ permalink raw reply related [flat|nested] 20+ messages in thread
end of thread, other threads:[~2021-05-04 15:50 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-16 0:19 [gentoo-commits] proj/g-sorcery:master commit in: tests/ Jauhien Piatlicki
-- strict thread matches above, loose matches on Subject: below --
2021-05-04 15:50 Ulrich Müller
2021-05-04 15:50 Ulrich Müller
2021-05-04 15:50 Ulrich Müller
2013-09-18 22:52 Jauhien Piatlicki
2013-09-18 22:52 Jauhien Piatlicki
2013-09-18 22:09 Jauhien Piatlicki
2013-09-18 22:09 Jauhien Piatlicki
2013-09-18 0:57 Jauhien Piatlicki
2013-09-16 14:33 Jauhien Piatlicki
2013-09-15 22:38 Jauhien Piatlicki
2013-09-15 22:38 Jauhien Piatlicki
2013-09-15 22:38 Jauhien Piatlicki
2013-07-17 15:41 Jauhien Piatlicki
2013-07-14 23:39 Jauhien Piatlicki
2013-07-08 23:53 Jauhien Piatlicki
2013-07-02 14:48 Jauhien Piatlicki
2013-07-02 10:21 Jauhien Piatlicki
2013-06-23 0:44 Jauhien Piatlicki
2013-06-23 0:44 Jauhien Piatlicki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox