aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2010-05-29 03:47:08 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2010-05-29 03:47:08 -0300
commit152e1a07d0afd2e50dd6897d88ed0d848d003390 (patch)
treecafed64da5e816859ef07471f9448f508cce5d1f
parentremoved the method to create a g_octave.DescriptionTree object from the modul... (diff)
downloadg-octave-152e1a07d0afd2e50dd6897d88ed0d848d003390.tar.gz
g-octave-152e1a07d0afd2e50dd6897d88ed0d848d003390.tar.bz2
g-octave-152e1a07d0afd2e50dd6897d88ed0d848d003390.zip
fixed tests to g_octave.overlay. added tests to g_octave.ebuild (tests/test_ebuild.py)
-rw-r--r--g_octave/ebuild.py12
-rw-r--r--tests/test_ebuild.py57
-rw-r--r--tests/test_overlay.py34
3 files changed, 70 insertions, 33 deletions
diff --git a/g_octave/ebuild.py b/g_octave/ebuild.py
index 71ece9a..85929a8 100644
--- a/g_octave/ebuild.py
+++ b/g_octave/ebuild.py
@@ -18,8 +18,6 @@ __all__ = [
]
from config import Config
-conf = Config()
-
from description import *
from description_tree import *
from exception import EbuildException
@@ -33,14 +31,18 @@ import subprocess
out = portage.output.EOutput()
# validating keywords (based on the keywords from the sci-mathematics/octave package)
-re_keywords = re.compile(r'(~)?(alpha|amd64|hppa|ppc|ppc64|sparc|x86)')
+re_keywords = re.compile(r'(~)?(alpha|amd64|hppa|ppc64|ppc|sparc|x86)')
class Ebuild:
- def __init__(self, pkg_atom, force=False):
+ def __init__(self, pkg_atom, force=False, conf=None):
self.__force = force
- self.__dbtree = DescriptionTree()
+
+ if conf is None:
+ conf = Config()
+
+ self.__dbtree = DescriptionTree(conf = conf)
atom = re_pkg_atom.match(pkg_atom)
if atom == None:
diff --git a/tests/test_ebuild.py b/tests/test_ebuild.py
new file mode 100644
index 0000000..5e0c629
--- /dev/null
+++ b/tests/test_ebuild.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""
+ test_ebuild.py
+ ~~~~~~~~~~~~~~
+
+ test suite for the *g_octave.ebuild* module
+
+ :copyright: (c) 2010 by Rafael Goncalves Martins
+ :license: GPL-2, see LICENSE for more details.
+"""
+
+import unittest
+import utils
+
+from g_octave import ebuild
+
+
+class TestEbuild(unittest.TestCase):
+
+ def setUp(self):
+ self._config, self._config_file, self._dir = utils.create_env()
+
+ def test_re_keywords(self):
+ keywords = [
+ ('alpha', (None, 'alpha')),
+ ('amd64', (None, 'amd64')),
+ ('hppa', (None, 'hppa')),
+ ('ppc', (None, 'ppc')),
+ ('ppc64', (None, 'ppc64')),
+ ('sparc', (None, 'sparc')),
+ ('x86', (None, 'x86')),
+ ('~alpha', ('~', 'alpha')),
+ ('~amd64', ('~', 'amd64')),
+ ('~hppa', ('~', 'hppa')),
+ ('~ppc', ('~', 'ppc')),
+ ('~ppc64', ('~', 'ppc64')),
+ ('~sparc', ('~', 'sparc')),
+ ('~x86', ('~', 'x86')),
+ ]
+
+ for kwstr, kwtpl in keywords:
+ match = ebuild.re_keywords.match(kwstr)
+ self.assertEqual(
+ (match.group(1), match.group(2)),
+ kwtpl
+ )
+
+ def tearDown(self):
+ utils.clean_env(self._config_file, self._dir)
+
+
+def suite():
+ suite = unittest.TestSuite()
+ suite.addTest(TestEbuild('test_re_keywords'))
+ return suite
diff --git a/tests/test_overlay.py b/tests/test_overlay.py
index 6d33edc..9242324 100644
--- a/tests/test_overlay.py
+++ b/tests/test_overlay.py
@@ -16,6 +16,7 @@ import os
import shutil
import tempfile
import unittest
+import utils
from g_octave import config, overlay
@@ -23,36 +24,14 @@ from g_octave import config, overlay
class TestOverlay(unittest.TestCase):
def setUp(self):
- self._config_file = tempfile.mkstemp(suffix='.cfg')[1]
- self._dir = tempfile.mkdtemp()
-
- # the directories doesn't need to be created. the config module
- # will do this
- self._db = os.path.join(self._dir, 'db')
- self._cache = os.path.join(self._dir, 'cache')
- self._overlay = os.path.join(self._dir, 'overlay')
-
- cp = ConfigParser.ConfigParser()
- cp.add_section('main')
- cp.set('main', 'db', self._db)
- cp.set('main', 'cache', self._cache)
- cp.set('main', 'overlay', self._overlay)
-
- with open(self._config_file, 'w') as fp:
- cp.write(fp)
-
- self._config = config.Config(
- fetch_phase = True,
- config_file = self._config_file,
- create_dirs = True
- )
+ self._config, self._config_file, self._dir = utils.create_env()
def test_overlay(self):
overlay.create_overlay(conf = self._config, quiet = True)
files = {
- os.path.join(self._overlay, 'eclass', 'octave-forge.eclass'): '',
- os.path.join(self._overlay, 'profiles', 'repo_name'): 'g-octave',
- os.path.join(self._overlay, 'profiles', 'categories'): 'g-octave',
+ os.path.join(self._config.overlay, 'eclass', 'octave-forge.eclass'): '',
+ os.path.join(self._config.overlay, 'profiles', 'repo_name'): 'g-octave',
+ os.path.join(self._config.overlay, 'profiles', 'categories'): 'g-octave',
}
for _file in files:
self.assertTrue(os.path.exists(_file))
@@ -60,8 +39,7 @@ class TestOverlay(unittest.TestCase):
self.assertEqual(fp.read(), files[_file])
def tearDown(self):
- shutil.rmtree(self._dir)
- os.unlink(self._config_file)
+ utils.clean_env(self._config_file, self._dir)
def suite():