1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Refs #24324 -- Fixed Python 2 test failures when path to Django source contains non-ASCII characters.

This commit is contained in:
Tim Graham 2015-02-14 19:47:07 -05:00
parent fa66ea7532
commit 307c0f299a
9 changed files with 31 additions and 23 deletions

View File

@ -32,7 +32,7 @@ if not os.path.exists(test_dir):
os.mkdir(test_dir) os.mkdir(test_dir)
open(os.path.join(test_dir, '__init__.py'), 'w').close() open(os.path.join(test_dir, '__init__.py'), 'w').close()
custom_templates_dir = os.path.join(os.path.dirname(__file__), 'custom_templates') custom_templates_dir = os.path.join(os.path.dirname(upath(__file__)), 'custom_templates')
SYSTEM_CHECK_MSG = 'System check identified no issues' SYSTEM_CHECK_MSG = 'System check identified no issues'
@ -113,7 +113,7 @@ class AdminScriptTestCase(unittest.TestCase):
def run_test(self, script, args, settings_file=None, apps=None): def run_test(self, script, args, settings_file=None, apps=None):
base_dir = os.path.dirname(test_dir) base_dir = os.path.dirname(test_dir)
# The base dir for Django's tests is one level up. # The base dir for Django's tests is one level up.
tests_dir = os.path.dirname(os.path.dirname(__file__)) tests_dir = os.path.dirname(os.path.dirname(upath(__file__)))
# The base dir for Django is one level above the test dir. We don't use # The base dir for Django is one level above the test dir. We don't use
# `import django` to figure that out, so we don't pick up a Django # `import django` to figure that out, so we don't pick up a Django
# from site-packages or similar. # from site-packages or similar.

View File

@ -35,7 +35,7 @@ SOME_INSTALLED_APPS_NAMES = [
'django.contrib.auth', 'django.contrib.auth',
] + SOME_INSTALLED_APPS[2:] ] + SOME_INSTALLED_APPS[2:]
HERE = os.path.dirname(__file__) HERE = os.path.dirname(upath(__file__))
class AppsTests(TestCase): class AppsTests(TestCase):

View File

@ -563,7 +563,7 @@ class MakeMigrationsTests(MigrationTestBase):
self.fail("Makemigrations failed while running interactive questioner") self.fail("Makemigrations failed while running interactive questioner")
finally: finally:
questioner.input = old_input questioner.input = old_input
self.assertIn("Created new merge migration", out.getvalue()) self.assertIn("Created new merge migration", force_text(out.getvalue()))
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_conflict"}) @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_conflict"})
def test_makemigrations_handle_merge(self): def test_makemigrations_handle_merge(self):
@ -572,14 +572,15 @@ class MakeMigrationsTests(MigrationTestBase):
""" """
out = six.StringIO() out = six.StringIO()
call_command("makemigrations", "migrations", merge=True, interactive=False, stdout=out) call_command("makemigrations", "migrations", merge=True, interactive=False, stdout=out)
self.assertIn("Merging migrations", out.getvalue()) output = force_text(out.getvalue())
self.assertIn("Branch 0002_second", out.getvalue()) self.assertIn("Merging migrations", output)
self.assertIn("Branch 0002_conflicting_second", out.getvalue()) self.assertIn("Branch 0002_second", output)
self.assertIn("Branch 0002_conflicting_second", output)
merge_file = os.path.join(self.test_dir, 'test_migrations_conflict', '0003_merge.py') merge_file = os.path.join(self.test_dir, 'test_migrations_conflict', '0003_merge.py')
self.assertTrue(os.path.exists(merge_file)) self.assertTrue(os.path.exists(merge_file))
os.remove(merge_file) os.remove(merge_file)
self.assertFalse(os.path.exists(merge_file)) self.assertFalse(os.path.exists(merge_file))
self.assertIn("Created new merge migration", out.getvalue()) self.assertIn("Created new merge migration", output)
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_no_default"}) @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations_no_default"})
def test_makemigrations_dry_run(self): def test_makemigrations_dry_run(self):
@ -797,7 +798,7 @@ class SquashMigrationsTest(MigrationTestBase):
""" """
out = six.StringIO() out = six.StringIO()
call_command("squashmigrations", "migrations", "0002", interactive=False, verbosity=1, stdout=out) call_command("squashmigrations", "migrations", "0002", interactive=False, verbosity=1, stdout=out)
self.assertIn("Optimized from 7 operations to 5 operations.", out.getvalue()) self.assertIn("Optimized from 7 operations to 5 operations.", force_text(out.getvalue()))
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"}) @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_ticket_23799_squashmigrations_no_optimize(self): def test_ticket_23799_squashmigrations_no_optimize(self):
@ -807,4 +808,4 @@ class SquashMigrationsTest(MigrationTestBase):
out = six.StringIO() out = six.StringIO()
call_command("squashmigrations", "migrations", "0002", call_command("squashmigrations", "migrations", "0002",
interactive=False, verbosity=1, no_optimize=True, stdout=out) interactive=False, verbosity=1, no_optimize=True, stdout=out)
self.assertIn("Skipping optimization", out.getvalue()) self.assertIn("Skipping optimization", force_text(out.getvalue()))

View File

@ -19,6 +19,7 @@ from django.db.migrations.writer import (
) )
from django.test import SimpleTestCase, TestCase, ignore_warnings from django.test import SimpleTestCase, TestCase, ignore_warnings
from django.utils import datetime_safe, six from django.utils import datetime_safe, six
from django.utils._os import upath
from django.utils.deconstruct import deconstructible from django.utils.deconstruct import deconstructible
from django.utils.timezone import FixedOffset, get_default_timezone, utc from django.utils.timezone import FixedOffset, get_default_timezone, utc
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -401,7 +402,7 @@ class WriterTests(TestCase):
'migrations.migrations_test_apps.without_init_file', 'migrations.migrations_test_apps.without_init_file',
] ]
base_dir = os.path.dirname(os.path.dirname(__file__)) base_dir = os.path.dirname(os.path.dirname(upath(__file__)))
for app in test_apps: for app in test_apps:
with self.modify_settings(INSTALLED_APPS={'append': app}): with self.modify_settings(INSTALLED_APPS={'append': app}):

View File

@ -241,7 +241,7 @@ class TestFindStatic(CollectionTestCase, TestDefaults):
self.assertIn('project', force_text(lines[1])) self.assertIn('project', force_text(lines[1]))
self.assertIn('apps', force_text(lines[2])) self.assertIn('apps', force_text(lines[2]))
self.assertIn("Looking in the following locations:", force_text(lines[3])) self.assertIn("Looking in the following locations:", force_text(lines[3]))
searched_locations = ', '.join(lines[4:]) searched_locations = ', '.join(force_text(x) for x in lines[4:])
# AppDirectoriesFinder searched locations # AppDirectoriesFinder searched locations
self.assertIn(os.path.join('staticfiles_tests', 'apps', 'test', 'static'), self.assertIn(os.path.join('staticfiles_tests', 'apps', 'test', 'static'),
searched_locations) searched_locations)

View File

@ -1,3 +1,5 @@
from __future__ import unicode_literals
import os import os
from django.test import SimpleTestCase, ignore_warnings from django.test import SimpleTestCase, ignore_warnings

View File

@ -5,6 +5,7 @@ from django.db import connection
from django.test import TestCase from django.test import TestCase
from django.test.runner import DiscoverRunner from django.test.runner import DiscoverRunner
from django.utils import six from django.utils import six
from django.utils.encoding import force_text
from .models import Person from .models import Person
@ -42,8 +43,9 @@ class TestDebugSQL(unittest.TestCase):
).run(suite) ).run(suite)
runner.teardown_databases(old_config) runner.teardown_databases(old_config)
stream.seek(0) if six.PY2:
return stream.read() stream.buflist = [force_text(x) for x in stream.buflist]
return stream.getvalue()
def test_output_normal(self): def test_output_normal(self):
full_output = self._test_output(1) full_output = self._test_output(1)

View File

@ -18,6 +18,7 @@ from django.test import (
from django.test.runner import DiscoverRunner, dependency_ordered from django.test.runner import DiscoverRunner, dependency_ordered
from django.test.testcases import connections_support_transactions from django.test.testcases import connections_support_transactions
from django.utils import six from django.utils import six
from django.utils.encoding import force_text
from .models import Person from .models import Person
@ -372,7 +373,7 @@ class DeprecationDisplayTest(AdminScriptTestCase):
def test_runner_deprecation_verbosity_default(self): def test_runner_deprecation_verbosity_default(self):
args = ['test', '--settings=test_project.settings', 'test_runner_deprecation_app'] args = ['test', '--settings=test_project.settings', 'test_runner_deprecation_app']
out, err = self.run_django_admin(args) out, err = self.run_django_admin(args)
self.assertIn("Ran 1 test", err) self.assertIn("Ran 1 test", force_text(err))
six.assertRegex(self, err, r"RemovedInDjango\d\dWarning: warning from test") six.assertRegex(self, err, r"RemovedInDjango\d\dWarning: warning from test")
six.assertRegex(self, err, r"RemovedInDjango\d\dWarning: module-level warning from deprecation_app") six.assertRegex(self, err, r"RemovedInDjango\d\dWarning: module-level warning from deprecation_app")

View File

@ -5,7 +5,7 @@ from importlib import import_module
from django import conf from django import conf
from django.contrib import admin from django.contrib import admin
from django.test import TestCase, override_settings from django.test import TestCase, override_settings
from django.utils._os import upath from django.utils._os import npath, upath
from django.utils.autoreload import gen_filenames from django.utils.autoreload import gen_filenames
LOCALE_PATH = os.path.join(os.path.dirname(__file__), 'locale') LOCALE_PATH = os.path.join(os.path.dirname(__file__), 'locale')
@ -58,9 +58,10 @@ class TestFilenameGenerator(TestCase):
Test that gen_filenames also yields from locale dirs in installed apps. Test that gen_filenames also yields from locale dirs in installed apps.
""" """
filenames = list(gen_filenames()) filenames = list(gen_filenames())
self.assertIn(os.path.join(os.path.dirname(admin.__file__), 'locale', self.assertIn(
'nl', 'LC_MESSAGES', 'django.mo'), os.path.join(os.path.dirname(upath(admin.__file__)), 'locale', 'nl', 'LC_MESSAGES', 'django.mo'),
filenames) filenames
)
@override_settings(USE_I18N=False) @override_settings(USE_I18N=False)
def test_no_i18n(self): def test_no_i18n(self):
@ -70,9 +71,9 @@ class TestFilenameGenerator(TestCase):
""" """
filenames = list(gen_filenames()) filenames = list(gen_filenames())
self.assertNotIn( self.assertNotIn(
os.path.join(os.path.dirname(conf.__file__), 'locale', 'nl', os.path.join(os.path.dirname(upath(conf.__file__)), 'locale', 'nl', 'LC_MESSAGES', 'django.mo'),
'LC_MESSAGES', 'django.mo'), filenames
filenames) )
def test_only_new_files(self): def test_only_new_files(self):
""" """
@ -91,7 +92,7 @@ class TestFilenameGenerator(TestCase):
try: try:
_, filename = os.path.split(filepath) _, filename = os.path.split(filepath)
import_module('.%s' % filename.replace('.py', ''), package='utils_tests') import_module('.%s' % filename.replace('.py', ''), package='utils_tests')
self.assertIn(filepath, gen_filenames()) self.assertIn(npath(filepath), gen_filenames())
finally: finally:
os.close(fd) os.close(fd)
os.remove(filepath) os.remove(filepath)