Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic tests #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/dist
/docs/build
*.pyc
__pycache__
.tox
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sudo: false
language: python
python:
- "2.7"
- "3.5"
- "3.6"
install: pip install tox-travis
script: tox
35 changes: 35 additions & 0 deletions runtests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from __future__ import unicode_literals, print_function, division, absolute_import
import django
import os
import sys


BASE_DIR = os.path.dirname(os.path.abspath(__file__))


def test_files_import():
count_files = 0
for root, dirs, files in os.walk(os.path.join(BASE_DIR, "staticbuilder")):
for filename in files:
if filename.endswith(".py"):
import_filename(os.path.join(root, filename))
count_files += 1
if not count_files:
raise Exception("No .py files found")


def import_filename(filename):
module = ".".join(filter(None, filename.replace(BASE_DIR, "", 1).split(os.sep)))[:-3]
if module.endswith(".__init__"):
module = module[:-9]
try:
__import__(module)
except:
print("Cannot import module %s" % module, file=sys.stderr)
raise


if __name__ == "__main__":
os.environ["DJANGO_SETTINGS_MODULE"] = "tests.settings"
django.setup()
test_files_import()
11 changes: 6 additions & 5 deletions staticbuilder/management/commands/buildstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
import subprocess


t = Terminal()


class Command(BaseCommand):
"""
Executes the shell commands in ``STATICBUILDER_BUILD_COMMANDS``
Expand All @@ -34,6 +31,10 @@ class Command(BaseCommand):
help='Skip collecting static files for build'),
)

def __init__(self, *args, **kwargs):
super(Command, self).__init__(*args, **kwargs)
self.t = Terminal()

def handle(self, *args, **options):

self.verbosity = int(options.get('verbosity', '1'))
Expand All @@ -59,7 +60,7 @@ def handle(self, *args, **options):
os.utime(build_dir, None)

def shell(self, cmd):
self.log(t.bold('Running command: ') + cmd)
self.log(self.t.bold('Running command: ') + cmd)

return_code = subprocess.call(cmd, shell=True)
if return_code:
Expand All @@ -73,6 +74,6 @@ def log(self, msg, level=1):
if not msg.endswith("\n"):
msg += "\n"
if level > 1:
msg = t.bright_black(msg)
msg = self.t.bright_black(msg)
if self.verbosity >= level:
self.stdout.write(msg)
8 changes: 8 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

SECRET_KEY = 'zomk1gko4kyiy(v^el6)id#h-#8rocoyvpnt$c6f#=-$c=qdx!'

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'testdb'
}
}

STATICBUILDER_BUILD_ROOT = os.path.join(BASE_DIR, 'build_root')
8 changes: 8 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[tox]
envlist =
{py27}-django-{18,19,110}
{py35}-django-{18,19,110}
{py36}-django-{18,19,110}

[testenv]
commands = python runtests.py