コード例 #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_init_missing_toks(self):
        values = {'sections': {}}
        coord = location.Coordinate('path', 23)
        toks = [perfile.Token(perfile.TOK_CHAR, '{')]

        with pytest.raises(perfile.ParseException):
            template.SectionDirective(values, coord, toks)

        assert values == {'sections': {}}
コード例 #3
0
    def test_init_bad_brace(self):
        values = {'sections': {}}
        coord = location.Coordinate('path', 23)
        toks = [
            perfile.Token(perfile.TOK_WORD, 'section'),
            perfile.Token(perfile.TOK_CHAR, '('),
        ]

        with pytest.raises(perfile.ParseException):
            template.SectionDirective(values, coord, toks)

        assert values == {'sections': {}}
コード例 #4
0
    def test_init_base(self):
        values = {'sections': {}}
        coord = location.Coordinate('path', 23)
        toks = [
            perfile.Token(perfile.TOK_WORD, 'section'),
            perfile.Token(perfile.TOK_CHAR, '{'),
        ]

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

        assert result.name == 'section'
        assert result.requires == set()
        assert result.values is values
        assert result.start_coord == coord
        assert values == {'sections': {}}
コード例 #5
0
    def test_init_missing_close_paren(self):
        values = {'sections': {}}
        coord = location.Coordinate('path', 23)
        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, '{'),
        ]

        with pytest.raises(perfile.ParseException):
            template.SectionDirective(values, coord, toks)

        assert values == {'sections': {}}
コード例 #6
0
    def test_call_bad_end(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 = [perfile.Token(perfile.TOK_CHAR, '}')]
        obj = template.SectionDirective(values, start_coord, start_toks)

        with pytest.raises(perfile.ParseException):
            obj(end_coord, 'buf', end_toks)

        assert values == {'sections': {}}
        assert not mock_Section.called