summaryrefslogtreecommitdiff
path: root/tests/conftest.py
blob: 0b6b3534faa42b50a0eba1c30bbb3fc39cbb15b4 (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# -*- coding: utf-8 -*-
"""
    jinja2.testsuite.conftest
    ~~~~~~~~~~~~~~~~~~~~~~~~~

    Configuration and Fixtures for the tests

    :copyright: (c) 2017 by the Jinja Team.
    :license: BSD, see LICENSE for more details.
"""
import pytest
import os

from jinja2 import loaders
from jinja2.utils import have_async_gen
from jinja2 import Environment


def pytest_ignore_collect(path):
    if 'async' in path.basename and not have_async_gen:
        return True
    return False


def pytest_configure(config):
    '''Register custom marks for test categories.'''
    custom_markers = [
        'api',
        'byte_code_cache',
        'core_tags',
        'debug',
        'escapeUrlizeTarget',
        'ext',
        'extended',
        'filesystemloader',
        'filter',
        'for_loop',
        'helpers',
        'if_condition',
        'imports',
        'includes',
        'inheritance',
        'lexer',
        'lexnparse',
        'loaders',
        'loremIpsum',
        'lowlevel',
        'lrucache',
        'lstripblocks',
        'macros',
        'meta',
        'moduleloader',
        'parser',
        'regression',
        'sandbox',
        'set',
        'streaming',
        'syntax',
        'test_tests',
        'tokenstream',
        'undefined',
        'utils',
        'with_',
    ]
    for mark in custom_markers:
        config.addinivalue_line('markers', mark + ': test category')


@pytest.fixture
def env():
    '''returns a new environment.
    '''
    return Environment()


@pytest.fixture
def dict_loader():
    '''returns DictLoader
    '''
    return loaders.DictLoader({
        'justdict.html':        'FOO'
    })


@pytest.fixture
def package_loader():
    '''returns PackageLoader initialized from templates
    '''
    return loaders.PackageLoader('res', 'templates')


@pytest.fixture
def filesystem_loader():
    '''returns FileSystemLoader initialized to res/templates directory
    '''
    here = os.path.dirname(os.path.abspath(__file__))
    return loaders.FileSystemLoader(here + '/res/templates')


@pytest.fixture
def function_loader():
    '''returns a FunctionLoader
    '''
    return loaders.FunctionLoader({'justfunction.html': 'FOO'}.get)


@pytest.fixture
def choice_loader(dict_loader, package_loader):
    '''returns a ChoiceLoader
    '''
    return loaders.ChoiceLoader([dict_loader, package_loader])


@pytest.fixture
def prefix_loader(filesystem_loader, dict_loader):
    '''returns a PrefixLoader
    '''
    return loaders.PrefixLoader({
        'a':        filesystem_loader,
        'b':        dict_loader
    })