Esempio n. 1
0
 def test_array(self):
     """
     You can do index-based access
     """
     variables = {'foo': [1, 'apple', 'cannon']}
     original = {'foo': '$foo[1]'}
     result = interpolate(original, variables)
     self.assertEqual(result, {'foo': 'apple'})
Esempio n. 2
0
 def test_deep_list(self):
     """
     All depths of lists should be traversed.
     """
     variables = {'foo': 'foo value'}
     original = {'hey': ['this', '$foo', 'thing']}
     result = interpolate(original, variables)
     self.assertEqual(result, {'hey': ['this', 'foo value', 'thing']})
Esempio n. 3
0
 def test_deep_dict(self):
     """
     All depths of dictionary should be traversed.
     """
     variables = {'foo': 'foo value'}
     original = {'hey': {'something': '$foo'}}
     result = interpolate(original, variables)
     self.assertEqual(result, {'hey': {'something': 'foo value'}})
Esempio n. 4
0
 def test_nonVars(self):
     """
     Non variables should be ignored.
     """
     variables = {'foo': 'foo value'}
     original = {'hey': 5}
     result = interpolate(original, variables)
     self.assertEqual(result, {'hey': 5})
Esempio n. 5
0
 def test_basic(self):
     """
     You can replace $vars with values from a dict
     """
     variables = {'foo': [1, 2, 'foo']}
     original = {'hey': '$foo'}
     result = interpolate(original, variables)
     self.assertEqual(result, {'hey': [1, 2, 'foo']})
     self.assertEqual(original, {'hey': '$foo'})
Esempio n. 6
0
 def test_attributes(self):
     """
     You can do attribute access.
     """
     class Foo:
         name = 'something'
     variables = {'foo': Foo()}
     original = {'foo': '$foo.name'}
     result = interpolate(original, variables)
     self.assertEqual(result, {'foo': 'something'})