[1.8.x] Refs #24324 -- Fixed Python 2 test failures when path to Django source contains non-ASCII characters.
Backport of 307c0f299a
from master
This commit is contained in:
parent
09da1b465e
commit
2aa06e439a
|
@ -36,7 +36,7 @@ if not os.path.exists(test_dir):
|
|||
os.mkdir(test_dir)
|
||||
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'
|
||||
|
||||
|
||||
|
@ -117,7 +117,7 @@ class AdminScriptTestCase(unittest.TestCase):
|
|||
def run_test(self, script, args, settings_file=None, apps=None):
|
||||
base_dir = os.path.dirname(test_dir)
|
||||
# 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
|
||||
# `import django` to figure that out, so we don't pick up a Django
|
||||
# from site-packages or similar.
|
||||
|
|
|
@ -35,7 +35,7 @@ SOME_INSTALLED_APPS_NAMES = [
|
|||
'django.contrib.auth',
|
||||
] + SOME_INSTALLED_APPS[2:]
|
||||
|
||||
HERE = os.path.dirname(__file__)
|
||||
HERE = os.path.dirname(upath(__file__))
|
||||
|
||||
|
||||
class AppsTests(TestCase):
|
||||
|
|
|
@ -563,7 +563,7 @@ class MakeMigrationsTests(MigrationTestBase):
|
|||
self.fail("Makemigrations failed while running interactive questioner")
|
||||
finally:
|
||||
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"})
|
||||
def test_makemigrations_handle_merge(self):
|
||||
|
@ -572,14 +572,15 @@ class MakeMigrationsTests(MigrationTestBase):
|
|||
"""
|
||||
out = six.StringIO()
|
||||
call_command("makemigrations", "migrations", merge=True, interactive=False, stdout=out)
|
||||
self.assertIn("Merging migrations", out.getvalue())
|
||||
self.assertIn("Branch 0002_second", out.getvalue())
|
||||
self.assertIn("Branch 0002_conflicting_second", out.getvalue())
|
||||
output = force_text(out.getvalue())
|
||||
self.assertIn("Merging migrations", output)
|
||||
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')
|
||||
self.assertTrue(os.path.exists(merge_file))
|
||||
os.remove(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"})
|
||||
def test_makemigrations_dry_run(self):
|
||||
|
@ -797,7 +798,7 @@ class SquashMigrationsTest(MigrationTestBase):
|
|||
"""
|
||||
out = six.StringIO()
|
||||
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"})
|
||||
def test_ticket_23799_squashmigrations_no_optimize(self):
|
||||
|
@ -807,4 +808,4 @@ class SquashMigrationsTest(MigrationTestBase):
|
|||
out = six.StringIO()
|
||||
call_command("squashmigrations", "migrations", "0002",
|
||||
interactive=False, verbosity=1, no_optimize=True, stdout=out)
|
||||
self.assertIn("Skipping optimization", out.getvalue())
|
||||
self.assertIn("Skipping optimization", force_text(out.getvalue()))
|
||||
|
|
|
@ -19,6 +19,7 @@ from django.db.migrations.writer import (
|
|||
)
|
||||
from django.test import SimpleTestCase, TestCase, ignore_warnings
|
||||
from django.utils import datetime_safe, six
|
||||
from django.utils._os import upath
|
||||
from django.utils.deconstruct import deconstructible
|
||||
from django.utils.timezone import FixedOffset, get_default_timezone, utc
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
@ -393,7 +394,7 @@ class WriterTests(TestCase):
|
|||
'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:
|
||||
with self.modify_settings(INSTALLED_APPS={'append': app}):
|
||||
|
|
|
@ -241,7 +241,7 @@ class TestFindStatic(CollectionTestCase, TestDefaults):
|
|||
self.assertIn('project', force_text(lines[1]))
|
||||
self.assertIn('apps', force_text(lines[2]))
|
||||
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
|
||||
self.assertIn(os.path.join('staticfiles_tests', 'apps', 'test', 'static'),
|
||||
searched_locations)
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
|
||||
from django.test import SimpleTestCase, ignore_warnings
|
||||
|
|
|
@ -5,6 +5,7 @@ from django.db import connection
|
|||
from django.test import TestCase
|
||||
from django.test.runner import DiscoverRunner
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
from .models import Person
|
||||
|
||||
|
@ -42,8 +43,9 @@ class TestDebugSQL(unittest.TestCase):
|
|||
).run(suite)
|
||||
runner.teardown_databases(old_config)
|
||||
|
||||
stream.seek(0)
|
||||
return stream.read()
|
||||
if six.PY2:
|
||||
stream.buflist = [force_text(x) for x in stream.buflist]
|
||||
return stream.getvalue()
|
||||
|
||||
def test_output_normal(self):
|
||||
full_output = self._test_output(1)
|
||||
|
|
|
@ -18,6 +18,7 @@ from django.test import (
|
|||
from django.test.runner import DiscoverRunner, dependency_ordered
|
||||
from django.test.testcases import connections_support_transactions
|
||||
from django.utils import six
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
from .models import Person
|
||||
|
||||
|
@ -391,7 +392,7 @@ class DeprecationDisplayTest(AdminScriptTestCase):
|
|||
def test_runner_deprecation_verbosity_default(self):
|
||||
args = ['test', '--settings=test_project.settings', 'test_runner_deprecation_app']
|
||||
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: module-level warning from deprecation_app")
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ from importlib import import_module
|
|||
from django import conf
|
||||
from django.contrib import admin
|
||||
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
|
||||
|
||||
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.
|
||||
"""
|
||||
filenames = list(gen_filenames())
|
||||
self.assertIn(os.path.join(os.path.dirname(admin.__file__), 'locale',
|
||||
'nl', 'LC_MESSAGES', 'django.mo'),
|
||||
filenames)
|
||||
self.assertIn(
|
||||
os.path.join(os.path.dirname(upath(admin.__file__)), 'locale', 'nl', 'LC_MESSAGES', 'django.mo'),
|
||||
filenames
|
||||
)
|
||||
|
||||
@override_settings(USE_I18N=False)
|
||||
def test_no_i18n(self):
|
||||
|
@ -70,9 +71,9 @@ class TestFilenameGenerator(TestCase):
|
|||
"""
|
||||
filenames = list(gen_filenames())
|
||||
self.assertNotIn(
|
||||
os.path.join(os.path.dirname(conf.__file__), 'locale', 'nl',
|
||||
'LC_MESSAGES', 'django.mo'),
|
||||
filenames)
|
||||
os.path.join(os.path.dirname(upath(conf.__file__)), 'locale', 'nl', 'LC_MESSAGES', 'django.mo'),
|
||||
filenames
|
||||
)
|
||||
|
||||
def test_only_new_files(self):
|
||||
"""
|
||||
|
@ -91,7 +92,7 @@ class TestFilenameGenerator(TestCase):
|
|||
try:
|
||||
_, filename = os.path.split(filepath)
|
||||
import_module('.%s' % filename.replace('.py', ''), package='utils_tests')
|
||||
self.assertIn(filepath, gen_filenames())
|
||||
self.assertIn(npath(filepath), gen_filenames())
|
||||
finally:
|
||||
os.close(fd)
|
||||
os.remove(filepath)
|
||||
|
|
Loading…
Reference in New Issue