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

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

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

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

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

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

        assert result.name == 'define'
        assert result.values is values
        assert result.start_coord == coord
        assert values == {'defines': {}}
示例#4
0
    def test_call_bad_end(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 = [perfile.Token(perfile.TOK_CHAR, '}')]
        obj = template.DefineDirective(values, start_coord, start_toks)

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

        assert values == {'defines': {}}
        assert not mock_Define.called
示例#5
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')