diff options
author | 2013-07-02 14:26:25 +0200 | |
---|---|---|
committer | 2013-07-02 14:26:25 +0200 | |
commit | 7c3f2ef461e92ef610ea835997c21921a8b4d05f (patch) | |
tree | e06e3a823c6320f62fae9c326a538b2bf98bdd8f /tests | |
parent | g_elpa/elpa_db: add_category to higher level (diff) | |
download | g-sorcery-7c3f2ef461e92ef610ea835997c21921a8b4d05f.tar.gz g-sorcery-7c3f2ef461e92ef610ea835997c21921a8b4d05f.tar.bz2 g-sorcery-7c3f2ef461e92ef610ea835997c21921a8b4d05f.zip |
base class for tests and initial commit for py2 compatibility module
Diffstat (limited to 'tests')
-rw-r--r-- | tests/base.py | 24 | ||||
-rw-r--r-- | tests/test_backend.py | 10 | ||||
-rw-r--r-- | tests/test_dummy.py | 7 | ||||
-rw-r--r-- | tests/test_ebuild.py | 18 | ||||
-rw-r--r-- | tests/test_elpa_db.py | 7 | ||||
-rw-r--r-- | tests/test_fileutils.py | 8 | ||||
-rw-r--r-- | tests/test_g_sorcery.py | 16 | ||||
-rw-r--r-- | tests/test_metadata.py | 14 | ||||
-rw-r--r-- | tests/test_package_db.py | 8 |
9 files changed, 52 insertions, 60 deletions
diff --git a/tests/base.py b/tests/base.py new file mode 100644 index 0000000..0c3270a --- /dev/null +++ b/tests/base.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" + base.py + ~~~~~~~ + + base class for tests + + :copyright: (c) 2013 by Jauhien Piatlicki + :license: GPL-2, see LICENSE for more details. +""" + +import unittest + +from g_sorcery.compatibility import TemporaryDirectory + +class BaseTest(unittest.TestCase): + + def setUp(self): + self.tempdir = TemporaryDirectory() + + def tearDown(self): + del self.tempdir diff --git a/tests/test_backend.py b/tests/test_backend.py index 65e136d..2c28f79 100644 --- a/tests/test_backend.py +++ b/tests/test_backend.py @@ -17,6 +17,8 @@ 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=""): @@ -24,14 +26,8 @@ class DummyBackend(backend.Backend): sync_db=sync_db, eclass_dir=eclass_dir) -class TestBackend(unittest.TestCase): +class TestBackend(BaseTest): - def setUp(self): - self.tempdir = tempfile.TemporaryDirectory() - - def tearDown(self): - del self.tempdir - def test_list_eclasses(self): backend = DummyBackend(package_db.PackageDB, ebuild.EbuildGenerator, metadata.MetadataGenerator, diff --git a/tests/test_dummy.py b/tests/test_dummy.py index dfa9700..58df716 100644 --- a/tests/test_dummy.py +++ b/tests/test_dummy.py @@ -13,10 +13,9 @@ import unittest -class TestDummy(unittest.TestCase): - - def setUp(self): - pass +from tests.base import BaseTest + +class TestDummy(BaseTest): def test_dummy(self): self.assertEqual('works', 'works') diff --git a/tests/test_ebuild.py b/tests/test_ebuild.py index 52c34f5..8e7aca4 100644 --- a/tests/test_ebuild.py +++ b/tests/test_ebuild.py @@ -15,6 +15,8 @@ import os, tempfile, unittest from g_sorcery import ebuild, package_db +from tests.base import BaseTest + package = package_db.Package("app-test", "test", "0.1") package2 = package_db.Package("app-test", "tst", "1") @@ -36,13 +38,7 @@ class DummyEbuildGenerator(ebuild.EbuildGenerator): return tmpl -class TestEbuildGenerator(unittest.TestCase): - - def setUp(self): - self.tempdir = tempfile.TemporaryDirectory() - - def tearDown(self): - del self.tempdir +class TestEbuildGenerator(BaseTest): def test_process(self): eg = DummyEbuildGenerator(None) @@ -69,13 +65,7 @@ class DummyEbuildGeneratorFromFile(ebuild.EbuildGeneratorFromFile): return self.path -class TestEbuildGeneratorFromFile(unittest.TestCase): - - def setUp(self): - self.tempdir = tempfile.TemporaryDirectory() - - def tearDown(self): - del self.tempdir +class TestEbuildGeneratorFromFile(BaseTest): def test_generate(self): db = DummyDB(os.path.join(self.tempdir.name, 'tstdb')) diff --git a/tests/test_elpa_db.py b/tests/test_elpa_db.py index 97ce4e2..874ee96 100644 --- a/tests/test_elpa_db.py +++ b/tests/test_elpa_db.py @@ -19,12 +19,9 @@ from g_sorcery import exceptions, package_db from tests.server import Server -class TestElpaDB(unittest.TestCase): - def setUp(self): - self.tempdir = tempfile.TemporaryDirectory() +from tests.base import BaseTest - def tearDown(self): - del self.tempdir +class TestElpaDB(BaseTest): def test_generate(self): prev = os.getcwd() diff --git a/tests/test_fileutils.py b/tests/test_fileutils.py index 1760444..1e3ab1f 100644 --- a/tests/test_fileutils.py +++ b/tests/test_fileutils.py @@ -15,17 +15,15 @@ import json, os, shutil, tempfile, unittest from g_sorcery import exceptions, fileutils +from tests.base import BaseTest -class TestFileJSON(unittest.TestCase): +class TestFileJSON(BaseTest): def setUp(self): - self.tempdir = tempfile.TemporaryDirectory() + super().setUp() self.path = os.path.join(self.tempdir.name, 'tst') self.name = 'tst.json' - def tearDown(self): - del self.tempdir - def do_test_read_ok(self, mandatories, value_suffix=""): f = fileutils.FileJSON(self.path, self.name, mandatories) content = f.read() diff --git a/tests/test_g_sorcery.py b/tests/test_g_sorcery.py index 4b18474..bc91e97 100644 --- a/tests/test_g_sorcery.py +++ b/tests/test_g_sorcery.py @@ -17,17 +17,16 @@ from g_sorcery import g_sorcery from tests.dummy_backend import backend as dummyBackend -class TestBin(unittest.TestCase): +from tests.base import BaseTest + +class TestBin(BaseTest): def setUp(self): - self.tempdir = tempfile.TemporaryDirectory() + super().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 tearDown(self): - del self.tempdir - def test_g_sorcery(self): self.assertEqual(subprocess.check_output(self.binary), b'g-sorcery\n') @@ -55,12 +54,7 @@ class TestBin(unittest.TestCase): dummyBackend.instance.test()) os.chdir(prev) -class TestGSorcery(unittest.TestCase): - def setUp(self): - self.tempdir = tempfile.TemporaryDirectory() - - def tearDown(self): - del self.tempdir +class TestGSorcery(BaseTest): def test_get_backend(self): self.assertEqual(g_sorcery.get_backend('nonexistent_backend'), None) diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 9bb1f43..4906541 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -17,12 +17,9 @@ import tempfile, unittest from g_sorcery import exceptions, metadata, package_db -class TestXMLGenerator(unittest.TestCase): - def setUp(self): - pass +from tests.base import BaseTest - def tearDown(self): - pass +class TestXMLGenerator(BaseTest): def test_generate(self): schema = [{'name' : 'desc', @@ -108,12 +105,7 @@ class DummyDB(package_db.PackageDB): self.add_package(package, description) -class TestMetadataGenerator(unittest.TestCase): - def setUp(self): - self.tempdir = tempfile.TemporaryDirectory() - - def tearDown(self): - del self.tempdir +class TestMetadataGenerator(BaseTest): def test_process(self): mg = DummyMetadataGenerator(None) diff --git a/tests/test_package_db.py b/tests/test_package_db.py index 1433eb7..6b1004e 100644 --- a/tests/test_package_db.py +++ b/tests/test_package_db.py @@ -17,6 +17,8 @@ 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().__init__(directory) @@ -33,10 +35,10 @@ class DummyDB(package_db.PackageDB): return self.db_uri + '/dummy.tar.gz' -class TestDummyDB(unittest.TestCase): +class TestDummyDB(BaseTest): def setUp(self): - self.tempdir = tempfile.TemporaryDirectory() + super().setUp() category1 = 'app-test' category2 = 'dev-test' self.packages = [package_db.Package(category1, 'test', '0.2'), @@ -47,7 +49,7 @@ class TestDummyDB(unittest.TestCase): package_db.Package(category2, 'tst', '0.1')] def tearDown(self): - del self.tempdir + super().tearDown() def test_manifest(self): db = DummyDB(self.tempdir.name, self.packages) |