From 18ba79ea15a017a2ae763f9519eec3e2f9cbd2ff Mon Sep 17 00:00:00 2001 From: David D Lowe Date: Wed, 21 Dec 2016 18:16:26 +0100 Subject: [PATCH 1/5] Add runtests.py --- runtests.py | 35 +++++++++++++++++++++++++++++++++++ tests/settings.py | 8 ++++++++ 2 files changed, 43 insertions(+) create mode 100644 runtests.py diff --git a/runtests.py b/runtests.py new file mode 100644 index 0000000..f0d236f --- /dev/null +++ b/runtests.py @@ -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() diff --git a/tests/settings.py b/tests/settings.py index 75ae085..15cd71f 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -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') From bfdcc6e2d68e11b842e3c9d4560368fca6594e37 Mon Sep 17 00:00:00 2001 From: David D Lowe Date: Thu, 22 Dec 2016 10:37:19 +0100 Subject: [PATCH 2/5] Add tox.ini Now just run `tox` to run the tests against different versions of Python and Django. --- .gitignore | 3 +++ tox.ini | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 6d920a6..34dc4cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ /dist /docs/build +*.pyc +__pycache__ +.tox diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..23ee04f --- /dev/null +++ b/tox.ini @@ -0,0 +1,7 @@ +[tox] +envlist = + {py27}-django-{18,19,110} + {py35}-django-{18,19,110} + +[testenv] +commands = python runtests.py From 253d46ac06e270a274be70453e82d4a1b6800bb5 Mon Sep 17 00:00:00 2001 From: David D Lowe Date: Thu, 22 Dec 2016 10:37:49 +0100 Subject: [PATCH 3/5] Add .travis.yml For integration with travis-ci.org --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..eaf6e30 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +sudo: false +language: python +python: + - "2.7" + - "3.5" +install: pip install tox-travis +script: tox From 981efd018b0d6ad82a2fd15281f1cc7c3a03eac3 Mon Sep 17 00:00:00 2001 From: David D Lowe Date: Thu, 22 Dec 2016 10:47:57 +0100 Subject: [PATCH 4/5] Initialize Terminal object later This is so that a fully featured terminal is not required merely for an import, allowing the tests to pass. --- staticbuilder/management/commands/buildstatic.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/staticbuilder/management/commands/buildstatic.py b/staticbuilder/management/commands/buildstatic.py index c4d9b2c..3cfcefb 100644 --- a/staticbuilder/management/commands/buildstatic.py +++ b/staticbuilder/management/commands/buildstatic.py @@ -10,9 +10,6 @@ import subprocess -t = Terminal() - - class Command(BaseCommand): """ Executes the shell commands in ``STATICBUILDER_BUILD_COMMANDS`` @@ -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')) @@ -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: @@ -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) From 9d0ef843381fd0edc8557cf904dcad4fec3f9aca Mon Sep 17 00:00:00 2001 From: David D Lowe Date: Tue, 27 Dec 2016 18:05:37 +0100 Subject: [PATCH 5/5] Test Python 3.6 --- .travis.yml | 1 + tox.ini | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index eaf6e30..502744e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,5 +3,6 @@ language: python python: - "2.7" - "3.5" + - "3.6" install: pip install tox-travis script: tox diff --git a/tox.ini b/tox.ini index 23ee04f..feb2e9e 100644 --- a/tox.ini +++ b/tox.ini @@ -2,6 +2,7 @@ envlist = {py27}-django-{18,19,110} {py35}-django-{18,19,110} + {py36}-django-{18,19,110} [testenv] commands = python runtests.py