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/.travis.yml b/.travis.yml new file mode 100644 index 0000000..502744e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,8 @@ +sudo: false +language: python +python: + - "2.7" + - "3.5" + - "3.6" +install: pip install tox-travis +script: tox 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/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) 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') diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..feb2e9e --- /dev/null +++ b/tox.ini @@ -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