def test_custom_extension(self): standard_path = '%s.basic1' % BASE_IMPORT_PATH custom_path = '%s.basic2' % BASE_IMPORT_PATH # standard: first works, second raises read_config(standard_path, enable_path_spliting=False) # should not raise self.assertRaises(ConfigParsingError, read_config, custom_path, enable_path_spliting=False) # change to custom ext, then first raises, second works orig_ext = set_setting('CONFIG_FILE_EXT', 'customfig') try: self.assertRaises(ConfigParsingError, read_config, standard_path, enable_path_spliting=False) read_config(custom_path, enable_path_spliting=False) # should not raise finally: set_setting('CONFIG_FILE_EXT', orig_ext) # change to a different ext, both should raise orig_ext = set_setting('CONFIG_FILE_EXT', 'nosuchfig') try: self.assertRaises(ConfigParsingError, read_config, standard_path, enable_path_spliting=False) self.assertRaises(ConfigParsingError, read_config, custom_path, enable_path_spliting=False) finally: set_setting('CONFIG_FILE_EXT', orig_ext)
def test_same_name_import_vs_config1(self): path = '%s.samename' % BASE_IMPORT_PATH # read_config -- get the fig file self.assertEqual(read_config(path).filetype, 'fig') # import -- get the py file import tests.config.samename self.assertEqual(tests.config.samename.filetype, 'py')
def test_same_name_import_vs_config1(self): path = '%s.samename' % BASE_IMPORT_PATH # read_config -- get the fig file self.assertEqual(read_config(path).filetype, 'fig') # import -- get the py file import tests.config.samename as M self.assertEqual(M.filetype, 'py')
def test_same_name_import_vs_config2(self): # same as test_same_name_import_vs_config1, but order is reversed path = '%s.samename' % BASE_IMPORT_PATH # import -- get the py file import tests.config.samename self.assertEqual(tests.config.samename.filetype, 'py') # read_config -- get the fig file self.assertEqual(read_config(path).filetype, 'fig')
def parse(self, path): # load the figura file data = read_config(UNITTEST_FILE_PATH_PREFIX + path) # extract test definitions tests = [] for k, v in list(data.items()): if getattr(v, 'is_unittest', False): v.name = k tests.append(v) data.pop(k) return tests, data
def _test_reload(self, path_to_reload, filepath_to_modify): if TEMPDIR not in sys.path: sys.path.append(TEMPDIR) config = read_config(path_to_reload).some_params self.assertEqual(config.a, 1) self.assertRaises(KeyError, lambda: config['z']) self.assertRaises(AttributeError, lambda: config.z) self.assertRaises(AttributeError, lambda: config.zz) # inject a new value, and reload (indented, to put it inside some_params) append_line(filepath_to_modify, ' z = 999') config = read_config(path_to_reload).some_params self.assertEqual(config.a, 1) self.assertEqual(config.z, 999) self.assertRaises(AttributeError, lambda: config.zz) # inject yet another value, and reload (indented, to put it inside some_params) append_line(filepath_to_modify, ' zz = 555') config = read_config(path_to_reload).some_params self.assertEqual(config.a, 1) self.assertEqual(config.z, 999) self.assertEqual(config.zz, 555)
def test_custom_extension(self): standard_path = '%s.basic1' % BASE_IMPORT_PATH custom_path = '%s.basic2' % BASE_IMPORT_PATH # standard: first works, second raises read_config(standard_path, enable_path_spliting = False) # should not raise self.assertRaises(ConfigParsingError, read_config, custom_path, enable_path_spliting = False) # change to custom ext, then first raises, second works orig_ext = set_setting('CONFIG_FILE_EXT', 'customfig') try: self.assertRaises(ConfigParsingError, read_config, standard_path, enable_path_spliting = False) read_config(custom_path, enable_path_spliting = False) # should not raise finally: set_setting('CONFIG_FILE_EXT', orig_ext) # change to a different ext, both should raise orig_ext = set_setting('CONFIG_FILE_EXT', 'nosuchfig') try: self.assertRaises(ConfigParsingError, read_config, standard_path, enable_path_spliting = False) self.assertRaises(ConfigParsingError, read_config, custom_path, enable_path_spliting = False) finally: set_setting('CONFIG_FILE_EXT', orig_ext)
def test_period_escaping_config_file(self): c = read_config('figura.tests.config.escape') self.assertIn('a.b', c) self.assertNotIn('a', c) self.assertEqual(c['a.b'], 'x') self.assertIn('d.e', c.c) self.assertNotIn('d', c.c) self.assertEqual(c.c['d.e'], 'z') ov = ConfigOverrideSet.from_dict({'c.d__e': 'DE', 'c.d': 'D'}) c.apply_overrides(ov) self.assertEqual(c.c['d.e'], 'DE') self.assertEqual(c.c.d, 'D')
def test_read_config_deep(self): c = read_config('figura.tests.config.basic1.some_params') self.assertEqual(2, c.b)
def test_entry_point_by_name(self): c = read_config('figura.tests.config.entry2') self.assertEqual(2, c.b) # __entry_point__ skips the some_params name
def test_entry_point_by_explicity_definition(self): c = read_config('figura.tests.config.entry3') self.assertEqual(2, c.b)
def test_read_config_directory(self): c = read_config('figura.tests.config') self.assertEqual(2, c.basic1.some_params.b) self.assertEqual('baz', c.more.xxx.foo.bar)
def test_read_config_directory(self): c = read_config('figura.tests.config') self.assertEqual(2, c.basic1.some_params.b) self.assertEqual('baz', c.more.xxx.foo.bar) self.assertEqual(1, c.deep1.conf1.attr1) self.assertEqual(2, c.deep1.deep2.conf2.attr2)