def test_interpolate_environment_default_loop(self, mock_compile, mock_os): mock_os.environ = {'FOO': 'foo'} parser = SchemaConfigParser(Schema()) mock_match = MagicMock() mock_match.group.return_value = "FOO" mock_compile.return_value.search.return_value = mock_match result = parser.interpolate_environment("${FOO:-bar}") # should be uninterpolated result self.assertEqual(result, '${FOO:-bar}')
def test_include(self): schema = Schema() self.assertTrue(hasattr(schema, 'includes'))
def test_interpolate_environment_without_keys(self): parser = SchemaConfigParser(Schema()) rawval = "['%H:%M:%S', '%Y-%m-%d']" value = parser.interpolate_environment(rawval) self.assertEqual(value, rawval)
def test_interpolate_environment_extended_syntax(self, mock_os): mock_os.environ = {'PATH': 'foo'} parser = SchemaConfigParser(Schema()) result = parser.interpolate_environment("${PATH}") self.assertEqual(result, 'foo')
def test_interpolate_environment_defaults_nested(self, mock_os): mock_os.environ = {'BAR': 'bar'} parser = SchemaConfigParser(Schema()) result = parser.interpolate_environment("${FOO:-$BAR}") self.assertEqual(result, 'bar')
def test_interpolate_environment_multiple_defaults(self): "Only the first default is used" parser = SchemaConfigParser(Schema()) result = parser.interpolate_environment( "${FOO:-default1}, ${FOO:-default2}") self.assertEqual(result, 'default1, default1')
def test_interpolate_environment_multiple_with_default(self, mock_os): mock_os.environ = {'FOO': 'foo', 'BAR': 'bar'} parser = SchemaConfigParser(Schema()) result = parser.interpolate_environment( "$FOO, ${BAR}, ${BAZ:-default}") self.assertEqual(result, 'foo, bar, default')
def test_interpolate_environment_with_empty_default(self, mock_os): mock_os.environ = {} parser = SchemaConfigParser(Schema()) result = parser.interpolate_environment("X${PATH:-}X") self.assertEqual(result, 'XX')
def test_interpolate_environment_with_default_uses_env(self, mock_os): mock_os.environ = {'PATH': 'foo'} parser = SchemaConfigParser(Schema()) result = parser.interpolate_environment("X${PATH:-bar}X") self.assertEqual(result, 'XfooX')