示例#1
0
    def test_init_bad_tok(self):
        values = {'structure': []}
        coord = location.Coordinate('path', 23)
        toks = [perfile.Token(perfile.TOK_CHAR, '(')]

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

        assert values == {'structure': []}
示例#2
0
    def test_init_base(self):
        values = {'structure': []}
        coord = location.Coordinate('path', 23)
        toks = [perfile.Token(perfile.TOK_CHAR, '{')]

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

        assert result.values is values
        assert result.start_coord == coord
        assert values == {'structure': []}
示例#3
0
    def test_init_too_many_toks(self):
        values = {'structure': []}
        coord = location.Coordinate('path', 23)
        toks = [
            perfile.Token(perfile.TOK_WORD, 'something'),
            perfile.Token(perfile.TOK_CHAR, '{'),
        ]

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

        assert values == {'structure': []}
示例#4
0
    def test_call_bad_end(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 = [perfile.Token(perfile.TOK_CHAR, '}')]
        obj = template.LiteralDirective(values, start_coord, start_toks)

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

        assert values == {'structure': []}
        assert not mock_Literal.called
示例#5
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')