class TestImport(unittest.TestCase): def setUp(self): self.conf = PyConfigParser() self.dir = tempfile.mkdtemp() self.file = os.path.join(self.dir, 'extend.conf') def tearDown(self): shutil.rmtree(self.dir) def test_import_empty_file_with_inline_comment(self): with open(os.path.join(self.dir, 'base.conf'), 'w') as f: print('a = 1', file=f) with open(self.file, 'w') as f: print('from base import * # really', file=f) print('b = 1', file=f) self.conf.load_from_file(self.file) self.assertEqual(self.conf, dict(a=1, b=1)) def test_opened_files(self): with open(os.path.join(self.dir, 'base.conf'), 'w') as f: print('a = 1', file=f) with open(self.file, 'w') as f: print('from base import * # really', file=f) print('b = 1', file=f) self.conf.load_from_file(self.file) self.assertTrue(self.file in self.conf.opened_files) self.assertTrue( os.path.join(self.dir, 'base.conf') in self.conf.opened_files)
class TestImport(unittest.TestCase): def setUp(self): self.conf = PyConfigParser() self.dir = tempfile.mkdtemp() self.file = os.path.join(self.dir, 'extend.conf') def tearDown(self): shutil.rmtree(self.dir) def test_import_empty_file_with_inline_comment(self): with open(os.path.join(self.dir, 'base.conf'), 'w') as f: print('a = 1', file=f) with open(self.file, 'w') as f: print('from base import * # really', file=f) print('b = 1', file=f) self.conf.load_from_file(self.file) self.assertEqual(self.conf, dict(a=1, b=1)) def test_opened_files(self): with open(os.path.join(self.dir, 'base.conf'), 'w') as f: print('a = 1', file=f) with open(self.file, 'w') as f: print('from base import * # really', file=f) print('b = 1', file=f) self.conf.load_from_file(self.file) self.assertTrue(self.file in self.conf.opened_files) self.assertTrue(os.path.join(self.dir, 'base.conf') in self.conf.opened_files)
class TestClientCommandContainer(unittest.TestCase): def setUp(self): self.dir = tempfile.mkdtemp() self.conf = PyConfigParser() self.file = os.path.join(self.dir, 'test.conf') with open(self.file, 'w') as f: f.write(TEST_CONFIG) self.conf.load_from_file(self.file) def tearDown(self): shutil.rmtree(self.dir) def test_config_from_file(self): container = ClientCommandContainer(self.conf) values = { 'HUB_URL': 'https://localhost/hub/xmlrpc', 'AUTH_METHOD': 'krbv' } self.assertEqual(container.conf, values) def test_config_from_kwargs(self): container = ClientCommandContainer(self.conf, USERNAME='******') values = { 'HUB_URL': 'https://localhost/hub/xmlrpc', 'AUTH_METHOD': 'krbv', 'USERNAME': '******' } self.assertEqual(container.conf, values)
def main(): conf = PyConfigParser() conf.load_from_file(os.path.expanduser(CONF_PATH)) container = BorgaCommandContainer(conf=conf) formatter = IndentedHelpFormatter(max_help_position=60, width=120) parser = CommandOptionParser(command_container=container, formatter=formatter, default_command='help') parser.run() sys.exit(0)
class TestImport(unittest.TestCase): def setUp(self): self.conf = PyConfigParser() self.dir = tempfile.mkdtemp() self.file = os.path.join(self.dir, 'extend.conf') def tearDown(self): shutil.rmtree(self.dir) def test_import_empty_file_with_inline_comment(self): with open(os.path.join(self.dir, 'base.conf'), 'w') as f: print('a = 1', file=f) with open(self.file, 'w') as f: print('from base import * # really', file=f) print('b = 1', file=f) self.conf.load_from_file(self.file) self.assertEqual(self.conf, dict(a=1, b=1)) def test_opened_files(self): with open(os.path.join(self.dir, 'base.conf'), 'w') as f: print('a = 1', file=f) with open(self.file, 'w') as f: print('from base import * # really', file=f) print('b = 1', file=f) self.conf.load_from_file(self.file) self.assertTrue(self.file in self.conf.opened_files) self.assertTrue( os.path.join(self.dir, 'base.conf') in self.conf.opened_files) def test_global_variables(self): with open(os.path.join(self.dir, 'base.conf'), 'w') as f: print('a = c', file=f) print('d = 5', file=f) print('global x', file=f) print('x = 6', file=f) with open(self.file, 'w') as f: print('global c', file=f) print('global d', file=f) print('global f', file=f) print('c = 42', file=f) print('d = 42', file=f) print('from base import * # really', file=f) self.conf.load_from_file(self.file) self.assertEqual(self.conf["a"], 42) self.assertEqual(self.conf["d"], 5) self.assertEqual(self.conf["x"], 6) self.assertEqual(self.conf["f"], None)
def conf(fixtures_dir): conf_file = os.path.join(fixtures_dir, 'basic.conf') conf = PyConfigParser() conf.load_from_file(conf_file) return conf