From d8ac62872398bfa6f88b4d2345b54bcd44fc940c Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Tue, 6 Dec 2011 21:17:40 +0100 Subject: [PATCH] Moved tests in correct app test package. --- compressor/test_settings.py | 30 +++++++++++++++++ compressor/tests/__init__.py | 16 +++++++++ compressor/tests/{tests => }/base.py | 2 +- compressor/tests/{tests => }/filters.py | 5 ++- compressor/tests/{tests => }/jinja2ext.py | 3 +- compressor/tests/models.py | 0 compressor/tests/{tests => }/offline.py | 16 ++++++--- compressor/tests/{tests => }/parsers.py | 3 +- compressor/tests/settings.py | 35 -------------------- compressor/tests/{tests => }/signals.py | 0 compressor/tests/{tests => }/storages.py | 5 ++- compressor/tests/{tests => }/templatetags.py | 3 +- compressor/tests/tests/__init__.py | 18 ---------- tox.ini | 4 +-- 14 files changed, 67 insertions(+), 73 deletions(-) create mode 100644 compressor/test_settings.py rename compressor/tests/{tests => }/base.py (99%) rename compressor/tests/{tests => }/filters.py (99%) rename compressor/tests/{tests => }/jinja2ext.py (99%) delete mode 100644 compressor/tests/models.py rename compressor/tests/{tests => }/offline.py (95%) rename compressor/tests/{tests => }/parsers.py (98%) rename compressor/tests/{tests => }/signals.py (100%) rename compressor/tests/{tests => }/storages.py (95%) rename compressor/tests/{tests => }/templatetags.py (99%) delete mode 100644 compressor/tests/tests/__init__.py diff --git a/compressor/test_settings.py b/compressor/test_settings.py new file mode 100644 index 0000000..06822e1 --- /dev/null +++ b/compressor/test_settings.py @@ -0,0 +1,30 @@ +import os + +TEST_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'tests') + +COMPRESS_CACHE_BACKEND = 'locmem://' + +DATABASE_ENGINE = 'sqlite3' + +INSTALLED_APPS = [ + 'compressor', + 'django_jenkins', +] + +MEDIA_URL = '/media/' + +MEDIA_ROOT = os.path.join(TEST_DIR, 'media') + +TEMPLATE_DIRS = ( + # Specifically choose a name that will not be considered + # by app_directories loader, to make sure each test uses + # a specific template without considering the others. + os.path.join(TEST_DIR, 'test_templates'), +) + +JENKINS_TASKS = ( + 'django_jenkins.tasks.run_pyflakes', + 'django_jenkins.tasks.run_pep8', + 'django_jenkins.tasks.with_coverage', + 'django_jenkins.tasks.django_tests', +) diff --git a/compressor/tests/__init__.py b/compressor/tests/__init__.py index e69de29..026af4d 100644 --- a/compressor/tests/__init__.py +++ b/compressor/tests/__init__.py @@ -0,0 +1,16 @@ +from compressor.tests.base import (CompressorTestCase, CssMediaTestCase, + VerboseTestCase, CacheBackendTestCase) +from compressor.tests.filters import (CssTidyTestCase, PrecompilerTestCase, + CssMinTestCase, CssAbsolutizingTestCase, CssAbsolutizingTestCaseWithHash, + CssDataUriTestCase) +from compressor.tests.jinja2ext import TestJinja2CompressorExtension +from compressor.tests.offline import ( + OfflineGenerationBlockSuperTestCase, OfflineGenerationConditionTestCase, + OfflineGenerationTemplateTagTestCase, OfflineGenerationTestCaseWithContext, + OfflineGenerationTestCaseErrors, OfflineGenerationTestCase) +from compressor.tests.parsers import (LxmlParserTests, Html5LibParserTests, + BeautifulSoupParserTests, HtmlParserTests) +from compressor.tests.signals import PostCompressSignalTestCase +from compressor.tests.storages import StorageTestCase +from compressor.tests.templatetags import (TemplatetagTestCase, + PrecompilerTemplatetagTestCase) diff --git a/compressor/tests/tests/base.py b/compressor/tests/base.py similarity index 99% rename from compressor/tests/tests/base.py rename to compressor/tests/base.py index 097fabe..e8d5268 100644 --- a/compressor/tests/tests/base.py +++ b/compressor/tests/base.py @@ -19,7 +19,7 @@ def css_tag(href, **kwargs): return template % (href, rendered_attrs) -test_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) +test_dir = os.path.abspath(os.path.join(os.path.dirname(__file__))) class CompressorTestCase(TestCase): diff --git a/compressor/tests/tests/filters.py b/compressor/tests/filters.py similarity index 99% rename from compressor/tests/tests/filters.py rename to compressor/tests/filters.py index 92fd551..d904180 100644 --- a/compressor/tests/tests/filters.py +++ b/compressor/tests/filters.py @@ -12,8 +12,7 @@ from compressor.utils import find_command from compressor.filters.base import CompilerFilter from compressor.filters.cssmin import CSSMinFilter from compressor.filters.css_default import CssAbsoluteFilter - -from .base import test_dir +from compressor.tests.base import test_dir class CssTidyTestCase(TestCase): @@ -30,7 +29,7 @@ color: black; CssTidyTestCase = skipIf( find_command(settings.COMPRESS_CSSTIDY_BINARY) is None, - 'CSStidy binary %r not found' % settings.COMPRESS_CSSTIDY_BINARY + 'CSStidy binary %r not found' % settings.COMPRESS_CSSTIDY_BINARY, )(CssTidyTestCase) diff --git a/compressor/tests/tests/jinja2ext.py b/compressor/tests/jinja2ext.py similarity index 99% rename from compressor/tests/tests/jinja2ext.py rename to compressor/tests/jinja2ext.py index f3fe028..c5a0495 100644 --- a/compressor/tests/tests/jinja2ext.py +++ b/compressor/tests/jinja2ext.py @@ -5,8 +5,7 @@ from django.test import TestCase import jinja2 from compressor.conf import settings - -from .base import css_tag +from compressor.tests.base import css_tag class TestJinja2CompressorExtension(TestCase): diff --git a/compressor/tests/models.py b/compressor/tests/models.py deleted file mode 100644 index e69de29..0000000 diff --git a/compressor/tests/tests/offline.py b/compressor/tests/offline.py similarity index 95% rename from compressor/tests/tests/offline.py rename to compressor/tests/offline.py index 7538a12..9f0fabc 100644 --- a/compressor/tests/tests/offline.py +++ b/compressor/tests/offline.py @@ -14,13 +14,13 @@ from compressor.exceptions import OfflineGenerationError from compressor.management.commands.compress import Command as CompressCommand from compressor.storage import default_storage -from .base import css_tag -class OfflineTestCaseMixin(): +class OfflineTestCaseMixin(object): template_name = "test_compressor_offline.html" - templates_dir = "" # Change this for each test class, to separate templates - expected_hash = "" # Change this for each test class to the expected result verbosity = 0 + # Change this for each test class + templates_dir = "" + expected_hash = "" def setUp(self): self._old_compress = settings.COMPRESS_ENABLED @@ -62,10 +62,12 @@ class OfflineTestCaseMixin(): rendered_template = self.template.render(Context(settings.COMPRESS_OFFLINE_CONTEXT)) self.assertEqual(rendered_template, "".join(result) + "\n") + class OfflineGenerationBlockSuperTestCase(OfflineTestCaseMixin, TestCase): templates_dir = "test_block_super" expected_hash = "7c02d201f69d" + class OfflineGenerationConditionTestCase(OfflineTestCaseMixin, TestCase): templates_dir = "test_condition" expected_hash = "4e3758d50224" @@ -81,10 +83,12 @@ class OfflineGenerationConditionTestCase(OfflineTestCaseMixin, TestCase): self.COMPRESS_OFFLINE_CONTEXT = self.old_offline_context super(OfflineGenerationConditionTestCase, self).tearDown() + class OfflineGenerationTemplateTagTestCase(OfflineTestCaseMixin, TestCase): templates_dir = "test_templatetag" expected_hash = "a27e1d3a619a" + class OfflineGenerationTestCaseWithContext(OfflineTestCaseMixin, TestCase): templates_dir = "test_with_context" expected_hash = "5838e2fd66af" @@ -99,11 +103,13 @@ class OfflineGenerationTestCaseWithContext(OfflineTestCaseMixin, TestCase): def tearDown(self): self.COMPRESS_OFFLINE_CONTEXT = self.old_offline_context super(OfflineGenerationTestCaseWithContext, self).tearDown() - + + class OfflineGenerationTestCaseErrors(OfflineTestCaseMixin, TestCase): templates_dir = "test_error_handling" expected_hash = "cd8870829421" + class OfflineGenerationTestCase(OfflineTestCaseMixin, TestCase): templates_dir = "basic" expected_hash = "f5e179b8eca4" diff --git a/compressor/tests/tests/parsers.py b/compressor/tests/parsers.py similarity index 98% rename from compressor/tests/tests/parsers.py rename to compressor/tests/parsers.py index e04a28f..dba2a5a 100644 --- a/compressor/tests/tests/parsers.py +++ b/compressor/tests/parsers.py @@ -21,8 +21,7 @@ except ImportError: from compressor.base import SOURCE_HUNK, SOURCE_FILE from compressor.conf import settings from compressor.css import CssCompressor - -from .base import CompressorTestCase +from compressor.tests.base import CompressorTestCase class ParserTestCase(object): diff --git a/compressor/tests/settings.py b/compressor/tests/settings.py index 151f68b..e69de29 100644 --- a/compressor/tests/settings.py +++ b/compressor/tests/settings.py @@ -1,35 +0,0 @@ -import os - -TEST_DIR = os.path.dirname(os.path.abspath(__file__)) - -COMPRESS_CACHE_BACKEND = 'locmem://' - -DATABASE_ENGINE = 'sqlite3' - -INSTALLED_APPS = [ - 'django.contrib.contenttypes', - 'django.contrib.sites', - 'django.contrib.auth', - 'django.contrib.admin', - 'django_jenkins', - 'compressor', - 'tests', -] - -MEDIA_URL = '/media/' - -MEDIA_ROOT = os.path.join(TEST_DIR, 'media') - -TEMPLATE_DIRS = ( - # Specifically choose a name that will not be considered - # by app_directories loader, to make sure each test uses - # a specific template without considering the others. - os.path.join(TEST_DIR, 'test_templates'), -) - -JENKINS_TASKS = ( - 'django_jenkins.tasks.run_pyflakes', - 'django_jenkins.tasks.run_pep8', - 'django_jenkins.tasks.with_coverage', - 'django_jenkins.tasks.django_tests', -) diff --git a/compressor/tests/tests/signals.py b/compressor/tests/signals.py similarity index 100% rename from compressor/tests/tests/signals.py rename to compressor/tests/signals.py diff --git a/compressor/tests/tests/storages.py b/compressor/tests/storages.py similarity index 95% rename from compressor/tests/tests/storages.py rename to compressor/tests/storages.py index ae43b85..d0a33e7 100644 --- a/compressor/tests/tests/storages.py +++ b/compressor/tests/storages.py @@ -8,9 +8,8 @@ from django.test import TestCase from compressor import base from compressor.conf import settings - -from .base import css_tag -from .templatetags import render +from compressor.tests.base import css_tag +from compressor.tests.templatetags import render class StorageTestCase(TestCase): diff --git a/compressor/tests/tests/templatetags.py b/compressor/tests/templatetags.py similarity index 99% rename from compressor/tests/tests/templatetags.py rename to compressor/tests/templatetags.py index ed31586..54e0ed7 100644 --- a/compressor/tests/tests/templatetags.py +++ b/compressor/tests/templatetags.py @@ -10,8 +10,7 @@ from django.test import TestCase from compressor.conf import settings from compressor.signals import post_compress - -from .base import css_tag, test_dir +from compressor.tests.base import css_tag, test_dir def render(template_string, context_dict=None): diff --git a/compressor/tests/tests/__init__.py b/compressor/tests/tests/__init__.py deleted file mode 100644 index b4ddd48..0000000 --- a/compressor/tests/tests/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -from .base import (CompressorTestCase, CssMediaTestCase, VerboseTestCase, - CacheBackendTestCase) -from .filters import (CssTidyTestCase, PrecompilerTestCase, CssMinTestCase, - CssAbsolutizingTestCase, CssAbsolutizingTestCaseWithHash, - CssDataUriTestCase) -from .jinja2ext import TestJinja2CompressorExtension -from .offline import ( - OfflineGenerationBlockSuperTestCase, - OfflineGenerationConditionTestCase, - OfflineGenerationTemplateTagTestCase, - OfflineGenerationTestCaseWithContext, - OfflineGenerationTestCaseErrors, - OfflineGenerationTestCase) -from .parsers import (LxmlParserTests, Html5LibParserTests, - BeautifulSoupParserTests, HtmlParserTests) -from .signals import PostCompressSignalTestCase -from .storages import StorageTestCase -from .templatetags import TemplatetagTestCase, PrecompilerTemplatetagTestCase diff --git a/tox.ini b/tox.ini index 01b106b..7542a70 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,9 @@ [testenv] downloadcache = {toxworkdir}/_download/ setenv = - DJANGO_SETTINGS_MODULE = compressor.tests.settings + DJANGO_SETTINGS_MODULE = compressor.test_settings commands = - {envbindir}/python {envbindir}/django-admin.py jenkins {posargs:tests} + {envbindir}/python {envbindir}/django-admin.py jenkins {posargs:compressor} [testenv:docs] basepython = python2.7