Skip to content
This repository was archived by the owner on Jun 15, 2021. It is now read-only.

Commit 6458127

Browse files
committed
Add testing
1 parent 90c0342 commit 6458127

8 files changed

+144
-43
lines changed

.coveragerc.example

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[run]
2+
branch = True
3+
source =
4+
django_package_template
5+
6+
omit =
7+
*/django_package_template/migrations/*
8+
*/tests/*
9+
*/.tox/*
10+
*/bin/*
11+
*/test/*
12+
runtests.py
13+
14+
[report]
15+
exclude_lines =
16+
if self.debug:
17+
pragma: no cover
18+
raise NotImplementedError
19+
if __name__ == .__main__.:
20+
def __repr__
21+
raise AssertionError
22+
23+
ignore_errors = True

.travis.yml.example

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
1-
dist: xenial
21
language: python
3-
4-
python:
5-
- "3.6"
6-
7-
services:
8-
- docker
9-
10-
before_install:
11-
- export DJANGO_SETTINGS_MODULE=app.settings
12-
- export EXTENSIONS=unknown_app
13-
2+
sudo: false
3+
cache: pip
4+
dist: xenial
145
install:
15-
- pip install -e django_package_template
16-
- django-admin startproject app
17-
- cp conf/settings.py app/app/settings.py
18-
- pip3 install coverage python-coveralls sphinx-markdown-tables django-extensions ipython notebook
19-
- cd app/
20-
- python3 manage.py migrate
21-
- cd ../
22-
23-
24-
jobs:
6+
- pip install coveralls>=1.1 tox
7+
script:
8+
- tox
9+
after_success:
10+
coveralls
11+
matrix:
2512
include:
26-
- stage: test
27-
script:
28-
- cd app/
29-
- coverage run --omit=**/tests.py,./install/*,./launcher,**/wsgi.py,**/manage.py --source=. ./manage.py test django_package_template --noinput --settings=app.settings
13+
- env: TOXENV=py36
14+
python: '3.6.7'
File renamed without changes.

manage.py

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
example_files = [
1111
'.travis.yml',
1212
'setup.py',
13-
'mkdocs.yml'
13+
'mkdocs.yml',
14+
'tox.ini',
15+
'MANIFEST.in',
16+
'.coveragerc'
1417
]
1518

1619
get_package_name = subprocess.run(
@@ -51,11 +54,30 @@ def commands_succeeded(rcs):
5154

5255
@manager.command
5356
def echo():
57+
"""Echo package directory."""
5458
print(dir_path)
5559

5660

61+
@manager.command
62+
def deploy():
63+
"""Deploy package and docs. Type in username and password for PyPi."""
64+
commands = [
65+
"python3 setup.py sdist",
66+
"python3 -m twine upload dist/*",
67+
"python3 -m mkdocs gh-deploy"
68+
]
69+
command_rcs = set()
70+
for command in commands:
71+
print(command)
72+
command_rcs.add(subprocess.run(
73+
[command],
74+
stdout=subprocess.PIPE,
75+
shell=True).returncode)
76+
77+
5778
@manager.command
5879
def venv():
80+
"""Create a virtual environment."""
5981
command_rc = subprocess.run(
6082
[f"python3 -m venv {dir_path}/venv"],
6183
stdout=subprocess.PIPE,
@@ -66,8 +88,9 @@ def venv():
6688
exit()
6789

6890

69-
@manager.command
70-
def initialize():
91+
@ manager.command
92+
def init():
93+
"""Initialize the project."""
7194
# Create application
7295
create_project = subprocess.run(
7396
[f"django-admin startapp {app_name}"],
@@ -125,8 +148,26 @@ def initialize():
125148
print("Successfully initialized project")
126149

127150

128-
@manager.command
129-
def scorched_earth():
151+
@ manager.command
152+
def prune():
153+
"""Prune all .example files. WARNING: Init will no longer function."""
154+
for example_files in example_files:
155+
command_rcs = set()
156+
command = f'rm -rf {dir_path}/{example_file}.example'
157+
print(command)
158+
159+
command_rcs.add(subprocess.run(
160+
[command],
161+
stdout=subprocess.PIPE,
162+
shell=True
163+
).returncode)
164+
if not commands_succeeded(command_rcs):
165+
print("Failed to clear files")
166+
exit()
167+
168+
@ manager.command
169+
def purge():
170+
"""Purge all created files."""
130171
for example_file in example_files:
131172
command_rcs = set()
132173
command = f'rm -rf {dir_path}/{example_file}'
@@ -152,16 +193,29 @@ def scorched_earth():
152193
print("Failed to clear files")
153194
exit()
154195

155-
command = f'rm -rf {dir_path}/venv'
156-
print(command)
157-
command_rcs.add(subprocess.run(
158-
[command],
159-
stdout=subprocess.PIPE,
160-
shell=True
161-
).returncode)
162-
if not commands_succeeded(command_rcs):
163-
print("Failed to clear files")
164-
exit()
196+
extra_files = [
197+
'coverage.xml',
198+
'dist',
199+
'.coverage',
200+
'*.egg-info',
201+
'site',
202+
'.tox',
203+
'venv'
204+
]
205+
206+
for example_file in extra_files:
207+
command_rcs = set()
208+
command = f'rm -rf {dir_path}/{example_file}'
209+
print(command)
210+
211+
command_rcs.add(subprocess.run(
212+
[command],
213+
stdout=subprocess.PIPE,
214+
shell=True
215+
).returncode)
216+
if not commands_succeeded(command_rcs):
217+
print("Failed to clear files")
218+
exit()
165219

166220

167221
if __name__ == '__main__':

runtests.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ['DJANGO_SETTINGS_MODULE'] = 'test.app.settings'
7+
print(os.getcwd())
8+
try:
9+
from django.core.management import execute_from_command_line
10+
except ImportError:
11+
try:
12+
import django
13+
except ImportError:
14+
raise ImportError(
15+
"Couldn't import Django. Are you sure it's installed and "
16+
"available on your PYTHONPATH environment variable? Did you "
17+
"forget to activate a virtual environment?"
18+
)
19+
raise
20+
execute_from_command_line(sys.argv.insert(1, 'test'))

setup.py.example

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import os
22
from setuptools import find_packages, setup
33

4+
install_requires = [
5+
'Django'
6+
]
7+
48
with open(os.path.join(os.path.dirname(__file__), 'README.md')) as readme:
59
README = readme.read()
610

@@ -32,6 +36,5 @@ setup(
3236
'Topic :: Internet :: WWW/HTTP',
3337
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
3438
],
35-
install_requires=[
36-
]
39+
install_requires=install_requires
3740
)

test/__init__.py

Whitespace-only changes.

tox.ini.example

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[tox]
2+
envlist = py36
3+
[testenv]
4+
setenv =
5+
DJANGO_SETTINGS_MODULE = tests.app.settings
6+
7+
deps=
8+
Django
9+
coverage
10+
.[test]
11+
12+
commands =
13+
pip freeze
14+
coverage run runtests.py
15+
coverage report -m
16+
coverage xml

0 commit comments

Comments
 (0)