예제 #1
0
 def test_5_copy(self):
     pwd = getcwd()
     test_settings = load(self.RC, paths=confparse.path_prefixes+(pwd,))
     self.assertEqual(test_settings.copy(True), {
         'foo': {
             'bar': {'var': 'v'},
             'test4': [{'foo': 'bar'}],
         },
         #'file': '/tmp/test1/.testrc',
         'config_file': self.tmpdir + 'test1/test/sub/dir/testrc',
     });
     test_settings = self.test_3_set_string()
     self.assertEqual(test_settings.copy(), {
         'test1': 'value',
         'test2': {
             'foo': {'bar': {'z': 'value3'}}},
         'foo': {
             'bar': {'var': 'v'},
             'test4': [{'foo': 'bar'}],
         },
         #'file': '/tmp/test1/.testrc'
         'config_file': self.tmpdir + 'test1/test/sub/dir/testrc',
     });
     #print test_settings
     #print test_settings.keys()
     return test_settings
예제 #2
0
    def test_3_set_string(self):
        test_settings = load(self.RC)
        test_settings.test1 = 'value'
        self.assertEqual(test_settings.test1, 'value')
        test_settings['test2.foo.bar.z'] = 'value'
        self.assertEqual(test_settings.test2.foo.bar.z, 'value')
        test_settings.test2.foo.bar['z'] = 'value2'
        self.assertEqual(test_settings.test2.foo.bar.z, 'value2')
        test_settings.test2.foo.bar.z = 'value3'
        self.assertEqual(test_settings.test2.foo.bar.z, 'value3')

        self.assertEqual(test_settings.test2.foo.bar.path(), '.test2.foo.bar')
        #self.assertEqual(test_settings.test2.foo.bar.z.path(), '.test2.foo.bar.z')
        return test_settings
예제 #3
0
    def test_2_load(self):
        test_settings = load(self.RC)
        self.assertEqual(getattr(confparse._, self.RC), test_settings)

        self.assert_('foo' in test_settings)
        self.assert_('bar' in test_settings.foo)
        self.assert_('var' in test_settings.foo.bar)
        self.assert_(test_settings.source_key in test_settings)

        self.assertEqual(test_settings.default_source_key, 'config_file')
        source_key = test_settings.source_key
        self.assertEqual(source_key, 'config_file')
        self.assert_(hasattr(test_settings, source_key))

        self.assertEqual(test_settings.default_config_key, 'default')
#        self.assertEqual(test_settings.config_key, 'config_file')

        self.assertEqual(self.tmpdir+'test1/'+self.PWD+'testrc', getattr(test_settings, source_key))
        # XXX: merge configs? self.assertEqual(tmpdir+'test1/.testrc', getattr(test_settings, source_key))

        test_settings.foo.bar.mod = load(self.RC)
        self.assert_('foo' in test_settings.foo.bar.mod)
        self.assert_('bar' in test_settings.foo.bar.mod.foo)
        self.assert_('var' in test_settings.foo.bar.mod.foo.bar)
예제 #4
0
 def test_2(self):
     settings = load(self.name)
     self.assert_('id' in settings)
예제 #5
0
 def confparse_test_func1_(self):
     self._print_test_files()
     conf = expand_config_path(self.NAME).next()
     #self.assertEqual(conf, self.name)
     settings = load(self.NAME)
예제 #6
0
 def test_4_lists(self):
     test_settings = load(self.RC)
     test_settings.test3 = [1,2,3]
     self.assertEqual(test_settings.test3, [1,2,3])
     self.assertEqual(test_settings.foo.test4[0].foo, 'bar')