From 30a59664d6e4c3967dda9a1fbc27800bfd5cc59e Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 6 Sep 2016 18:48:50 +0300 Subject: [PATCH 1/8] Remove Django<1.8 compatibility safeguards --- django_babel/extract.py | 24 ++---------------------- django_babel/middleware.py | 5 +---- 2 files changed, 3 insertions(+), 26 deletions(-) diff --git a/django_babel/extract.py b/django_babel/extract.py index a34149a..3169ffb 100644 --- a/django_babel/extract.py +++ b/django_babel/extract.py @@ -1,31 +1,11 @@ # -*- coding: utf-8 -*- -try: - from django.template import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK -except ImportError: - # Django 1.8 moved most stuff to .base - from django.template.base import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK - -try: - from django.utils.translation import trim_whitespace as trim_django -except ImportError: - trim_django = False - +from django.template.base import Lexer, TOKEN_TEXT, TOKEN_VAR, TOKEN_BLOCK +from django.utils.translation import trim_whitespace from django.utils.encoding import smart_text from django.utils.translation.trans_real import ( inline_re, block_re, endblock_re, plural_re, constant_re) -def trim_whitespace(string): - """Trim whitespace. - - This is only supported in Django>=1.7. This method help in cases of older - Django versions. - """ - if trim_django: - return trim_django(string) - return string - - def join_tokens(tokens, trim=False): message = ''.join(tokens) if trim: diff --git a/django_babel/middleware.py b/django_babel/middleware.py index 5c3ac1c..16a618a 100644 --- a/django_babel/middleware.py +++ b/django_babel/middleware.py @@ -2,10 +2,7 @@ from babel import Locale, UnknownLocaleError from django.utils.translation import get_language -try: - from threading import local -except ImportError: - from django.utils._threading_local import local +from threading import local __all__ = ['get_current_locale', 'LocaleMiddleware'] From a46facb352ef747e8f15ecf813ad0d6d3c8821e1 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 6 Sep 2016 18:27:58 +0300 Subject: [PATCH 2/8] Add pytest-django and test things --- .gitignore | 1 + manage.py | 0 setup.cfg | 4 ++++ tests/__init__.py | 0 tests/settings.py | 23 +++++++++++++++++++++++ tests/templates/test.txt | 11 +++++++++++ tests/test_render.py | 26 ++++++++++++++++++++++++++ tests/urls.py | 18 ++++++++++++++++++ tox.ini | 1 + 9 files changed, 84 insertions(+) create mode 100644 manage.py create mode 100644 tests/__init__.py create mode 100644 tests/settings.py create mode 100644 tests/templates/test.txt create mode 100644 tests/test_render.py create mode 100644 tests/urls.py diff --git a/.gitignore b/.gitignore index b4c2573..5ba10f3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dist *.pyc django_babel.egg-info .tox +htmlcov diff --git a/manage.py b/manage.py new file mode 100644 index 0000000..e69de29 diff --git a/setup.cfg b/setup.cfg index 5e40900..6993de8 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,2 +1,6 @@ [wheel] universal = 1 + +[tool:pytest] +DJANGO_SETTINGS_MODULE = tests.settings +norecursedirs = .git .tox .eggs .cache htmlcov venv* diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/settings.py b/tests/settings.py new file mode 100644 index 0000000..decc0d4 --- /dev/null +++ b/tests/settings.py @@ -0,0 +1,23 @@ +SECRET_KEY = 'x' +USE_I18N = True +ROOT_URLCONF = 'tests.urls' +INSTALLED_APPS = [ + 'django_babel', + 'tests', +] +MIDDLEWARE_CLASSES = [ + 'django.middleware.locale.LocaleMiddleware', + 'django_babel.middleware.LocaleMiddleware', +] +TEMPLATES = [ + { + 'NAME': 'default', + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.i18n', + ], + }, + }, +] diff --git a/tests/templates/test.txt b/tests/templates/test.txt new file mode 100644 index 0000000..0283a6c --- /dev/null +++ b/tests/templates/test.txt @@ -0,0 +1,11 @@ +{% load babel %} +language_code={{ LANGUAGE_CODE }} +language_name={{ locale.language_name }} +date={{ date|datefmt }} +datetime={{ date|datetimefmt }} +time={{ date|timefmt }} +number={{ number|numberfmt }} +decimal={{ number|decimalfmt }} +currency={{ number|currencyfmt:"EUR" }} +percent={{ number|percentfmt }} +scientificfmt={{ number|scientificfmt }} diff --git a/tests/test_render.py b/tests/test_render.py new file mode 100644 index 0000000..61d8ddb --- /dev/null +++ b/tests/test_render.py @@ -0,0 +1,26 @@ +# -- encoding: utf-8 -- +from __future__ import unicode_literals + +import pytest + + +@pytest.mark.parametrize('locale', ('en', 'fi', 'sv', 'pt-BR')) +def test_babel_render(client, locale): + """ + Test the middleware and the rendery bits. + """ + response = client.get('/', HTTP_ACCEPT_LANGUAGE=locale) + # "Parse" the key-value format + lines = response.content.decode('utf-8').strip().splitlines() + content = dict(kv.split('=', 1) for kv in lines) + # See that we're rendering in the locale we expect + assert content['language_code'] == locale.lower() + # check that we could access `babel.Locale.language_name` + assert content['language_name'] == { + 'en': 'English', + 'fi': 'suomi', + 'sv': 'svenska', + 'pt-BR': 'português', + }[locale] + # The rest are not really tested (aside from smoke tests) further; + # the Babel test suite has taken care of that. diff --git a/tests/urls.py b/tests/urls.py new file mode 100644 index 0000000..2bf2501 --- /dev/null +++ b/tests/urls.py @@ -0,0 +1,18 @@ +import time + +from django.conf.urls import url +from django.shortcuts import render +from django.utils.timezone import now + + +def test_view(request): + return render(request, 'test.txt', { + 'date': now(), + 'number': time.time(), + 'locale': request.locale, + }) + + +urlpatterns = [ + url('^$', test_view), +] diff --git a/tox.ini b/tox.ini index fe5926c..4e341ea 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,7 @@ deps = coverage pytest pytest-cov + pytest-django python-coveralls django15: Django>=1.5,<1.6 django16: Django>=1.6,<1.7 From bdc6bd39483225ea1b9120b61e5888fd6de341c5 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 6 Sep 2016 18:49:09 +0300 Subject: [PATCH 3/8] Fix up the `babel` command: * Use `add_arguments` (`option_list` is old hat) * Add tests --- django_babel/management/commands/babel.py | 15 +++++---- tests/babel.cfg | 1 + tests/locale/en/LC_MESSAGES/.gitkeep | 0 tests/locale/fi/LC_MESSAGES/django.po | 8 +++++ tests/settings.py | 5 +++ tests/templates/test.txt | 3 +- tests/test_command.py | 37 +++++++++++++++++++++++ 7 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 tests/babel.cfg create mode 100644 tests/locale/en/LC_MESSAGES/.gitkeep create mode 100644 tests/locale/fi/LC_MESSAGES/django.po create mode 100644 tests/test_command.py diff --git a/django_babel/management/commands/babel.py b/django_babel/management/commands/babel.py index 240a453..a616bd4 100644 --- a/django_babel/management/commands/babel.py +++ b/django_babel/management/commands/babel.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- import os from distutils.dist import Distribution -from optparse import make_option from subprocess import call from django.core.management.base import LabelCommand, CommandError @@ -15,23 +14,23 @@ class Command(LabelCommand): args = '[makemessages] [compilemessages]' - option_list = LabelCommand.option_list + ( - make_option( - '--locale', '-l', default=None, dest='locale', action='append', + def add_arguments(self, parser): + super(Command, self).add_arguments(parser) + parser.add_argument( + '--locale', '-l', default=[], dest='locale', action='append', help=( 'Creates or updates the message files for the given locale(s)' ' (e.g pt_BR). Can be used multiple times.' ), - ), - make_option( + ) + parser.add_argument( '--domain', '-d', default='django', dest='domain', help='The domain of the message files (default: "django").', ), - make_option( + parser.add_argument( '--mapping-file', '-F', default=None, dest='mapping_file', help='Mapping file', ) - ) def handle_label(self, command, **options): if command not in ('makemessages', 'compilemessages'): diff --git a/tests/babel.cfg b/tests/babel.cfg new file mode 100644 index 0000000..3d87ef6 --- /dev/null +++ b/tests/babel.cfg @@ -0,0 +1 @@ +[django: templates/**.*] diff --git a/tests/locale/en/LC_MESSAGES/.gitkeep b/tests/locale/en/LC_MESSAGES/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/locale/fi/LC_MESSAGES/django.po b/tests/locale/fi/LC_MESSAGES/django.po new file mode 100644 index 0000000..94c7244 --- /dev/null +++ b/tests/locale/fi/LC_MESSAGES/django.po @@ -0,0 +1,8 @@ +# the header message is required to turn off the fuzzy bit for the catalog +msgid "" +msgstr "" + +#: tests/templates/test.txt:2 +msgid "This could be translated." +msgstr "Tämän voisi kääntää." + diff --git a/tests/settings.py b/tests/settings.py index decc0d4..38971b9 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -1,3 +1,5 @@ +import os + SECRET_KEY = 'x' USE_I18N = True ROOT_URLCONF = 'tests.urls' @@ -21,3 +23,6 @@ TEMPLATES = [ }, }, ] +LOCALE_PATHS = [ + os.path.join(os.path.dirname(__file__), 'locale'), +] diff --git a/tests/templates/test.txt b/tests/templates/test.txt index 0283a6c..2599688 100644 --- a/tests/templates/test.txt +++ b/tests/templates/test.txt @@ -1,4 +1,5 @@ -{% load babel %} +{% load i18n babel %} +text={% trans "This could be translated." %} language_code={{ LANGUAGE_CODE }} language_name={{ locale.language_name }} date={{ date|datefmt }} diff --git a/tests/test_command.py b/tests/test_command.py new file mode 100644 index 0000000..5cc04df --- /dev/null +++ b/tests/test_command.py @@ -0,0 +1,37 @@ +import os + +from django.core.management import call_command + +TEST_LOCALE_DIR = os.path.join( + os.path.dirname(__file__), + 'locale', +) + + +def test_babel_compilemessages(): + call_command( + 'babel', + 'compilemessages', + '-l', 'fi', + ) + # Assert that the .mo file was created by attempting to delete it. + os.unlink( + os.path.join(TEST_LOCALE_DIR, 'fi', 'LC_MESSAGES', 'django.mo') + ) + + +def test_babel_makemessages(): + call_command( + 'babel', + 'makemessages', + '-l', 'en', + '-F', os.path.join(os.path.dirname(__file__), 'babel.cfg'), + ) + # See that the expected files get populated with the discovered message + for path in [ + os.path.join(TEST_LOCALE_DIR, 'django.pot'), + os.path.join(TEST_LOCALE_DIR, 'en', 'LC_MESSAGES', 'django.po'), + ]: + with open(path) as infp: + assert '"This could be translated."' in infp.read() + os.unlink(path) # clean up From c55dff356b02626f1e48327bdb5c498fe6df7873 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 6 Sep 2016 18:17:07 +0300 Subject: [PATCH 4/8] Assert compatibility with Django 1.10 and remove official Django<1.8 support Refs #32 --- .travis.yml | 19 +++++-------------- setup.py | 2 +- tox.ini | 6 ++---- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0512861..3ad88ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,26 +2,17 @@ language: python python: 3.4 sudo: false env: - - TOX_ENV=py27-django15 - - TOX_ENV=py27-django16 - - TOX_ENV=py27-django17 + - TOX_ENV=docs + - TOX_ENV=lint - TOX_ENV=py27-django18 - TOX_ENV=py27-django19 + - TOX_ENV=py27-django110 - TOX_ENV=py27-djangomaster - - TOX_ENV=py34-django15 - - TOX_ENV=py34-django16 - - TOX_ENV=py34-django17 + - TOX_ENV=py33-django18 - TOX_ENV=py34-django18 - TOX_ENV=py34-django19 + - TOX_ENV=py34-django110 - TOX_ENV=py34-djangomaster - - TOX_ENV=py33-django15 - - TOX_ENV=py33-django16 - - TOX_ENV=py33-django17 - - TOX_ENV=py33-django18 - - TOX_ENV=py26-django15 - - TOX_ENV=py26-django16 - - TOX_ENV=lint - - TOX_ENV=docs install: - pip install tox script: diff --git a/setup.py b/setup.py index c9c1688..b8cbdf1 100755 --- a/setup.py +++ b/setup.py @@ -24,7 +24,7 @@ setup( url='https://github.com/python-babel/django-babel/', packages=find_packages(exclude=('tests',)), install_requires=[ - 'django>=1.4,<1.10', + 'django>=1.4,<1.11', 'babel>=1.3', ], classifiers=[ diff --git a/tox.ini b/tox.ini index 4e341ea..03257de 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = {py27,py34}-django{15,16,17,18,19,master}, py33-django{15,16,17,18}, py26-django{15,16}, lint, docs +envlist = {py27,py34}-django{18,19,110,master}, py33-django18, lint, docs [testenv] deps = @@ -8,11 +8,9 @@ deps = pytest-cov pytest-django python-coveralls - django15: Django>=1.5,<1.6 - django16: Django>=1.6,<1.7 - django17: Django>=1.7,<1.8 django18: Django>=1.8,<1.9 django19: Django>=1.9,<1.10 + django110: Django>=1.10,<1.11 djangomaster: https://github.com/django/django/archive/master.tar.gz#egg=Django commands = py.test {posargs} From 264f4479167bbe9db259a5c486d03fdf6aae6d6e Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Wed, 7 Sep 2016 08:48:13 +0300 Subject: [PATCH 5/8] Separate `tests` and `testproject` --- setup.cfg | 3 +-- {tests => testproject}/__init__.py | 0 {tests => testproject}/locale/en/LC_MESSAGES/.gitkeep | 0 {tests => testproject}/locale/fi/LC_MESSAGES/django.po | 0 {tests => testproject}/settings.py | 8 ++++---- {tests => testproject}/templates/test.txt | 0 {tests => testproject}/urls.py | 0 tests/babel.cfg | 2 +- tests/test_command.py | 8 +++----- tox.ini | 2 +- 10 files changed, 10 insertions(+), 13 deletions(-) rename {tests => testproject}/__init__.py (100%) rename {tests => testproject}/locale/en/LC_MESSAGES/.gitkeep (100%) rename {tests => testproject}/locale/fi/LC_MESSAGES/django.po (100%) rename {tests => testproject}/settings.py (79%) rename {tests => testproject}/templates/test.txt (100%) rename {tests => testproject}/urls.py (100%) diff --git a/setup.cfg b/setup.cfg index 6993de8..18e9ca2 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,5 +2,4 @@ universal = 1 [tool:pytest] -DJANGO_SETTINGS_MODULE = tests.settings -norecursedirs = .git .tox .eggs .cache htmlcov venv* +DJANGO_SETTINGS_MODULE = testproject.settings diff --git a/tests/__init__.py b/testproject/__init__.py similarity index 100% rename from tests/__init__.py rename to testproject/__init__.py diff --git a/tests/locale/en/LC_MESSAGES/.gitkeep b/testproject/locale/en/LC_MESSAGES/.gitkeep similarity index 100% rename from tests/locale/en/LC_MESSAGES/.gitkeep rename to testproject/locale/en/LC_MESSAGES/.gitkeep diff --git a/tests/locale/fi/LC_MESSAGES/django.po b/testproject/locale/fi/LC_MESSAGES/django.po similarity index 100% rename from tests/locale/fi/LC_MESSAGES/django.po rename to testproject/locale/fi/LC_MESSAGES/django.po diff --git a/tests/settings.py b/testproject/settings.py similarity index 79% rename from tests/settings.py rename to testproject/settings.py index 38971b9..e3b46c8 100644 --- a/tests/settings.py +++ b/testproject/settings.py @@ -1,11 +1,11 @@ -import os +import pkg_resources SECRET_KEY = 'x' USE_I18N = True -ROOT_URLCONF = 'tests.urls' +ROOT_URLCONF = 'testproject.urls' INSTALLED_APPS = [ 'django_babel', - 'tests', + 'testproject', ] MIDDLEWARE_CLASSES = [ 'django.middleware.locale.LocaleMiddleware', @@ -24,5 +24,5 @@ TEMPLATES = [ }, ] LOCALE_PATHS = [ - os.path.join(os.path.dirname(__file__), 'locale'), + pkg_resources.resource_filename(__name__, 'locale'), ] diff --git a/tests/templates/test.txt b/testproject/templates/test.txt similarity index 100% rename from tests/templates/test.txt rename to testproject/templates/test.txt diff --git a/tests/urls.py b/testproject/urls.py similarity index 100% rename from tests/urls.py rename to testproject/urls.py diff --git a/tests/babel.cfg b/tests/babel.cfg index 3d87ef6..71fb876 100644 --- a/tests/babel.cfg +++ b/tests/babel.cfg @@ -1 +1 @@ -[django: templates/**.*] +[django: **/templates/**.*] diff --git a/tests/test_command.py b/tests/test_command.py index 5cc04df..8ee6107 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -1,11 +1,9 @@ import os +import pkg_resources from django.core.management import call_command -TEST_LOCALE_DIR = os.path.join( - os.path.dirname(__file__), - 'locale', -) +TEST_LOCALE_DIR = pkg_resources.resource_filename('testproject', 'locale') def test_babel_compilemessages(): @@ -25,7 +23,7 @@ def test_babel_makemessages(): 'babel', 'makemessages', '-l', 'en', - '-F', os.path.join(os.path.dirname(__file__), 'babel.cfg'), + '-F', pkg_resources.resource_filename(__name__, 'babel.cfg'), ) # See that the expected files get populated with the discovered message for path in [ diff --git a/tox.ini b/tox.ini index 03257de..8c45bdb 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = {py27,py34}-django{18,19,110,master}, py33-django18, lint, docs +envlist = {py27,py34,py35}-django{18,19,110,master}, py33-django18, lint, docs [testenv] deps = From 753be70b0c094484d553da7561d4e271c4496787 Mon Sep 17 00:00:00 2001 From: Axel Haustant Date: Sun, 30 Oct 2016 16:10:28 +0100 Subject: [PATCH 6/8] Ensure compatibility with Django 1.10+ middlewares --- django_babel/middleware.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/django_babel/middleware.py b/django_babel/middleware.py index 16a618a..8ad5b38 100644 --- a/django_babel/middleware.py +++ b/django_babel/middleware.py @@ -4,6 +4,13 @@ from babel import Locale, UnknownLocaleError from django.utils.translation import get_language from threading import local +try: + from django.utils.deprecation import MiddlewareMixin +except ImportError: + # Not required for Django <= 1.9, see: + # https://docs.djangoproject.com/en/1.10/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware + MiddlewareMixin = object + __all__ = ['get_current_locale', 'LocaleMiddleware'] @@ -19,7 +26,7 @@ def get_current_locale(): return getattr(_thread_locals, 'locale', None) -class LocaleMiddleware(object): +class LocaleMiddleware(MiddlewareMixin): """Simple Django middleware that makes available a Babel `Locale` object via the `request.locale` attribute. From a2f779d3929b8689b17d1874314dcf86740df783 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Mon, 14 Nov 2016 17:14:35 +0200 Subject: [PATCH 7/8] Move testproject under tests --- setup.cfg | 2 +- {testproject => tests}/__init__.py | 0 tests/test_command.py | 4 +++- .../en/LC_MESSAGES/.gitkeep => tests/testproject/__init__.py | 0 tests/testproject/locale/en/LC_MESSAGES/.gitkeep | 0 .../testproject}/locale/fi/LC_MESSAGES/django.po | 0 {testproject => tests/testproject}/settings.py | 4 ++-- {testproject => tests/testproject}/templates/test.txt | 0 {testproject => tests/testproject}/urls.py | 0 9 files changed, 6 insertions(+), 4 deletions(-) rename {testproject => tests}/__init__.py (100%) rename testproject/locale/en/LC_MESSAGES/.gitkeep => tests/testproject/__init__.py (100%) create mode 100644 tests/testproject/locale/en/LC_MESSAGES/.gitkeep rename {testproject => tests/testproject}/locale/fi/LC_MESSAGES/django.po (100%) rename {testproject => tests/testproject}/settings.py (90%) rename {testproject => tests/testproject}/templates/test.txt (100%) rename {testproject => tests/testproject}/urls.py (100%) diff --git a/setup.cfg b/setup.cfg index 18e9ca2..837b2fe 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,4 +2,4 @@ universal = 1 [tool:pytest] -DJANGO_SETTINGS_MODULE = testproject.settings +DJANGO_SETTINGS_MODULE = tests.testproject.settings diff --git a/testproject/__init__.py b/tests/__init__.py similarity index 100% rename from testproject/__init__.py rename to tests/__init__.py diff --git a/tests/test_command.py b/tests/test_command.py index 8ee6107..93415eb 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -3,7 +3,9 @@ import os import pkg_resources from django.core.management import call_command -TEST_LOCALE_DIR = pkg_resources.resource_filename('testproject', 'locale') +TEST_LOCALE_DIR = pkg_resources.resource_filename( + 'tests.testproject', 'locale' +) def test_babel_compilemessages(): diff --git a/testproject/locale/en/LC_MESSAGES/.gitkeep b/tests/testproject/__init__.py similarity index 100% rename from testproject/locale/en/LC_MESSAGES/.gitkeep rename to tests/testproject/__init__.py diff --git a/tests/testproject/locale/en/LC_MESSAGES/.gitkeep b/tests/testproject/locale/en/LC_MESSAGES/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/testproject/locale/fi/LC_MESSAGES/django.po b/tests/testproject/locale/fi/LC_MESSAGES/django.po similarity index 100% rename from testproject/locale/fi/LC_MESSAGES/django.po rename to tests/testproject/locale/fi/LC_MESSAGES/django.po diff --git a/testproject/settings.py b/tests/testproject/settings.py similarity index 90% rename from testproject/settings.py rename to tests/testproject/settings.py index e3b46c8..42947f8 100644 --- a/testproject/settings.py +++ b/tests/testproject/settings.py @@ -2,10 +2,10 @@ import pkg_resources SECRET_KEY = 'x' USE_I18N = True -ROOT_URLCONF = 'testproject.urls' +ROOT_URLCONF = 'tests.testproject.urls' INSTALLED_APPS = [ 'django_babel', - 'testproject', + 'tests.testproject', ] MIDDLEWARE_CLASSES = [ 'django.middleware.locale.LocaleMiddleware', diff --git a/testproject/templates/test.txt b/tests/testproject/templates/test.txt similarity index 100% rename from testproject/templates/test.txt rename to tests/testproject/templates/test.txt diff --git a/testproject/urls.py b/tests/testproject/urls.py similarity index 100% rename from testproject/urls.py rename to tests/testproject/urls.py From 76fd987e7fcc9704d06de45b456a2c6fe5b2538e Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 13 Dec 2016 17:57:44 +0000 Subject: [PATCH 8/8] remove tests/__init__.py --- manage.py | 0 setup.cfg | 3 --- tests/__init__.py | 0 tests/conftest.py | 7 +++++++ tests/test_command.py | 2 +- tests/testproject/settings.py | 4 ++-- 6 files changed, 10 insertions(+), 6 deletions(-) delete mode 100644 manage.py delete mode 100644 tests/__init__.py create mode 100644 tests/conftest.py diff --git a/manage.py b/manage.py deleted file mode 100644 index e69de29..0000000 diff --git a/setup.cfg b/setup.cfg index 837b2fe..5e40900 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,2 @@ [wheel] universal = 1 - -[tool:pytest] -DJANGO_SETTINGS_MODULE = tests.testproject.settings diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..49cfd8e --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,7 @@ +from django.conf import settings + +from testproject import settings as testproject_settings + + +def pytest_configure(): + settings.configure(**vars(testproject_settings)) diff --git a/tests/test_command.py b/tests/test_command.py index 93415eb..d685160 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -4,7 +4,7 @@ import pkg_resources from django.core.management import call_command TEST_LOCALE_DIR = pkg_resources.resource_filename( - 'tests.testproject', 'locale' + 'testproject', 'locale' ) diff --git a/tests/testproject/settings.py b/tests/testproject/settings.py index 42947f8..e3b46c8 100644 --- a/tests/testproject/settings.py +++ b/tests/testproject/settings.py @@ -2,10 +2,10 @@ import pkg_resources SECRET_KEY = 'x' USE_I18N = True -ROOT_URLCONF = 'tests.testproject.urls' +ROOT_URLCONF = 'testproject.urls' INSTALLED_APPS = [ 'django_babel', - 'tests.testproject', + 'testproject', ] MIDDLEWARE_CLASSES = [ 'django.middleware.locale.LocaleMiddleware',