diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2010-12-09 23:22:27 -0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2010-12-09 23:22:27 -0200 |
commit | d0c6e156e471287ae0aa33150b01bba60362db57 (patch) | |
tree | b53b7b8b9e58412356ab6b954010e912afb1c497 /tests | |
parent | small fixes on the log class and some minor typos (diff) | |
download | g-octave-d0c6e156e471287ae0aa33150b01bba60362db57.tar.gz g-octave-d0c6e156e471287ae0aa33150b01bba60362db57.tar.bz2 g-octave-d0c6e156e471287ae0aa33150b01bba60362db57.zip |
fixed a bunch of tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/files/DESCRIPTION | 4 | ||||
-rw-r--r-- | tests/files/manifest.json | 11 | ||||
-rw-r--r-- | tests/test_checksum.py | 16 | ||||
-rw-r--r-- | tests/test_description.py | 22 | ||||
-rw-r--r-- | tests/test_description_tree.py | 14 | ||||
-rw-r--r-- | tests/test_ebuild.py | 18 | ||||
-rw-r--r-- | tests/test_overlay.py | 12 | ||||
-rw-r--r-- | tests/testcase.py | 34 | ||||
-rw-r--r-- | tests/utils.py | 55 |
9 files changed, 80 insertions, 106 deletions
diff --git a/tests/files/DESCRIPTION b/tests/files/DESCRIPTION index cfc9104..d02ceea 100644 --- a/tests/files/DESCRIPTION +++ b/tests/files/DESCRIPTION @@ -15,8 +15,8 @@ Description: Lorem ipsum dolor sit amet, consectetur adipisicing elit, mollit anim id est laborum. Categories: Category1,Category2, Category3 Url: http://example.org -SystemRequirements: pkg1 ( >= 4.3.2), pkg2 (<1.2.3 ), pkg3 -BuildRequires: pkg4 (>1.0.0) +SystemRequirements: pkg11 ( >= 4.3.2), pkg12 (<1.2.3 ), pkg13 +BuildRequires: pkg14 (>1.0.0) Depends: Octave ( >= 3.0.0 ) Autoload: NO License: GPL version 3 or later diff --git a/tests/files/manifest.json b/tests/files/manifest.json new file mode 100644 index 0000000..1d14b43 --- /dev/null +++ b/tests/files/manifest.json @@ -0,0 +1,11 @@ +{ + "extra2-0.0.1": "c2a29cf7dfa0394dc8f490d0d6b5b39434d6f078", + "extra2-0.0.2": "910739744eaeeb2e51cc98d6c1828085d651c4c8", + "extra1-0.0.1": "54ae28a2bb8669684a4497940abe2862e3fcf638", + "language1-0.0.1": "7ff62ff7c852ea5d099d5baaa224a19ba0093029", + "language2-0.0.2": "273dd20b59fe6532ea6a0f4a07b5491da2c40f04", + "language2-0.0.1": "0f1a86d309a54b90949006d6cf2db763a1d9278e", + "main1-0.0.1": "18b9694a20f852ac4011e05f9ee1308c07e9ba0a", + "main2-0.0.2": "95b757747bd71d3d8e4e3cda328d62ddb739b835", + "main2-0.0.1": "8579145e5972c2a2af886f475938624b9c161dbe" +} diff --git a/tests/test_checksum.py b/tests/test_checksum.py index 66cd96b..b8f0453 100644 --- a/tests/test_checksum.py +++ b/tests/test_checksum.py @@ -14,27 +14,33 @@ import os import tempfile import unittest +import testcase -from g_octave import checksum +from g_octave import checksum, description_tree -class TestChecksum(unittest.TestCase): +class TestChecksum(testcase.TestCase): def setUp(self): + testcase.TestCase.setUp(self) self._tempfile = tempfile.mkstemp()[1] with open(self._tempfile, 'w') as fp: # SHA1 checksum: 8aa49f56d049193b183cb2918f8fb59e0caf1283 fp.write("I'm the walrus\n") - def test_checksum(self): + def test_filechecksum(self): my_checksum = checksum.sha1_compute(self._tempfile) self.assertEqual(my_checksum, '8aa49f56d049193b183cb2918f8fb59e0caf1283') - self.assertTrue(checksum.sha1_check(self._tempfile, my_checksum)) + + def test_dbchecksum(self): + self.assertTrue(checksum.sha1_check_db(description_tree.DescriptionTree())) def tearDown(self): + testcase.TestCase.tearDown(self) os.unlink(self._tempfile) def suite(): suite = unittest.TestSuite() - suite.addTest(TestChecksum('test_checksum')) + suite.addTest(TestChecksum('test_filechecksum')) + suite.addTest(TestChecksum('test_dbchecksum')) return suite diff --git a/tests/test_description.py b/tests/test_description.py index 57f933b..dc31431 100644 --- a/tests/test_description.py +++ b/tests/test_description.py @@ -13,20 +13,19 @@ import os import unittest -import utils +import testcase from g_octave import description -class TestDescription(unittest.TestCase): +class TestDescription(testcase.TestCase): def setUp(self): - conf, self._config_file, self._tempdir = utils.create_env() + testcase.TestCase.setUp(self) self.desc = description.Description( os.path.join( os.path.dirname(os.path.abspath(__file__)), 'files', 'DESCRIPTION', ), - conf = conf ) def test_re_depends(self): @@ -187,22 +186,17 @@ class TestDescription(unittest.TestCase): self.assertEqual(self.desc.url, 'http://example.org') requirements = [ - '>=g-octave/pkg1-4.3.2', - '<g-octave/pkg2-1.2.3', - 'g-octave/pkg3' + '<g-octave/pkg12-1.2.3', + 'g-octave/pkg13', + '>=g-octave/pkg11-4.3.2', ] - requirements.sort() self.assertEqual(self.desc.systemrequirements, requirements) - self.assertEqual(self.desc.buildrequires, ['>g-octave/pkg4-1.0.0']) + self.assertEqual(self.desc.buildrequires, ['>g-octave/pkg14-1.0.0']) self.assertEqual(self.desc.depends, ['>=sci-mathematics/octave-3.0.0']) self.assertEqual(self.desc.autoload, 'NO') self.assertEqual(self.desc.license, 'GPL version 3 or later') - self.assertEqual(self.desc.sha1sum(), '6538f6e7cd4515ef38e04a9b62da4bebb7496b51') - - def tearDown(self): - # removing the temp tree - utils.clean_env(self._config_file, self._tempdir) + self.assertEqual(self.desc.sha1sum(), '6d1559b50a09189e5d25b402a004d12cafc8ee4f') def suite(): diff --git a/tests/test_description_tree.py b/tests/test_description_tree.py index 7e9f527..da194f3 100644 --- a/tests/test_description_tree.py +++ b/tests/test_description_tree.py @@ -14,16 +14,16 @@ import os import shutil import unittest -import utils +import testcase from g_octave import description, description_tree -class TestDescriptionTree(unittest.TestCase): +class TestDescriptionTree(testcase.TestCase): def setUp(self): - conf, self._config_file, self._tempdir = utils.create_env() - self._tree = description_tree.DescriptionTree(conf = conf) + testcase.TestCase.setUp(self) + self._tree = description_tree.DescriptionTree() def test_package_versions(self): versions = { @@ -93,11 +93,7 @@ class TestDescriptionTree(unittest.TestCase): self._tree[pkg+'-'+ver], description.Description ) - ) - - def tearDown(self): - # removing the temp tree - utils.clean_env(self._config_file, self._tempdir) + ) def suite(): diff --git a/tests/test_ebuild.py b/tests/test_ebuild.py index 580e2a3..cb3481b 100644 --- a/tests/test_ebuild.py +++ b/tests/test_ebuild.py @@ -13,16 +13,16 @@ import os import unittest -import utils +import testcase from g_octave import ebuild, overlay -class TestEbuild(unittest.TestCase): +class TestEbuild(testcase.TestCase): def setUp(self): - self._config, self._config_file, self._dir = utils.create_env(json_files=True) - overlay.create_overlay(conf = self._config, quiet = True) + testcase.TestCase.setUp(self) + overlay.create_overlay(quiet=True) def test_re_keywords(self): keywords = [ @@ -59,10 +59,7 @@ class TestEbuild(unittest.TestCase): ('language2', '0.0.1'), ] for pkgname, pkgver in ebuilds: - _ebuild = ebuild.Ebuild( - pkgname + '-' + pkgver, - conf = self._config, - ) + _ebuild = ebuild.Ebuild(pkgname + '-' + pkgver) _ebuild.create( accept_keywords = 'amd64 ~amd64 x86 ~x86', manifest = False, @@ -87,10 +84,7 @@ class TestEbuild(unittest.TestCase): self.assertEqual(len(created_ebuild), len(original_ebuild)) for i in range(len(created_ebuild)): self.assertEqual(created_ebuild[i], original_ebuild[i]) - - def tearDown(self): - utils.clean_env(self._config_file, self._dir) - + def suite(): suite = unittest.TestSuite() diff --git a/tests/test_overlay.py b/tests/test_overlay.py index 6a480c1..62239f5 100644 --- a/tests/test_overlay.py +++ b/tests/test_overlay.py @@ -13,18 +13,15 @@ import os import unittest -import utils +import testcase from g_octave import config, overlay -class TestOverlay(unittest.TestCase): - - def setUp(self): - self._config, self._config_file, self._dir = utils.create_env() +class TestOverlay(testcase.TestCase): def test_overlay(self): - overlay.create_overlay(conf = self._config, quiet = True) + overlay.create_overlay(quiet=True) files = { os.path.join(self._config.overlay, 'profiles', 'repo_name'): 'g-octave', os.path.join(self._config.overlay, 'profiles', 'categories'): 'g-octave', @@ -37,9 +34,6 @@ class TestOverlay(unittest.TestCase): os.path.join(self._config.overlay, 'eclass', 'g-octave.eclass') )) - def tearDown(self): - utils.clean_env(self._config_file, self._dir) - def suite(): suite = unittest.TestSuite() diff --git a/tests/testcase.py b/tests/testcase.py new file mode 100644 index 0000000..cb9e576 --- /dev/null +++ b/tests/testcase.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +""" + testcase.py + ~~~~~~~~~~~ + + Custom test-case class for g-octave. The g_octave.config test suite + SHOULD NOT inherit this class. + + :copyright: (c) 2010 by Rafael Goncalves Martins + :license: GPL-2, see LICENSE for more details. +""" + +import os +import shutil +import tempfile +import unittest + +from g_octave.config import Config + + +class TestCase(unittest.TestCase): + + def setUp(self): + self._tempdir = tempfile.mkdtemp() + current_dir = os.path.dirname(os.path.abspath(__file__)) + os.environ['GOCTAVE_DB'] = os.path.join(current_dir, 'files') + os.environ['GOCTAVE_OVERLAY'] = os.path.join(self._tempdir, 'overlay') + self._config = Config() + + def tearDown(self): + shutil.rmtree(self._tempdir) + del os.environ['GOCTAVE_DB'] + del os.environ['GOCTAVE_OVERLAY'] diff --git a/tests/utils.py b/tests/utils.py deleted file mode 100644 index 13caa19..0000000 --- a/tests/utils.py +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -""" - utils.py - ~~~~~~~~ - - module with helper functions to the test suites. - - :copyright: (c) 2010 by Rafael Goncalves Martins - :license: GPL-2, see LICENSE for more details. -""" - -from g_octave.compat import py3k, open - -if py3k: - import configparser -else: - import ConfigParser as configparser -import os -import shutil -import tempfile - -from g_octave import config - -def create_env(json_files=False): - """returns a tuple with the *g_octave.config* object and the path of - the temporary config and directory - """ - - config_file = tempfile.mkstemp(suffix='.cfg')[1] - directory = tempfile.mkdtemp() - current_dir = os.path.dirname(os.path.abspath(__file__)) - db = os.path.join(current_dir, 'files') - overlay = os.path.join(directory, 'overlay') - - cp = configparser.ConfigParser() - cp.add_section('main') - cp.set('main', 'db', db) - cp.set('main', 'overlay', overlay) - - with open(config_file, 'w') as fp: - cp.write(fp) - - conf = config.Config( - fetch_phase = not json_files, - config_file = config_file, - create_dirs = True - ) - - return conf, config_file, directory - -def clean_env(config_file, directory): - os.unlink(config_file) - shutil.rmtree(directory) |