/
test_tools.py
60 lines (39 loc) · 1.62 KB
/
test_tools.py
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
import os
import pytest
from split_settings.tools import include
_FIXTURE_VALUE = 'FIXTURE_VALUE'
def test_missing_file_error(scope):
"""This test covers the OSError, when file does not exist."""
with pytest.raises(OSError, match='does-not-exist.py'):
include('does-not-exist.py', scope=scope)
def test_keys_count(scope, fixture_file):
"""Scope must contain all base python attrs and a custom value."""
include(fixture_file, scope=scope)
# Keys:
# 'FIXTURE_VALUE', '__file__', '__doc__',
# '__builtins__', '__included_files__'
assert len(scope.keys()) == 5
def test_included_file_scope(scope, fixture_file):
"""Test emulates gunicorn behavior with `__included_file__` value."""
base = os.path.dirname(__file__)
saved_file = os.path.join(base, 'basic')
scope['__included_file__'] = saved_file
include(fixture_file, scope=scope)
assert _FIXTURE_VALUE in scope
assert scope['__included_file__'] == saved_file
def test_empty_included_file(scope, fixture_file):
"""Test when there's no `__included_file__`."""
include(fixture_file, scope=scope)
assert _FIXTURE_VALUE in scope
assert '__included_file__' not in scope
def test_unicode_passed(scope, fixture_file):
"""Tests the `unicode` filename in `python2`."""
include(fixture_file, scope=scope)
assert _FIXTURE_VALUE in scope
def test_caller_scope_automatically(fixture_file):
"""
Tests `include` function for automatic `globals()` extraction.
Now you can omit positional argument `scope`.
"""
include(fixture_file)
assert _FIXTURE_VALUE in globals() # noqa: WPS421