-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathtest_project.py
More file actions
109 lines (80 loc) · 2.65 KB
/
test_project.py
File metadata and controls
109 lines (80 loc) · 2.65 KB
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
import pytest
import os
import sys
from ruamel import yaml
try:
import sh
except ImportError:
pass
def load_yaml(filename):
"""Return object in yaml file."""
with open(filename) as myfile:
content = myfile.read()
if "win" in sys.platform:
content = content.replace("\\", "/")
return yaml.safe_load(content)
def test_project(cookies):
project = cookies.bake()
assert project.exit_code == 0
assert project.exception is None
assert project.project.basename == 'my_python_project'
assert project.project.isdir()
@pytest.mark.skipif(sys.platform.startswith('win'),
reason='Skipping test with sh-module on Windows')
def test_install(cookies):
project = cookies.bake()
assert project.exit_code == 0
assert project.exception is None
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'install'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
@pytest.mark.skipif(sys.platform.startswith('win'),
reason='Skipping test with sh-module on Windows')
def test_running_tests(cookies):
project = cookies.bake()
assert project.exit_code == 0
assert project.exception is None
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'test'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
@pytest.mark.skipif(sys.platform.startswith('win'),
reason='Skipping test with sh-module on Windows')
def test_building_documentation_no_apidocs(cookies):
project = cookies.bake()
assert project.exit_code == 0
assert project.exception is None
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'build_sphinx'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
@pytest.mark.skipif(sys.platform.startswith('win'),
reason='Skipping test with sh-module on Windows')
def test_building_documentation_apidocs(cookies):
project = cookies.bake(extra_context={'apidoc': 'yes'})
assert project.exit_code == 0
assert project.exception is None
cwd = os.getcwd()
os.chdir(str(project.project))
try:
sh.python(['setup.py', 'build_sphinx'])
except sh.ErrorReturnCode as e:
pytest.fail(e)
finally:
os.chdir(cwd)
apidocs = project.project.join('docs', '_build', 'html', 'apidocs')
assert apidocs.join('my_python_project.html').isfile()
assert apidocs.join('my_python_project.my_python_project.html').isfile()