aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2010-12-09 23:22:27 -0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2010-12-09 23:22:27 -0200
commitd0c6e156e471287ae0aa33150b01bba60362db57 (patch)
treeb53b7b8b9e58412356ab6b954010e912afb1c497
parentsmall fixes on the log class and some minor typos (diff)
downloadg-octave-d0c6e156e471287ae0aa33150b01bba60362db57.tar.gz
g-octave-d0c6e156e471287ae0aa33150b01bba60362db57.tar.bz2
g-octave-d0c6e156e471287ae0aa33150b01bba60362db57.zip
fixed a bunch of tests
-rw-r--r--g_octave/checksum.py6
-rw-r--r--g_octave/description_tree.py34
-rw-r--r--g_octave/ebuild.py23
-rw-r--r--g_octave/log.py2
-rw-r--r--g_octave/overlay.py23
-rw-r--r--tests/files/DESCRIPTION4
-rw-r--r--tests/files/manifest.json11
-rw-r--r--tests/test_checksum.py16
-rw-r--r--tests/test_description.py22
-rw-r--r--tests/test_description_tree.py14
-rw-r--r--tests/test_ebuild.py18
-rw-r--r--tests/test_overlay.py12
-rw-r--r--tests/testcase.py34
-rw-r--r--tests/utils.py55
14 files changed, 117 insertions, 157 deletions
diff --git a/g_octave/checksum.py b/g_octave/checksum.py
index 7a55499..22e47d2 100644
--- a/g_octave/checksum.py
+++ b/g_octave/checksum.py
@@ -24,12 +24,16 @@ import json
import os
from .config import Config
+from .compat import py3k
config = Config()
def sha1_compute(filename):
with open(filename) as fp:
- return sha1(fp.read()).hexdigest()
+ content = fp.read()
+ if py3k:
+ content = bytes(content, 'utf-8')
+ return sha1(content).hexdigest()
def sha1_check(db, p):
description = db[p]
diff --git a/g_octave/description_tree.py b/g_octave/description_tree.py
index b719a5a..e65f8b0 100644
--- a/g_octave/description_tree.py
+++ b/g_octave/description_tree.py
@@ -27,6 +27,8 @@ from .exception import DescriptionTreeException
from .log import Log
log = Log('g_octave.description_tree')
+config = Config()
+
# from http://wiki.python.org/moin/HowTo/Sorting/
def cmp_to_key(mycmp):
'Convert a cmp= function into a key= function'
@@ -49,25 +51,20 @@ def cmp_to_key(mycmp):
class DescriptionTree(object):
- def __init__(self, conf=None, parse_sysreq=True):
+ def __init__(self, parse_sysreq=True):
log.info('Parsing the package database.')
self._parse_sysreq = parse_sysreq
self.pkg_list = {}
-
- if conf is None:
- conf = Config()
- self._config = conf
-
- self._db_path = os.path.join(conf.db, 'octave-forge')
+ self._db_path = os.path.join(config.db, 'octave-forge')
if not os.path.isdir(self._db_path):
log.error('Invalid db: %s' % self._db_path)
raise DescriptionTreeException('Invalid db: %s' % self._db_path)
self.categories = {}
- for cat in [i.strip() for i in conf.categories.split(',')]:
+ for cat in [i.strip() for i in config.categories.split(',')]:
catdir = os.path.join(self._db_path, cat)
if os.path.isdir(catdir):
self.pkg_list[cat] = []
@@ -78,14 +75,13 @@ class DescriptionTree(object):
pkg_p = desc_file[:-len('.DESCRIPTION')]
mypkg = re_pkg_atom.match(pkg_p)
if mypkg is None:
- log.error('Invalid Atom: %s' % mypkg)
- raise DescriptionTreeException('Invalid Atom: %s' % mypkg)
- if not parse_sysreq:
- self.categories[mypkg.group(1)] = cat
- self.pkg_list[cat].append({
- 'name': mypkg.group(1),
- 'version': mypkg.group(2),
- })
+ log.error('Invalid Atom: %s' % pkg_p)
+ raise DescriptionTreeException('Invalid Atom: %s' % pkg_p)
+ self.categories[mypkg.group(1)] = cat
+ self.pkg_list[cat].append({
+ 'name': mypkg.group(1),
+ 'version': mypkg.group(2),
+ })
def __getitem__(self, key):
@@ -106,11 +102,7 @@ class DescriptionTree(object):
pkg['name'],
'%s-%s.DESCRIPTION' % (pkg['name'], pkg['version']),
)
- return Description(
- pkgfile,
- conf = self._config,
- parse_sysreq = self._parse_sysreq
- )
+ return Description(pkgfile, parse_sysreq=self._parse_sysreq)
return None
diff --git a/g_octave/ebuild.py b/g_octave/ebuild.py
index f6eacef..0c5a780 100644
--- a/g_octave/ebuild.py
+++ b/g_octave/ebuild.py
@@ -33,6 +33,7 @@ import subprocess
from portage.versions import vercmp
+config = Config()
out = portage.output.EOutput()
# validating keywords (based on the keywords from the sci-mathematics/octave package)
@@ -40,19 +41,12 @@ re_keywords = re.compile(r'(~)?(alpha|amd64|hppa|ppc64|ppc|sparc|x86)')
class Ebuild:
- def __init__(self, pkg_atom, force=False, scm=False, conf=None, pkg_manager=None):
+ def __init__(self, pkg_atom, force=False, scm=False, pkg_manager=None):
self.__scm = scm
self.__force = force
- self.__conf = conf
self.__pkg_manager = pkg_manager
-
- if conf is None:
- conf = Config()
-
- self._config = conf
-
- self.__dbtree = DescriptionTree(conf = self._config)
+ self.__dbtree = DescriptionTree()
atom = re_pkg_atom.match(pkg_atom)
if atom == None:
@@ -84,7 +78,7 @@ class Ebuild:
def create(self, display_info=True, accept_keywords=None, manifest=True, nodeps=False):
my_ebuild = os.path.join(
- self._config.overlay,
+ config.overlay,
'g-octave',
'%s' % self.pkgname,
'%s-%s.ebuild' % (self.pkgname, self.version)
@@ -115,7 +109,7 @@ class Ebuild:
def __create(self, accept_keywords=None, manifest=True):
- ebuild_path = os.path.join(self._config.overlay, 'g-octave', self.pkgname)
+ ebuild_path = os.path.join(config.overlay, 'g-octave', self.pkgname)
ebuild_file = os.path.join(ebuild_path, '%s-%s.ebuild' % (self.pkgname, self.version))
metadata_file = os.path.join(ebuild_path, 'metadata.xml')
@@ -193,8 +187,8 @@ RDEPEND="${DEPEND}
# WOW, we have patches :(
- patchesdir = os.path.join(self._config.db, 'patches')
- filesdir = os.path.join(self._config.overlay, 'g-octave', self.pkgname, 'files')
+ patchesdir = os.path.join(config.db, 'patches')
+ filesdir = os.path.join(config.overlay, 'g-octave', self.pkgname, 'files')
if not os.path.exists(filesdir):
os.makedirs(filesdir, 0o755)
@@ -270,7 +264,7 @@ RDEPEND="${DEPEND}
def __search_patches(self):
- patches_dir = os.path.join(self._config.db, 'patches')
+ patches_dir = os.path.join(config.db, 'patches')
if not os.path.exists(patches_dir):
return []
@@ -317,7 +311,6 @@ RDEPEND="${DEPEND}
Ebuild(
ebuild,
force = self.__force,
- conf = self.__conf,
pkg_manager = self.__pkg_manager,
scm = self.__scm
).create()
diff --git a/g_octave/log.py b/g_octave/log.py
index b0c3010..2473bc0 100644
--- a/g_octave/log.py
+++ b/g_octave/log.py
@@ -4,7 +4,7 @@
log.py
~~~~~~
- a simple Python module to deal with g-octave logging stuff.
+ A simple Python module to deal with g-octave logging stuff.
:copyright: (c) 2010 by Rafael Goncalves Martins
:license: GPL-2, see LICENSE for more details.
diff --git a/g_octave/overlay.py b/g_octave/overlay.py
index 6433f2f..49984f3 100644
--- a/g_octave/overlay.py
+++ b/g_octave/overlay.py
@@ -23,33 +23,30 @@ import portage.output
from .config import Config, ConfigException
from .compat import open
+config = Config()
out = portage.output.EOutput()
-def create_overlay(force=False, conf=None, quiet=False):
+def create_overlay(force=False, quiet=False):
- # the function parameter conf is used by the tests
- if conf is None:
- conf = Config()
+ if force and os.path.exists(config.overlay):
+ shutil.rmtree(config.overlay)
- if force and os.path.exists(conf.overlay):
- shutil.rmtree(conf.overlay)
-
- if not os.path.exists(os.path.join(conf.overlay, 'profiles', 'repo_name')):
+ if not os.path.exists(os.path.join(config.overlay, 'profiles', 'repo_name')):
if not quiet:
- out.ebegin('Creating overlay: %s' % conf.overlay)
+ out.ebegin('Creating overlay: %s' % config.overlay)
try:
# creating dirs
for _dir in ['profiles', 'eclass']:
- dir = os.path.join(conf.overlay, _dir)
+ dir = os.path.join(config.overlay, _dir)
if not os.path.exists(dir) or force:
os.makedirs(dir, 0o755)
# creating files
files = {
- os.path.join(conf.overlay, 'profiles', 'repo_name'): 'g-octave',
- os.path.join(conf.overlay, 'profiles', 'categories'): 'g-octave',
+ os.path.join(config.overlay, 'profiles', 'repo_name'): 'g-octave',
+ os.path.join(config.overlay, 'profiles', 'categories'): 'g-octave',
}
# symlinking g-octave eclass
@@ -58,7 +55,7 @@ def create_overlay(force=False, conf=None, quiet=False):
'..', 'share', 'g-octave.eclass'
)
global_eclass = os.path.join(sys.prefix, 'share', 'g-octave', 'g-octave.eclass')
- overlay_eclass = os.path.join(conf.overlay, 'eclass', 'g-octave.eclass')
+ overlay_eclass = os.path.join(config.overlay, 'eclass', 'g-octave.eclass')
if os.path.exists(local_eclass):
os.symlink(local_eclass, overlay_eclass)
elif os.path.exists(global_eclass):
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)