diff options
author | 2010-05-27 20:59:26 -0300 | |
---|---|---|
committer | 2010-05-27 20:59:26 -0300 | |
commit | c822ec02f43b0549b689a0f0dc31486c7f5539a5 (patch) | |
tree | bf32c3f42e950c02b7edd96d2ef329d53fa9f508 | |
parent | moved the snippet of code that creates a "fake" DESCRIPTION tree from tests/t... (diff) | |
download | g-octave-c822ec02f43b0549b689a0f0dc31486c7f5539a5.tar.gz g-octave-c822ec02f43b0549b689a0f0dc31486c7f5539a5.tar.bz2 g-octave-c822ec02f43b0549b689a0f0dc31486c7f5539a5.zip |
Added tests to g_octave/config.py (tests/test_config.py)
-rw-r--r-- | g_octave/config.py | 8 | ||||
-rw-r--r-- | tests/g-octave.cfg | 5 | ||||
-rw-r--r-- | tests/g-octave_empty.cfg | 1 | ||||
-rw-r--r-- | tests/test_config.py | 57 |
4 files changed, 68 insertions, 3 deletions
diff --git a/g_octave/config.py b/g_octave/config.py index 8ba1a5d..8609df6 100644 --- a/g_octave/config.py +++ b/g_octave/config.py @@ -21,12 +21,14 @@ class Config(object): __section_name = 'main' - def __init__(self, fetch_phase=False): + def __init__(self, fetch_phase=False, config_file=None, create_dirs=True): # Config Parser self.__config = ConfigParser.ConfigParser(self.__defaults) - if os.path.exists('../etc/g-octave.cfg.devel'): + if config_file is not None: + self.__config_file = config_file + elif os.path.exists('../etc/g-octave.cfg.devel'): self.__config_file = '../etc/g-octave.cfg.devel' else: self.__config_file = '/etc/g-octave.cfg' @@ -37,7 +39,7 @@ class Config(object): __overlay = self.__config.get(self.__section_name, 'overlay') for dir in [__db, __overlay]: - if not os.path.exists(dir): + if not os.path.exists(dir) and create_dirs: os.makedirs(dir, 0755) if not fetch_phase: diff --git a/tests/g-octave.cfg b/tests/g-octave.cfg new file mode 100644 index 0000000..d50b924 --- /dev/null +++ b/tests/g-octave.cfg @@ -0,0 +1,5 @@ +[main] +db = /path/to/the/db +overlay = /path/to/the/overlay +categories = comma,separated,categories,names +db_mirror = http://some.cool.url/octave-forge/ diff --git a/tests/g-octave_empty.cfg b/tests/g-octave_empty.cfg new file mode 100644 index 0000000..15685c3 --- /dev/null +++ b/tests/g-octave_empty.cfg @@ -0,0 +1 @@ +[main] diff --git a/tests/test_config.py b/tests/test_config.py new file mode 100644 index 0000000..7c2cc26 --- /dev/null +++ b/tests/test_config.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" + test_config.py + ~~~~~~~~~~~~~~ + + test suite for the *g_octave.config* module + + :copyright: (c) 2010 by Rafael Goncalves Martins + :license: GPL-2, see LICENSE for more details. +""" + +import os +import unittest + +from g_octave import config + + +class TestConfig(unittest.TestCase): + + def setUp(self): + # TODO: fetch_phase = False + current_dir = os.path.dirname(os.path.abspath(__file__)) + + # object with the config file empty, should use the default values + self._empty_cfg = config.Config( + config_file = os.path.join(current_dir, 'g-octave_empty.cfg'), + create_dirs = False, + fetch_phase = True + ) + + # object with an example config file + self._cfg = config.Config( + config_file = os.path.join(current_dir, 'g-octave.cfg'), + create_dirs = False, + fetch_phase = True + ) + + def test_empty_config_attributes(self): + self.assertEqual(self._empty_cfg.db, '/var/cache/g-octave') + self.assertEqual(self._empty_cfg.overlay, '/usr/local/portage/g-octave') + self.assertEqual(self._empty_cfg.categories, 'main,extra,language') + self.assertEqual(self._empty_cfg.db_mirror, 'http://files.rafaelmartins.eng.br/octave-forge') + + def test_config_attributes(self): + self.assertEqual(self._cfg.db, '/path/to/the/db') + self.assertEqual(self._cfg.overlay, '/path/to/the/overlay') + self.assertEqual(self._cfg.categories, 'comma,separated,categories,names') + self.assertEqual(self._cfg.db_mirror, 'http://some.cool.url/octave-forge/') + + +def suite(): + suite = unittest.TestSuite() + suite.addTest(TestConfig('test_empty_config_attributes')) + suite.addTest(TestConfig('test_config_attributes')) + return suite |