示例#1
0
 def test_config_print(self):
     expected = [
         'directory: setting1',
         'directoryMonth: setting2',
         'weekdays: [\'setting3\', \'setting4\']',
         '',
         ]
     expected = "\n".join(expected)
     test_conf = alarm.AppConfig(self.config_filename)
     
     # backup stdout
     stdout_org = sys.stdout
     # create fake stdout
     my_stdout = MyOutput()
     try:
         # redirect output
         sys.stdout = my_stdout
         # capture print() in fake stdout
         test_conf.print_config()
     except Exception:
         raise Exception
     finally:
         # reset output
         sys.stdout = stdout_org
     self.assertEqual(str(my_stdout), expected)
示例#2
0
 def test_config_get(self):
     test_conf = alarm.AppConfig(self.config_filename)
     expected = {
         'directory': 'setting1',
         'directoryMonth': 'setting2',
         'weekdays': ['setting3', 'setting4'],
     }
     self.assertEqual(test_conf.get_config(), expected)
示例#3
0
 def test_config_default(self):
     test_conf = alarm.AppConfig(self.config_filename)
     test_conf.default_config()
     self.assertEqual(
         test_conf.configuration['weekdays'],
         ['ponedeljak', 'utorak', 'sreda', 'cetvrtak', 'petak']
     )
     self.assertEqual(test_conf.configuration['loglevel'],  'INFO')
     self.assertEqual(
         test_conf.configuration['directory'],
         'd:\mp3\podcast\Alarm'
     )
     self.assertEqual(test_conf.configuration['directoryMonth'], '201708')
示例#4
0
 def test_write_config(self):
     #Load config file, write under different name and compare them as strings
     test_configuration = alarm.AppConfig(self.config_filename)
     # save original config filename
     config_filename_original = self.config_filename
     test_configuration.config_filename = 'test_config_write.xml'
     # write second config file
     test_configuration.write_config()
     test = self.load_txt_file(self.config_filename)
     expected = self.load_txt_file(config_filename_original)
     self.assertEqual(test, expected)
     # delete econd config file
     self.delete_configuration_file()
     # restore original config file name for tearDown() removal
     self.config_filename = config_filename_original
示例#5
0
 def test_config_weekdays(self):
     test_conf = alarm.AppConfig(self.config_filename)
     self.assertEqual(
         test_conf.configuration['weekdays'],
         ['setting3', 'setting4']
     )
示例#6
0
 def test_set_config(self):
     test_conf = alarm.AppConfig(self.config_filename)
     # TODO: add support for setting and writing config
     self.assertIsNone(
         test_conf.set_config({'itemA': 'settingA', 'itemB': 'settingB'})
     )
示例#7
0
 def test_config_weekdays_exists(self):
     test_conf = alarm.AppConfig(self.config_filename)
     self.assertIn('weekdays', test_conf.configuration)
示例#8
0
 def test_config_directory_month(self):
     test_conf = alarm.AppConfig(self.config_filename)
     self.assertEqual(test_conf.configuration['directoryMonth'], 'setting2')
示例#9
0
 def test_config_directory_month_exists(self):
     test_conf = alarm.AppConfig(self.config_filename)
     self.assertIn('directoryMonth', test_conf.configuration)
示例#10
0
 def test_config_repr(self):
     test_conf = alarm.AppConfig(self.config_filename)
     self.assertEqual(repr(test_conf), 'AppConfig(test_config.xml)')
示例#11
0
 def test_config_string(self):
     test_conf = alarm.AppConfig(self.config_filename)
     self.assertEqual(
         str(test_conf),
         ' Configuration loaded from ' + self.config_filename
    )