def test_profiles(self): emptyCfg = configfile.ConfigFileWithProfiles() self.assertListEqual(emptyCfg.profiles(), ['1',]) self.assertListEqual(self.cfg.profiles(), ['1', '2', '3', '4']) self.cfg.removeProfile('3') self.assertListEqual(self.cfg.profiles(), ['1', '2', '4'])
def test_load(self): """ ConfigFile should be able to load its content from a previously saved ConfigFile object. """ with NamedTemporaryFile() as cfgFile: origCfg = configfile.ConfigFileWithProfiles() origCfg.setIntValue('profiles.version', 1) key = "config_key" value = "config_value" origCfg.setProfileStrValue(key, value) origCfg.setProfileStrValue(key, value, profile_id = '2') origCfg.save(cfgFile.name) self.cfg.load(cfgFile.name) self.assertEqual(len(self.cfg.keys()), len(origCfg.keys())) for k in origCfg.keys(): with self.subTest(k = k): #workaround for py.test3 2.5.1 doesn't support subTest msg = 'k = %s' %k self.assertTrue(self.cfg.hasKey(k), msg) self.assertEqual(origCfg.strValue(k), self.cfg.strValue(k))
def setUp(self): super(TestConfigFileWithProfiles, self).setUp() self.cfg = configfile.ConfigFileWithProfiles('DefaultProfileName') self.cfg.addProfile('foo') self.cfg.addProfile('bar') self.cfg.addProfile('baz')
def setUp(self): logger.DEBUG = '-v' in sys.argv self.cfg = configfile.ConfigFileWithProfiles('DefaultProfileName') self.cfg.add_profile('foo') self.cfg.add_profile('bar') self.cfg.add_profile('baz')