File: test_api.py

package info (click to toggle)
python-tinycss 0.4-8
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 716 kB
  • sloc: python: 2,476; makefile: 7
file content (45 lines) | stat: -rw-r--r-- 1,340 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# coding: utf-8
"""
    Tests for the public API
    ------------------------

    :copyright: (c) 2012 by Simon Sapin.
    :license: BSD, see LICENSE for more details.
"""


from __future__ import unicode_literals

from pytest import raises
from tinycss import make_parser
from tinycss.page3 import CSSPage3Parser


def test_make_parser():
    class MyParser(object):
        def __init__(self, some_config):
            self.some_config = some_config

    parsers = [
        make_parser(),
        make_parser('page3'),
        make_parser(CSSPage3Parser),
        make_parser(MyParser, some_config=42),
        make_parser(CSSPage3Parser, MyParser, some_config=42),
        make_parser(MyParser, 'page3', some_config=42),
    ]

    for parser, exp in zip(parsers, [False, True, True, False, True, True]):
        assert isinstance(parser, CSSPage3Parser) == exp

    for parser, exp in zip(parsers, [False, False, False, True, True, True]):
        assert isinstance(parser, MyParser) == exp

    for parser in parsers[3:]:
        assert parser.some_config == 42

    # Extra or missing named parameters
    raises(TypeError, make_parser, some_config=4)
    raises(TypeError, make_parser, 'page3', some_config=4)
    raises(TypeError, make_parser, MyParser)
    raises(TypeError, make_parser, MyParser, some_config=4, other_config=7)