Пример #1
0
    def test_call_base(self, mocker):
        mock_Section = mocker.patch.object(template, 'Section')
        values = {'sections': {}}
        start_coord = location.Coordinate('path', 23)
        end_coord = location.Coordinate('path', 42)
        start_toks = [
            perfile.Token(perfile.TOK_WORD, 'section'),
            perfile.Token(perfile.TOK_CHAR, '('),
            perfile.Token(perfile.TOK_WORD, 'var1'),
            perfile.Token(perfile.TOK_CHAR, ','),
            perfile.Token(perfile.TOK_WORD, 'var2'),
            perfile.Token(perfile.TOK_CHAR, ','),
            perfile.Token(perfile.TOK_WORD, 'var3'),
            perfile.Token(perfile.TOK_CHAR, ')'),
            perfile.Token(perfile.TOK_CHAR, '{'),
        ]
        end_toks = []
        obj = template.SectionDirective(values, start_coord, start_toks)

        result = obj(end_coord, 'buf', end_toks)

        assert result is None
        assert values == {
            'sections': {
                'section': mock_Section.return_value
            },
        }
        mock_Section.assert_called_once_with(
            location.CoordinateRange('path', 23, 42),
            'section',
            {'var1', 'var2', 'var3'},
            'buf',
        )
Пример #2
0
    def test_base(self, mocker):
        mock_InsertSection = mocker.patch.object(template, 'InsertSection')
        values = {'structure': []}
        coord = location.Coordinate('path', 23)
        toks = [perfile.Token(perfile.TOK_WORD, 'section')]

        result = template.insert(values, coord, toks)

        assert result is None
        assert values == {
            'structure': [mock_InsertSection.return_value],
        }
        mock_InsertSection.assert_called_once_with(
            location.CoordinateRange('path', 23, 23), 'section')
Пример #3
0
    def test_call_base(self, mocker):
        mock_Literal = mocker.patch.object(template, 'Literal')
        values = {'structure': []}
        start_coord = location.Coordinate('path', 23)
        end_coord = location.Coordinate('path', 42)
        start_toks = [perfile.Token(perfile.TOK_CHAR, '{')]
        end_toks = []
        obj = template.LiteralDirective(values, start_coord, start_toks)

        result = obj(end_coord, 'buf', end_toks)

        assert result is None
        assert values == {
            'structure': [mock_Literal.return_value],
        }
        mock_Literal.assert_called_once_with(
            location.CoordinateRange('path', 23, 42), 'buf')
Пример #4
0
    def test_call_base(self, mocker):
        mock_Define = mocker.patch.object(template, 'Define')
        values = {'defines': {}}
        start_coord = location.Coordinate('path', 23)
        end_coord = location.Coordinate('path', 42)
        start_toks = [
            perfile.Token(perfile.TOK_WORD, 'define'),
            perfile.Token(perfile.TOK_CHAR, '{'),
        ]
        end_toks = []
        obj = template.DefineDirective(values, start_coord, start_toks)

        result = obj(end_coord, 'buf', end_toks)

        assert result is None
        assert values == {
            'defines': {
                'define': mock_Define.return_value
            },
        }
        mock_Define.assert_called_once_with(
            location.CoordinateRange('path', 23, 42), 'define', 'buf')
Пример #5
0
    def test_ne_unequal_end(self):
        obj1 = location.CoordinateRange('file.name', 23, 42)
        obj2 = location.CoordinateRange('file.name', 23, 43)

        assert obj1.__ne__(obj2)
Пример #6
0
    def test_ne_other(self):
        obj = location.CoordinateRange('file.name', 23, 42)

        assert obj.__ne__(other)
Пример #7
0
    def test_ne_equal(self):
        obj1 = location.CoordinateRange('file.name', 23, 42)
        obj2 = location.CoordinateRange('file.name', 23, 42)

        assert not obj1.__ne__(obj2)
Пример #8
0
    def test_eq_unequal_start(self):
        obj1 = location.CoordinateRange('file.name', 23, 42)
        obj2 = location.CoordinateRange('file.name', 24, 42)

        assert not obj1.__eq__(obj2)
Пример #9
0
    def test_str_multiline(self):
        obj = location.CoordinateRange('file.name', 23, 42)

        result = str(obj)

        assert result == 'file.name:23-42'
Пример #10
0
    def test_str_oneline(self):
        obj = location.CoordinateRange('file.name', 23, 23)

        result = str(obj)

        assert result == 'file.name:23'
Пример #11
0
    def test_init(self):
        result = location.CoordinateRange('file.name', 23, 42)

        assert result.path == 'file.name'
        assert result.start == 23
        assert result.end == 42