예제 #1
0
파일: test_fileop.py 프로젝트: lowks/coal
 def test(l, p):
     src = self.src(path('template_dir') / p)
     dst = self.dst(path('test_dir') / p)
     self.assertTrue(dst in l)
     if l[dst] is not None:
         self.assertEqual(l[dst], src)
     del l[dst]
예제 #2
0
파일: test_config.py 프로젝트: cjmeyer/coal
    def test_update(self):
        self.cfg1.update(self.cfg2)

        self.assertEqual(self.cfg1.get("section1", "key1"), "value1")
        self.assertEqual(self.cfg1.source("section1", "key1"), path("source1").abspath())
        self.assertEqual(self.cfg1.get("section2", "key2"), "value2")
        self.assertEqual(self.cfg1.source("section2", "key2"), None)

        self.cfg2.set("section2", "key2", "VALUE2")

        self.assertEqual(self.cfg1.get("section2", "key2"), "value2")
예제 #3
0
    def test_update(self):
        self.cfg1.update(self.cfg2)

        self.assertEqual(self.cfg1.get('section1', 'key1'), 'value1')
        self.assertEqual(self.cfg1.source('section1', 'key1'),
                         path('source1').abspath())
        self.assertEqual(self.cfg1.get('section2', 'key2'), 'value2')
        self.assertEqual(self.cfg1.source('section2', 'key2'), None)

        self.cfg2.set('section2', 'key2', 'VALUE2')

        self.assertEqual(self.cfg1.get('section2', 'key2'), 'value2')
예제 #4
0
파일: test_fileop.py 프로젝트: lowks/coal
 def setUp(self):
     self.basepath = path(__file__).dirname()
     self.srcroot = self.basepath / 'templates'
     self.dstroot = self.basepath / 'results'
     self._stdin = StringIO.StringIO()
     self._stdout = StringIO.StringIO()
     self._stderr = StringIO.StringIO()
     self.shell = self.build_shell(self._stdin, self._stdout, self._stderr)
     self.fop = self.build_fop(self.shell, self.srcroot, self.dstroot)
     if self.dstroot.exists():
         self.dstroot.removedirs()
     self.dstroot.makedirs(0755)
예제 #5
0
class IniConfigStore(unittest.TestCase):
    ini_file = path(__file__).parent / 'config/ini_test.conf'

    def _test(self, section, key, value, source=None):
        self.assertEqual(self.cfg.get(section, key), value)
        self.assertEqual(self.cfg.source(section, key), source
                         or self.ini_file.abspath())

    def _test_expected(self):
        self._test('section1', 'key1', 'value1')
        self._test('section1', 'key2', 'value2')
        self._test('section2', 'key3', 'value3')
        self._test('section2', 'key4', 'value4')

    def test_load_file(self):
        self.cfg = config.IniConfigStore.load_file(self.ini_file)
        self._test_expected()

    def test_read_file(self):
        self.cfg = config.IniConfigStore()
        with open(self.ini_file, 'r') as f:
            self.cfg.read(f)
        self._test_expected()

    def test_write_file(self):
        fp = StringIO.StringIO()

        cfg = config.IniConfigStore()
        cfg.set('section1', 'key1', 'value1')
        cfg.set('section1', 'key2', 'value2')
        cfg.set('section2', 'key3', 'value3')
        cfg.set('section2', 'key4', 'value4')

        cfg.write(fp)

        fp = StringIO.StringIO(fp.getvalue())
        fp.name = '/fp'

        self.cfg = config.IniConfigStore()
        self.cfg.read(fp)
        self._test('section1', 'key1', 'value1', '/fp')
        self._test('section1', 'key2', 'value2', '/fp')
        self._test('section2', 'key3', 'value3', '/fp')
        self._test('section2', 'key4', 'value4', '/fp')
예제 #6
0
class ConfigTest(unittest.TestCase):
    ini_file = path(__file__).parent / 'config/ini_test.conf'

    def setUp(self):
        self.cfg = config.Config()
        self.cfg.read_file(self.ini_file)

    def test_get_config(self):
        self.assertEqual(self.cfg.config('section1', 'key1'), 'value1')

    def test_get_config_source(self):
        self.assertEqual(self.cfg.source('section1', 'key1'),
                         self.ini_file.abspath())

    def test_get_config_path(self):
        self.assertEqual(self.cfg.configpath('section1', 'key2'),
                         self.ini_file.abspath() / 'value2')

    def test_set_config_with_source(self):
        self.cfg.setconfig('section3', 'key5', 'value5', '/source5')
        self.assertEqual(self.cfg.config('section3', 'key5'), 'value5')
        self.assertEqual(self.cfg.source('section3', 'key5'), '/source5')

    def test_set_config_without_source(self):
        self.cfg.setconfig('section3', 'key5', 'value5')
        self.assertEqual(self.cfg.config('section3', 'key5'), 'value5')
        self.assertEqual(self.cfg.source('section3', 'key5'), None)

    def test_unset_config(self):
        self.cfg.unsetconfig('section1', 'key1')
        self.assertEqual(self.cfg.config('section1', 'key1'), None)
        self.assertEqual(self.cfg.source('section1', 'key1'), None)

    def test_copy_config(self):
        cfg = self.cfg.copy()

        self.cfg.setconfig('section1', 'key1', 'VALUE1')
        self.assertEqual(cfg.config('section1', 'key1'), 'value1')
예제 #7
0
 def test_set_with_source(self):
     self.assertEqual(self.cfg1.get('section1', 'key1'), 'value1')
     self.assertEqual(self.cfg1.source('section1', 'key1'),
                      path('source1').abspath())
예제 #8
0
파일: test_fileop.py 프로젝트: lowks/coal
 def assert_status(self, msg, p, color=None):
     p = path(p)
     if p.isabs():
         p = p.relpath()
     self.assertEqual(self.shell.status.call_args_list.pop(0), ((msg.rjust(12),), {'color':color}))
     self.assertEqual(self.shell.status.call_args_list.pop(0), (('  %s\n' % p,), {}))
예제 #9
0
파일: test_fileop.py 프로젝트: lowks/coal
 def directory(dst):
     directories[path(dst).normpath()] = None
예제 #10
0
파일: test_fileop.py 프로젝트: lowks/coal
 def template(src, dst):
     templates[path(dst).normpath()] = path(src).normpath()
예제 #11
0
파일: test_fileop.py 프로젝트: lowks/coal
 def copy_file(src, dst):
     files[path(dst).normpath()] = path(src).normpath()
예제 #12
0
파일: test_config.py 프로젝트: cjmeyer/coal
 def test_set_with_source(self):
     self.assertEqual(self.cfg1.get("section1", "key1"), "value1")
     self.assertEqual(self.cfg1.source("section1", "key1"), path("source1").abspath())