Skip to content

Commit 214c989

Browse files
authored
Merge pull request #138 from NLeSC/101-test-fixes
thanks!
2 parents b809889 + b10bf70 commit 214c989

8 files changed

Lines changed: 19 additions & 268 deletions

File tree

requirements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
cookiecutter==1.7.2
2-
sh
32

43
# Testing
54
pytest<5.0.0,>=3.3.0
65
pytest-cookies
7-
pycodestyle
8-
ruamel.yaml

tests/test_lint.py

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/test_project.py

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,10 @@
11
import pytest
2-
import os
3-
import sys
42

5-
from ruamel import yaml
63

7-
try:
8-
import sh
9-
except ImportError:
10-
pass
11-
12-
13-
def load_yaml(filename):
14-
"""Return object in yaml file."""
15-
with open(filename) as myfile:
16-
content = myfile.read()
17-
if "win" in sys.platform:
18-
content = content.replace("\\", "/")
19-
return yaml.safe_load(content)
20-
21-
22-
def test_project(cookies):
4+
def test_project_folder(cookies):
235
project = cookies.bake()
246

257
assert project.exit_code == 0
268
assert project.exception is None
279
assert project.project.basename == 'my_python_project'
2810
assert project.project.isdir()
29-
30-
31-
@pytest.mark.skipif(sys.platform.startswith('win'),
32-
reason='Skipping test with sh-module on Windows')
33-
def test_install(cookies):
34-
project = cookies.bake()
35-
36-
assert project.exit_code == 0
37-
assert project.exception is None
38-
39-
cwd = os.getcwd()
40-
os.chdir(str(project.project))
41-
42-
try:
43-
sh.python(['setup.py', 'install'])
44-
except sh.ErrorReturnCode as e:
45-
pytest.fail(e)
46-
finally:
47-
os.chdir(cwd)
48-
49-
50-
@pytest.mark.skipif(sys.platform.startswith('win'),
51-
reason='Skipping test with sh-module on Windows')
52-
def test_running_tests(cookies):
53-
project = cookies.bake()
54-
55-
assert project.exit_code == 0
56-
assert project.exception is None
57-
58-
cwd = os.getcwd()
59-
os.chdir(str(project.project))
60-
61-
try:
62-
sh.python(['setup.py', 'test'])
63-
except sh.ErrorReturnCode as e:
64-
pytest.fail(e)
65-
finally:
66-
os.chdir(cwd)
67-
68-
69-
@pytest.mark.skipif(sys.platform.startswith('win'),
70-
reason='Skipping test with sh-module on Windows')
71-
def test_building_documentation_no_apidocs(cookies):
72-
project = cookies.bake()
73-
74-
assert project.exit_code == 0
75-
assert project.exception is None
76-
77-
cwd = os.getcwd()
78-
os.chdir(str(project.project))
79-
80-
try:
81-
sh.python(['setup.py', 'build_sphinx'])
82-
except sh.ErrorReturnCode as e:
83-
pytest.fail(e)
84-
finally:
85-
os.chdir(cwd)
86-
87-
88-
@pytest.mark.skipif(sys.platform.startswith('win'),
89-
reason='Skipping test with sh-module on Windows')
90-
def test_building_documentation_apidocs(cookies):
91-
project = cookies.bake(extra_context={'apidoc': 'yes'})
92-
93-
assert project.exit_code == 0
94-
assert project.exception is None
95-
96-
cwd = os.getcwd()
97-
os.chdir(str(project.project))
98-
99-
try:
100-
sh.python(['setup.py', 'build_sphinx'])
101-
except sh.ErrorReturnCode as e:
102-
pytest.fail(e)
103-
finally:
104-
os.chdir(cwd)
105-
106-
apidocs = project.project.join('docs', '_build', 'html', 'apidocs')
107-
108-
assert apidocs.join('my_python_project.html').isfile()
109-
assert apidocs.join('my_python_project.my_python_project.html').isfile()

tests/test_values.py

Lines changed: 14 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,39 @@
11
import pytest
2-
import os
3-
import sys
42

5-
try:
6-
import sh
7-
except ImportError:
8-
pass
93

10-
11-
@pytest.mark.skipif(sys.platform.startswith('win'),
12-
reason='Skipping test with sh-module on Windows')
134
def test_double_quotes_in_name_and_description(cookies):
14-
ctx = {'project_short_description': '"double quotes"',
15-
'full_name': '"name"name'}
5+
ctx = {
6+
"project_short_description": '"double quotes"',
7+
"full_name": '"name"name'
8+
}
169
project = cookies.bake(extra_context=ctx)
1710

1811
assert project.exit_code == 0
1912

20-
with open(os.path.join(str(project.project), 'setup.py')) as f:
21-
setup = f.read()
22-
print(setup)
23-
24-
cwd = os.getcwd()
25-
os.chdir(str(project.project))
26-
27-
try:
28-
sh.python(['setup.py', 'install'])
29-
except sh.ErrorReturnCode as e:
30-
pytest.fail(e)
31-
finally:
32-
os.chdir(cwd)
33-
3413

35-
@pytest.mark.skipif(sys.platform.startswith('win'),
36-
reason='Skipping test with sh-module on Windows')
3714
def test_single_quotes_in_name_and_description(cookies):
38-
ctx = {'project_short_description': "'single quotes'",
39-
'full_name': "Mr. O'Keeffe"}
15+
ctx = {
16+
"project_short_description": "'single quotes'",
17+
"full_name": "Mr. O'Keeffe"
18+
}
4019
project = cookies.bake(extra_context=ctx)
4120

4221
assert project.exit_code == 0
4322

44-
with open(os.path.join(str(project.project), 'setup.py')) as f:
45-
setup = f.read()
46-
print(setup)
47-
48-
cwd = os.getcwd()
49-
os.chdir(str(project.project))
50-
51-
try:
52-
sh.python(['setup.py', 'install'])
53-
except sh.ErrorReturnCode as e:
54-
pytest.fail(e)
55-
finally:
56-
os.chdir(cwd)
57-
5823

59-
@pytest.mark.skipif(sys.platform.startswith('win'),
60-
reason='Skipping test with sh-module on Windows')
6124
def test_dash_in_project_slug(cookies):
62-
ctx = {'project_slug': "my-package"}
25+
ctx = {
26+
"project_slug": "my-package"
27+
}
6328
project = cookies.bake(extra_context=ctx)
6429

6530
assert project.exit_code == 0
6631

67-
with open(os.path.join(str(project.project), 'setup.py')) as f:
68-
setup = f.read()
69-
print(setup)
7032

71-
cwd = os.getcwd()
72-
os.chdir(str(project.project))
73-
74-
try:
75-
sh.python(['setup.py', 'install'])
76-
sh.python(['setup.py', 'build_sphinx'])
77-
except sh.ErrorReturnCode as e:
78-
pytest.fail(e)
79-
finally:
80-
os.chdir(cwd)
81-
82-
83-
@pytest.mark.skipif(sys.platform.startswith('win'),
84-
reason='Skipping test with sh-module on Windows')
8533
def test_space_in_project_slug(cookies):
86-
ctx = {'project_slug': "my package"}
34+
ctx = {
35+
"project_slug": "my package"
36+
}
8737
project = cookies.bake(extra_context=ctx)
8838

8939
assert project.exit_code == 0
90-
91-
with open(os.path.join(str(project.project), 'setup.py')) as f:
92-
setup = f.read()
93-
print(setup)
94-
95-
cwd = os.getcwd()
96-
os.chdir(str(project.project))
97-
98-
try:
99-
sh.python(['setup.py', 'install'])
100-
sh.python(['setup.py', 'build_sphinx'])
101-
except sh.ErrorReturnCode as e:
102-
pytest.fail(e)
103-
finally:
104-
os.chdir(cwd)

{{cookiecutter.project_slug}}/.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ jobs:
4040
- name: Test
4141
shell: bash -l {0}
4242
run: |
43-
python setup.py test
43+
pytest tests
4444
pytest --cov --cov-report term --cov-report xml --junitxml=xunit-result.xml

{{cookiecutter.project_slug}}/docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
import os
1818
import sys
1919

20-
import {{ cookiecutter.project_slug.lower().replace(" ", "_").replace("-", "_")}}
21-
2220
here = os.path.dirname(__file__)
2321
sys.path.insert(0, os.path.abspath(os.path.join(here, "..")))
2422

23+
import {{ cookiecutter.project_slug.lower().replace(" ", "_").replace("-", "_")}}
24+
2525

2626
# -- General configuration ------------------------------------------------
2727

{{cookiecutter.project_slug}}/tests/test_lint.py

Lines changed: 0 additions & 43 deletions
This file was deleted.
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
import os
2-
import sys
3-
4-
# To update the package version number, edit CITATION.cff
5-
citationfile = os.path.join(sys.exec_prefix, "citation/{{ cookiecutter.project_slug.lower().replace(" ", "_").replace("-", "_")}}", "CITATION.cff")
6-
with open(citationfile, "r") as cff:
7-
for line in cff:
8-
if "version:" in line:
9-
__version__ = line.replace("version:", "").strip().strip('"')
1+
__version__ = "{{ cookiecutter.version }}"

0 commit comments

Comments
 (0)