Esempio n. 1
0
    def test_infinite_substitution_raises(self):
        # Given
        data = '{key1}'
        store = {'key1': '{key2}', 'key2': '{key1}'}

        # Then
        with self.assertRaises(RuntimeError):
            parser.expand_str(data, store)
Esempio n. 2
0
    def test_replace_nested(self):
        # Given
        data = '{numbers:five} = 2 + 3'
        store = {'numbers': {'five': 5}}

        # Then
        self.assertEquals(parser.expand_str(data, store), '5 = 2 + 3')
Esempio n. 3
0
    def test_replace_a_non_string_value(self):
        # Given
        data = '{five} = 2 + 3'
        store = {'five': 5}

        # Then
        self.assertEquals(parser.expand_str(data, store), '5 = 2 + 3')
Esempio n. 4
0
    def test_replace_same_input_twice(self):
        # Given
        data = '{number} is equal to {number}'
        store = {'number': 'five'}

        # Then
        self.assertEquals(parser.expand_str(data, store),
                          'five is equal to five')
Esempio n. 5
0
    def test_one_level_replace(self):
        # Given
        data = 'There is {something} to replace'
        store = {'something': 'nothing'}

        # Then
        self.assertEquals(parser.expand_str(data, store),
                          'There is nothing to replace')
Esempio n. 6
0
    def test_replace_two_levels(self):
        # Given
        data = 'This is equal to {value}'
        store = {
            'value': '{part1}{part2}',
            'part1': 'fi',
            'part2': '{part3}e',
            'part3': 'v'
        }

        # Then
        self.assertEquals(parser.expand_str(data, store),
                          'This is equal to five')
Esempio n. 7
0
    def test_nothing_to_replace(self):
        # Given
        data = "There is nothing to replace"

        # Then
        self.assertEquals(parser.expand_str(data, {}), data)