def setUp(self): self.env = Environment(self.generateData(), INT_VAR=int, NOT_PRESENT_VAR=(float, 33.3), STR_VAR=text_type, INT_LIST=[int], DEFAULT_LIST=([int], [2]))
class FileEnvTests(EnvTests): def setUp(self): self.env = Environment(self.generateData()) file_path = filepath('test_env.txt') self.env.read_env(file_path, PATH_VAR="/another/path") def test_path(self): self.assertNotEqual(self.PATH, self.env('PATH_VAR'))
def test_read_method(self): ENVIRON = {} env = Environment(ENVIRON) infiles = [filepath("common.properties"), filepath("env.properties")] env.read(infiles) self.assertEqual(ENVIRON['foo'], 'TEST') self.assertEqual(ENVIRON['fee'], 'DB_TEST') self.assertEqual(ENVIRON['fab'], 'DB_TEST TABLE_TEST') self.assertEqual(ENVIRON['baf'], 'TABLE_TEST DB_TEST') self.assertEqual(ENVIRON['fit'], 'cat DB_TEST TABLE_TEST') self.assertEqual(ENVIRON['tif'], 'DB_TEST TABLE_TEST cat')
class DictionaryInterfaceTests(BaseTests): def setUp(self): self.env = Environment(self.generateData(), INT_VAR=int, NOT_PRESENT_VAR=(float, 33.3), STR_VAR=text_type, INT_LIST=[int], DEFAULT_LIST=([int], [2])) def test_get(self): self.assertTypeAndValue(int, 42, self.env['INT_VAR']) self.assertTypeAndValue(int, 42, self.env.get('INT_VAR')) def test_set_and_get(self): self.env['INT_VAR'] = 24 self.assertTypeAndValue(int, 24, self.env['INT_VAR']) self.assertTypeAndValue(int, 24, self.env.get('INT_VAR')) self.env['INT_VAR'] = '99' self.assertTypeAndValue(int, 99, self.env['INT_VAR']) self.assertTypeAndValue(int, 99, self.env.get('INT_VAR')) def test_get_returns_none_not_keyerror(self): self.assertTrue(self.env.get('nonexistent') is None) def test_length(self): self.assertEqual(len(self.env), 27) def test_keys_method(self): self.assertEqual(set(self.env.keys()), set(self.generateData().keys())) def test_copy(self): copied = self.env.copy() self.assertTrue(type(self.env) is type(copied)) self.assertEqual(len(self.env), len(copied)) def test_get_attribute(self): int_var_value = self.env['INT_VAR'] self.assertEqual(int_var_value, self.env('INT_VAR')) self.assertEqual(int_var_value, self.env.INT_VAR) def test_set_attribute(self): self.env.MY_DEFAULT_SETTING = '1000' self.assertEqual(self.env.MY_DEFAULT_SETTING, '1000') self.assertEqual(self.env['MY_DEFAULT_SETTING'], '1000') self.assertEqual(self.env('MY_DEFAULT_SETTING'), '1000') self.assertEqual(self.env.int('MY_DEFAULT_SETTING'), 1000) def test_setdefault(self): self.assertTrue('INT_VAR' in self.env) self.assertTrue('XYZ' not in self.env) int_var_value = self.env['INT_VAR'] ret = self.env.setdefault('INT_VAR', int_var_value) self.assertEqual(ret, int_var_value) default = 'AAAAAA' ret = self.env.setdefault('XYZ', default) self.assertEqual(ret, default) self.assertTrue('INT_VAR' in self.env) self.assertTrue('XYZ' in self.env)
def test_set_and_get_variable_values(self): ENVIRON = {} env = Environment(ENVIRON) env['PATH'] = '$CURRENT/path/to/file' self.assertEqual(env['PATH'], '$CURRENT/path/to/file') env['CURRENT'] = '/home/user' self.assertEqual(env['PATH'], '/home/user/path/to/file')
def setUp(self): self.env = Environment( self.generateData(), INT_VAR=int, NOT_PRESENT_VAR=(float, 33.3), STR_VAR=text_type, INT_LIST=[int], DEFAULT_LIST=([int], [2]) )
def test_variables_in_initial_dict(self): env = Environment({ 'INSTALL_ROOT': '$PWD', 'PATH': '$INSTALL_ROOT/path' }) self.assertEqual(env['INSTALL_ROOT'], '$PWD') self.assertEqual(env['PATH'], '$INSTALL_ROOT/path') env['PWD'] = '/home/user' self.assertEqual(env['INSTALL_ROOT'], '/home/user') self.assertEqual(env['PATH'], '/home/user/path')
def test_environ_mutation(self): os.environ['MUSETTE_TEST_KEY'] = 'musette' env = Environment() self.assertEqual(env['MUSETTE_TEST_KEY'], 'musette') env['MUSETTE_TEST_KEY'] = 'mutated' self.assertEqual(env['MUSETTE_TEST_KEY'], 'mutated') self.assertEqual(os.environ['MUSETTE_TEST_KEY'], 'mutated') del env['MUSETTE_TEST_KEY'] with self.assertRaises(KeyError): env['MUSETTE_TEST_KEY'] with self.assertRaises(KeyError): os.environ['MUSETTE_TEST_KEY']
def test_set_and_get_nested_variable_values_again(self): ENVIRON = {} env = Environment(ENVIRON) env['PATH'] = '$CURRENT/path/to/file/$NAME' self.assertEqual(env['PATH'], '$CURRENT/path/to/file/$NAME') env['CURRENT'] = '${ROOT}/instance' # unresolved self.assertEqual(env['CURRENT'], '${ROOT}/instance') self.assertEqual(env['PATH'], '$CURRENT/path/to/file/$NAME') env['NAME'] = 'setup.py' # still unresolved self.assertEqual(env['CURRENT'], '${ROOT}/instance') self.assertEqual(env['PATH'], '$CURRENT/path/to/file/$NAME') env['ROOT'] = '/opt' # resolved self.assertEqual(env['CURRENT'], '/opt/instance') self.assertEqual(env['PATH'], '/opt/instance/path/to/file/setup.py')
class DictionaryInterfaceTests(BaseTests): def setUp(self): self.env = Environment( self.generateData(), INT_VAR=int, NOT_PRESENT_VAR=(float, 33.3), STR_VAR=text_type, INT_LIST=[int], DEFAULT_LIST=([int], [2]) ) def test_get(self): self.assertTypeAndValue(int, 42, self.env['INT_VAR']) self.assertTypeAndValue(int, 42, self.env.get('INT_VAR')) def test_set_and_get(self): self.env['INT_VAR'] = 24 self.assertTypeAndValue(int, 24, self.env['INT_VAR']) self.assertTypeAndValue(int, 24, self.env.get('INT_VAR')) self.env['INT_VAR'] = '99' self.assertTypeAndValue(int, 99, self.env['INT_VAR']) self.assertTypeAndValue(int, 99, self.env.get('INT_VAR')) def test_get_returns_none_not_keyerror(self): self.assertTrue(self.env.get('nonexistent') is None) def test_length(self): self.assertEqual(len(self.env), 27) def test_keys_method(self): self.assertEqual(set(self.env.keys()), set(self.generateData().keys())) def test_copy(self): copied = self.env.copy() self.assertTrue(type(self.env) is type(copied)) self.assertEqual(len(self.env), len(copied)) def test_get_attribute(self): int_var_value = self.env['INT_VAR'] self.assertEqual(int_var_value, self.env('INT_VAR')) self.assertEqual(int_var_value, self.env.INT_VAR) def test_set_attribute(self): self.env.MY_DEFAULT_SETTING = '1000' self.assertEqual(self.env.MY_DEFAULT_SETTING, '1000') self.assertEqual(self.env['MY_DEFAULT_SETTING'], '1000') self.assertEqual(self.env('MY_DEFAULT_SETTING'), '1000') self.assertEqual(self.env.int('MY_DEFAULT_SETTING'), 1000) def test_setdefault(self): self.assertTrue('INT_VAR' in self.env) self.assertTrue('XYZ' not in self.env) int_var_value = self.env['INT_VAR'] ret = self.env.setdefault('INT_VAR', int_var_value) self.assertEqual(ret, int_var_value) default = 'AAAAAA' ret = self.env.setdefault('XYZ', default) self.assertEqual(ret, default) self.assertTrue('INT_VAR' in self.env) self.assertTrue('XYZ' in self.env)
def setUp(self): self.env = Environment(self.generateData()) file_path = filepath('test_env.txt') self.env.read_env(file_path, PATH_VAR="/another/path")
def test_singleton_environ(self): env = Environment() self.assertTrue(env._environ is os.environ)
def setUp(self): self.env = Environment(self.generateData())
def setUp(self): self._environ = {} self.env = Environment(self._environ)