Beispiel #1
0
 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)
Beispiel #2
0
 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')
Beispiel #3
0
 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')
Beispiel #4
0
 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')
Beispiel #5
0
 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
Beispiel #6
0
 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)
Beispiel #7
0
 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)
Beispiel #8
0
 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
Beispiel #9
0
 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)
Beispiel #10
0
 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')
Beispiel #11
0
 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')
Beispiel #12
0
 def test_read_config_deep(self):
     c = read_config('figura.tests.config.basic1.some_params')
     self.assertEqual(2, c.b)
Beispiel #13
0
 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
Beispiel #14
0
 def test_entry_point_by_explicity_definition(self):
     c = read_config('figura.tests.config.entry3')
     self.assertEqual(2, c.b)
Beispiel #15
0
 def test_entry_point_by_explicity_definition(self):
     c = read_config('figura.tests.config.entry3')
     self.assertEqual(2, c.b)
Beispiel #16
0
 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
Beispiel #17
0
 def test_read_config_deep(self):
     c = read_config('figura.tests.config.basic1.some_params')
     self.assertEqual(2, c.b)
Beispiel #18
0
 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)
Beispiel #19
0
 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)