summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2012-12-08 11:13:52 +0100
committerClaude Paroz <claude@2xlibre.net>2012-12-08 11:13:52 +0100
commitc91667338a4e774e2819ccf4da852dc7b759bc19 (patch)
tree42a700d237c85ac2b647999d02d3dcd7d8047068 /tests
parent53b879f045f0e55cc8f4bedff67b5a14f3057561 (diff)
Fixed #19357 -- Allow non-ASCII chars in filesystem paths
Thanks kujiu for the report and Aymeric Augustin for the review.
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/fixtures/tests.py12
-rw-r--r--tests/modeltests/model_forms/tests.py5
-rw-r--r--tests/modeltests/proxy_model_inheritance/tests.py3
-rw-r--r--tests/regressiontests/admin_scripts/tests.py15
-rw-r--r--tests/regressiontests/admin_scripts/urls.py3
-rw-r--r--tests/regressiontests/admin_views/tests.py3
-rw-r--r--tests/regressiontests/app_loading/tests.py3
-rw-r--r--tests/regressiontests/bug639/tests.py3
-rw-r--r--tests/regressiontests/file_storage/tests.py7
-rw-r--r--tests/regressiontests/fixtures_regress/tests.py8
-rw-r--r--tests/regressiontests/forms/tests/fields.py11
-rw-r--r--tests/regressiontests/httpwrappers/tests.py5
-rw-r--r--tests/regressiontests/i18n/commands/compilation.py7
-rw-r--r--tests/regressiontests/i18n/commands/extraction.py31
-rw-r--r--tests/regressiontests/i18n/contenttypes/tests.py3
-rw-r--r--tests/regressiontests/i18n/patterns/tests.py5
-rw-r--r--tests/regressiontests/i18n/tests.py7
-rw-r--r--tests/regressiontests/logging_tests/tests.py5
-rw-r--r--tests/regressiontests/model_fields/imagefield.py5
-rw-r--r--tests/regressiontests/model_forms_regress/models.py3
-rw-r--r--tests/regressiontests/servers/tests.py3
-rw-r--r--tests/regressiontests/staticfiles_tests/tests.py14
-rw-r--r--tests/regressiontests/templates/loaders.py7
-rw-r--r--tests/regressiontests/templates/response.py3
-rw-r--r--tests/regressiontests/templates/tests.py7
-rw-r--r--tests/regressiontests/test_client_regress/tests.py5
-rw-r--r--tests/regressiontests/urlpatterns_reverse/tests.py2
-rw-r--r--tests/regressiontests/utils/archive.py3
-rw-r--r--tests/regressiontests/utils/module_loading.py3
-rw-r--r--tests/regressiontests/views/tests/debug.py46
-rw-r--r--tests/regressiontests/views/tests/i18n.py3
-rw-r--r--tests/regressiontests/views/urls.py3
-rwxr-xr-xtests/runtests.py9
33 files changed, 146 insertions, 106 deletions
diff --git a/tests/modeltests/fixtures/tests.py b/tests/modeltests/fixtures/tests.py
index f9b0ac8a46..b667c8c6d4 100644
--- a/tests/modeltests/fixtures/tests.py
+++ b/tests/modeltests/fixtures/tests.py
@@ -226,9 +226,9 @@ class FixtureLoadingTests(TestCase):
def test_ambiguous_compressed_fixture(self):
# The name "fixture5" is ambigous, so loading it will raise an error
- with six.assertRaisesRegex(self, management.CommandError,
- "Multiple fixtures named 'fixture5'"):
+ with self.assertRaises(management.CommandError) as cm:
management.call_command('loaddata', 'fixture5', verbosity=0, commit=False)
+ self.assertIn("Multiple fixtures named 'fixture5'", cm.exception.args[0])
def test_db_loading(self):
# Load db fixtures 1 and 2. These will load using the 'default' database identifier implicitly
@@ -250,9 +250,9 @@ class FixtureLoadingTests(TestCase):
# is closed at the end of each test.
if connection.vendor == 'mysql':
connection.cursor().execute("SET sql_mode = 'TRADITIONAL'")
- with six.assertRaisesRegex(self, IntegrityError,
- "Could not load fixtures.Article\(pk=1\): .*$"):
+ with self.assertRaises(IntegrityError) as cm:
management.call_command('loaddata', 'invalid.json', verbosity=0, commit=False)
+ self.assertIn("Could not load fixtures.Article(pk=1):", cm.exception.args[0])
def test_loading_using(self):
# Load db fixtures 1 and 2. These will load using the 'default' database identifier explicitly
@@ -308,9 +308,9 @@ class FixtureTransactionTests(TransactionTestCase):
# Try to load fixture 2 using format discovery; this will fail
# because there are two fixture2's in the fixtures directory
- with six.assertRaisesRegex(self, management.CommandError,
- "Multiple fixtures named 'fixture2'"):
+ with self.assertRaises(management.CommandError) as cm:
management.call_command('loaddata', 'fixture2', verbosity=0)
+ self.assertIn("Multiple fixtures named 'fixture2'", cm.exception.args[0])
# object list is unaffected
self.assertQuerysetEqual(Article.objects.all(), [
diff --git a/tests/modeltests/model_forms/tests.py b/tests/modeltests/model_forms/tests.py
index c47de45ef7..c008c00906 100644
--- a/tests/modeltests/model_forms/tests.py
+++ b/tests/modeltests/model_forms/tests.py
@@ -10,6 +10,7 @@ from django.core.validators import ValidationError
from django.db import connection
from django.db.models.query import EmptyQuerySet
from django.forms.models import model_to_dict
+from django.utils._os import upath
from django.utils.unittest import skipUnless
from django.test import TestCase
from django.utils import six
@@ -1282,9 +1283,9 @@ class OldFormForXTests(TestCase):
# it comes to validation. This specifically tests that #6302 is fixed for
# both file fields and image fields.
- with open(os.path.join(os.path.dirname(__file__), "test.png"), 'rb') as fp:
+ with open(os.path.join(os.path.dirname(upath(__file__)), "test.png"), 'rb') as fp:
image_data = fp.read()
- with open(os.path.join(os.path.dirname(__file__), "test2.png"), 'rb') as fp:
+ with open(os.path.join(os.path.dirname(upath(__file__)), "test2.png"), 'rb') as fp:
image_data2 = fp.read()
f = ImageFileForm(
diff --git a/tests/modeltests/proxy_model_inheritance/tests.py b/tests/modeltests/proxy_model_inheritance/tests.py
index 39fee7ee6d..239bc67809 100644
--- a/tests/modeltests/proxy_model_inheritance/tests.py
+++ b/tests/modeltests/proxy_model_inheritance/tests.py
@@ -8,6 +8,7 @@ from django.core.management import call_command
from django.db.models.loading import cache, load_app
from django.test import TestCase, TransactionTestCase
from django.test.utils import override_settings
+from django.utils._os import upath
from .models import (ConcreteModel, ConcreteModelSubclass,
ConcreteModelSubclassProxy)
@@ -23,7 +24,7 @@ class ProxyModelInheritanceTests(TransactionTestCase):
def setUp(self):
self.old_sys_path = sys.path[:]
- sys.path.append(os.path.dirname(os.path.abspath(__file__)))
+ sys.path.append(os.path.dirname(os.path.abspath(upath(__file__))))
for app in settings.INSTALLED_APPS:
load_app(app)
diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
index a26d7a6eaa..d0ca9d26df 100644
--- a/tests/regressiontests/admin_scripts/tests.py
+++ b/tests/regressiontests/admin_scripts/tests.py
@@ -19,13 +19,15 @@ from django.conf import settings
from django.db import connection
from django.test.simple import DjangoTestSuiteRunner
from django.utils import unittest
+from django.utils.encoding import force_str, force_text
+from django.utils._os import upath
from django.test import LiveServerTestCase
-test_dir = os.path.dirname(os.path.dirname(__file__))
+test_dir = os.path.dirname(os.path.dirname(upath(__file__)))
class AdminScriptTestCase(unittest.TestCase):
def write_settings(self, filename, apps=None, is_dir=False, sdict=None):
- test_dir = os.path.dirname(os.path.dirname(__file__))
+ test_dir = os.path.dirname(os.path.dirname(upath(__file__)))
if is_dir:
settings_dir = os.path.join(test_dir, filename)
os.mkdir(settings_dir)
@@ -94,6 +96,7 @@ class AdminScriptTestCase(unittest.TestCase):
return paths
def run_test(self, script, args, settings_file=None, apps=None):
+ test_dir = os.path.dirname(os.path.dirname(__file__))
project_dir = os.path.dirname(test_dir)
base_dir = os.path.dirname(project_dir)
ext_backend_base_dirs = self._ext_backend_paths()
@@ -134,7 +137,7 @@ class AdminScriptTestCase(unittest.TestCase):
return out, err
def run_django_admin(self, args, settings_file=None):
- bin_dir = os.path.abspath(os.path.dirname(bin.__file__))
+ bin_dir = os.path.abspath(os.path.dirname(upath(bin.__file__)))
return self.run_test(os.path.join(bin_dir, 'django-admin.py'), args, settings_file)
def run_manage(self, args, settings_file=None):
@@ -144,7 +147,7 @@ class AdminScriptTestCase(unittest.TestCase):
except OSError:
pass
- conf_dir = os.path.dirname(conf.__file__)
+ conf_dir = os.path.dirname(upath(conf.__file__))
template_manage_py = os.path.join(conf_dir, 'project_template', 'manage.py')
test_manage_py = os.path.join(test_dir, 'manage.py')
@@ -166,10 +169,12 @@ class AdminScriptTestCase(unittest.TestCase):
def assertOutput(self, stream, msg):
"Utility assertion: assert that the given message exists in the output"
+ stream = force_text(stream)
self.assertTrue(msg in stream, "'%s' does not match actual output text '%s'" % (msg, stream))
def assertNotInOutput(self, stream, msg):
"Utility assertion: assert that the given message doesn't exist in the output"
+ stream = force_text(stream)
self.assertFalse(msg in stream, "'%s' matches actual output text '%s'" % (msg, stream))
##########################################################################
@@ -1553,7 +1558,7 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
self.assertNoOutput(err)
test_manage_py = os.path.join(testproject_dir, 'manage.py')
with open(test_manage_py, 'r') as fp:
- content = fp.read()
+ content = force_text(fp.read())
self.assertIn("project_name = 'another_project'", content)
self.assertIn("project_directory = '%s'" % testproject_dir, content)
diff --git a/tests/regressiontests/admin_scripts/urls.py b/tests/regressiontests/admin_scripts/urls.py
index 692638ceca..a45dc3e9a6 100644
--- a/tests/regressiontests/admin_scripts/urls.py
+++ b/tests/regressiontests/admin_scripts/urls.py
@@ -1,7 +1,8 @@
import os
from django.conf.urls import patterns
+from django.utils._os import upath
-here = os.path.dirname(__file__)
+here = os.path.dirname(upath(__file__))
urlpatterns = patterns('',
(r'^custom_templates/(?P<path>.*)$', 'django.views.static.serve', {
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 10f946132d..04394a673b 100644
--- a/tests/regressiontests/admin_views/tests.py
+++ b/tests/regressiontests/admin_views/tests.py
@@ -33,6 +33,7 @@ from django.utils.cache import get_max_age
from django.utils.encoding import iri_to_uri, force_bytes
from django.utils.html import escape
from django.utils.http import urlencode
+from django.utils._os import upath
from django.utils import six
from django.test.utils import override_settings
@@ -633,7 +634,7 @@ class AdminViewFormUrlTest(TestCase):
Refs #17515.
"""
template_dirs = settings.TEMPLATE_DIRS + (
- os.path.join(os.path.dirname(__file__), 'templates'),)
+ os.path.join(os.path.dirname(upath(__file__)), 'templates'),)
with self.settings(TEMPLATE_DIRS=template_dirs):
response = self.client.get("/test_admin/admin/admin_views/color2/")
self.assertTrue('custom_filter_template.html' in [t.name for t in response.templates])
diff --git a/tests/regressiontests/app_loading/tests.py b/tests/regressiontests/app_loading/tests.py
index 0e66a5aad3..6dd0be2194 100644
--- a/tests/regressiontests/app_loading/tests.py
+++ b/tests/regressiontests/app_loading/tests.py
@@ -7,13 +7,14 @@ import time
from django.conf import Settings
from django.db.models.loading import cache, load_app, get_model, get_models
+from django.utils._os import upath
from django.utils.unittest import TestCase
class EggLoadingTest(TestCase):
def setUp(self):
self.old_path = sys.path[:]
- self.egg_dir = '%s/eggs' % os.path.dirname(__file__)
+ self.egg_dir = '%s/eggs' % os.path.dirname(upath(__file__))
# This test adds dummy applications to the app cache. These
# need to be removed in order to prevent bad interactions
diff --git a/tests/regressiontests/bug639/tests.py b/tests/regressiontests/bug639/tests.py
index b7547696d4..fcc1e0f7d1 100644
--- a/tests/regressiontests/bug639/tests.py
+++ b/tests/regressiontests/bug639/tests.py
@@ -11,6 +11,7 @@ import shutil
from django.core.files.uploadedfile import SimpleUploadedFile
from django.utils import unittest
+from django.utils._os import upath
from .models import Photo, PhotoForm, temp_storage_dir
@@ -23,7 +24,7 @@ class Bug639Test(unittest.TestCase):
called.
"""
# Grab an image for testing.
- filename = os.path.join(os.path.dirname(__file__), "test.jpg")
+ filename = os.path.join(os.path.dirname(upath(__file__)), "test.jpg")
with open(filename, "rb") as fp:
img = fp.read()
diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
index 45c18ba14a..b6d3e1ff0b 100644
--- a/tests/regressiontests/file_storage/tests.py
+++ b/tests/regressiontests/file_storage/tests.py
@@ -24,6 +24,7 @@ from django.core.files.uploadedfile import UploadedFile
from django.test import SimpleTestCase
from django.utils import six
from django.utils import unittest
+from django.utils._os import upath
from django.test.utils import override_settings
from ..servers.tests import LiveServerBase
@@ -104,7 +105,7 @@ class FileStorageTests(unittest.TestCase):
"""
storage = self.storage_class(location='')
self.assertEqual(storage.base_location, '')
- self.assertEqual(storage.location, os.getcwd())
+ self.assertEqual(storage.location, upath(os.getcwd()))
def test_file_access_options(self):
"""
@@ -534,7 +535,7 @@ class DimensionClosingBug(unittest.TestCase):
from django.core.files import images
images.open = catching_open
try:
- get_image_dimensions(os.path.join(os.path.dirname(__file__), "test1.png"))
+ get_image_dimensions(os.path.join(os.path.dirname(upath(__file__)), "test1.png"))
finally:
del images.open
self.assertTrue(FileWrapper._closed)
@@ -551,7 +552,7 @@ class InconsistentGetImageDimensionsBug(unittest.TestCase):
"""
from django.core.files.images import ImageFile
- img_path = os.path.join(os.path.dirname(__file__), "test.png")
+ img_path = os.path.join(os.path.dirname(upath(__file__)), "test.png")
image = ImageFile(open(img_path, 'rb'))
image_pil = Image.open(img_path)
size_1, size_2 = get_image_dimensions(image), get_image_dimensions(image)
diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py
index 55363bc5b7..988c5acd0c 100644
--- a/tests/regressiontests/fixtures_regress/tests.py
+++ b/tests/regressiontests/fixtures_regress/tests.py
@@ -14,6 +14,8 @@ from django.db.models import signals
from django.test import (TestCase, TransactionTestCase, skipIfDBFeature,
skipUnlessDBFeature)
from django.test.utils import override_settings
+from django.utils.encoding import force_text
+from django.utils._os import upath
from django.utils import six
from django.utils.six import PY3, StringIO
@@ -126,7 +128,7 @@ class TestFixtures(TestCase):
fixture directory.
"""
load_absolute_path = os.path.join(
- os.path.dirname(__file__),
+ os.path.dirname(upath(__file__)),
'fixtures',
'absolute.json'
)
@@ -388,7 +390,7 @@ class TestFixtures(TestCase):
commit=False,
)
- _cur_dir = os.path.dirname(os.path.abspath(__file__))
+ _cur_dir = os.path.dirname(os.path.abspath(upath(__file__)))
@override_settings(FIXTURE_DIRS=[os.path.join(_cur_dir, 'fixtures_1'),
os.path.join(_cur_dir, 'fixtures_2')])
@@ -430,7 +432,7 @@ class TestFixtures(TestCase):
stdout=stdout_output,
)
self.assertTrue("No xml fixture 'this_fixture_doesnt_exist' in" in
- stdout_output.getvalue())
+ force_text(stdout_output.getvalue()))
class NaturalKeyFixtureTests(TestCase):
diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
index 1027afceb1..e17d976fcf 100644
--- a/tests/regressiontests/forms/tests/fields.py
+++ b/tests/regressiontests/forms/tests/fields.py
@@ -36,6 +36,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile
from django.forms import *
from django.test import SimpleTestCase
from django.utils import six
+from django.utils._os import upath
def fix_os_paths(x):
@@ -928,12 +929,12 @@ class FieldsTests(SimpleTestCase):
# FilePathField ###############################################################
def test_filepathfield_1(self):
- path = os.path.abspath(forms.__file__)
+ path = os.path.abspath(upath(forms.__file__))
path = os.path.dirname(path) + '/'
self.assertTrue(fix_os_paths(path).endswith('/django/forms/'))
def test_filepathfield_2(self):
- path = forms.__file__
+ path = upath(forms.__file__)
path = os.path.dirname(os.path.abspath(path)) + '/'
f = FilePathField(path=path)
f.choices = [p for p in f.choices if p[0].endswith('.py')]
@@ -954,7 +955,7 @@ class FieldsTests(SimpleTestCase):
assert fix_os_paths(f.clean(path + 'fields.py')).endswith('/django/forms/fields.py')
def test_filepathfield_3(self):
- path = forms.__file__
+ path = upath(forms.__file__)
path = os.path.dirname(os.path.abspath(path)) + '/'
f = FilePathField(path=path, match='^.*?\.py$')
f.choices.sort()
@@ -972,7 +973,7 @@ class FieldsTests(SimpleTestCase):
self.assertTrue(got[0].endswith(exp[0]))
def test_filepathfield_4(self):
- path = os.path.abspath(forms.__file__)
+ path = os.path.abspath(upath(forms.__file__))
path = os.path.dirname(path) + '/'
f = FilePathField(path=path, recursive=True, match='^.*?\.py$')
f.choices.sort()
@@ -992,7 +993,7 @@ class FieldsTests(SimpleTestCase):
self.assertTrue(got[0].endswith(exp[0]))
def test_filepathfield_folders(self):
- path = os.path.dirname(__file__) + '/filepath_test_files/'
+ path = os.path.dirname(upath(__file__)) + '/filepath_test_files/'
f = FilePathField(path=path, allow_folders=True, allow_files=False)
f.choices.sort()
expected = [
diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
index 2d172ad0e0..a601e541c6 100644
--- a/tests/regressiontests/httpwrappers/tests.py
+++ b/tests/regressiontests/httpwrappers/tests.py
@@ -14,6 +14,7 @@ from django.http import (QueryDict, HttpResponse, HttpResponseRedirect,
parse_cookie)
from django.test import TestCase
from django.utils.encoding import smart_str
+from django.utils._os import upath
from django.utils import six
from django.utils import unittest
@@ -483,7 +484,7 @@ class StreamingHttpResponseTests(TestCase):
class FileCloseTests(TestCase):
def test_response(self):
- filename = os.path.join(os.path.dirname(__file__), 'abc.txt')
+ filename = os.path.join(os.path.dirname(upath(__file__)), 'abc.txt')
# file isn't closed until we close the response.
file1 = open(filename)
@@ -516,7 +517,7 @@ class FileCloseTests(TestCase):
self.assertTrue(file2.closed)
def test_streaming_response(self):
- filename = os.path.join(os.path.dirname(__file__), 'abc.txt')
+ filename = os.path.join(os.path.dirname(upath(__file__)), 'abc.txt')
# file isn't closed until we close the response.
file1 = open(filename)
diff --git a/tests/regressiontests/i18n/commands/compilation.py b/tests/regressiontests/i18n/commands/compilation.py
index c6ab77941b..2944469110 100644
--- a/tests/regressiontests/i18n/commands/compilation.py
+++ b/tests/regressiontests/i18n/commands/compilation.py
@@ -4,9 +4,10 @@ from django.core.management import call_command, CommandError
from django.test import TestCase
from django.test.utils import override_settings
from django.utils import translation, six
+from django.utils._os import upath
from django.utils.six import StringIO
-test_dir = os.path.abspath(os.path.dirname(__file__))
+test_dir = os.path.abspath(os.path.dirname(upath(__file__)))
class MessageCompilationTests(TestCase):
@@ -25,9 +26,9 @@ class PoFileTests(MessageCompilationTests):
def test_bom_rejection(self):
os.chdir(test_dir)
- with six.assertRaisesRegex(self, CommandError,
- "file has a BOM \(Byte Order Mark\)"):
+ with self.assertRaises(CommandError) as cm:
call_command('compilemessages', locale=self.LOCALE, stderr=StringIO())
+ self.assertIn("file has a BOM (Byte Order Mark)", cm.exception.args[0])
self.assertFalse(os.path.exists(self.MO_FILE))
diff --git a/tests/regressiontests/i18n/commands/extraction.py b/tests/regressiontests/i18n/commands/extraction.py
index ca2c3cc026..aa5efe1967 100644
--- a/tests/regressiontests/i18n/commands/extraction.py
+++ b/tests/regressiontests/i18n/commands/extraction.py
@@ -1,4 +1,5 @@
# -*- encoding: utf-8 -*-
+from __future__ import unicode_literals
import os
import re
@@ -6,6 +7,8 @@ import shutil
from django.core import management
from django.test import TestCase
+from django.utils.encoding import force_text
+from django.utils._os import upath
from django.utils.six import StringIO
@@ -17,7 +20,7 @@ class ExtractorTests(TestCase):
def setUp(self):
self._cwd = os.getcwd()
- self.test_dir = os.path.abspath(os.path.dirname(__file__))
+ self.test_dir = os.path.abspath(os.path.dirname(upath(__file__)))
def _rmrf(self, dname):
if os.path.commonprefix([self.test_dir, os.path.abspath(dname)]) != self.test_dir:
@@ -55,7 +58,7 @@ class BasicExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=LOCALE, verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = fp.read()
+ po_contents = force_text(fp.read())
self.assertTrue('#. Translators: This comment should be extracted' in po_contents)
self.assertTrue('This comment should not be extracted' not in po_contents)
# Comments in templates
@@ -83,7 +86,7 @@ class BasicExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=LOCALE, verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = fp.read()
+ po_contents = force_text(fp.read())
self.assertMsgId('Literal with a percent symbol at the end %%', po_contents)
self.assertMsgId('Literal with a percent %% symbol in the middle', po_contents)
self.assertMsgId('Completed 50%% of all the tasks', po_contents)
@@ -99,7 +102,7 @@ class BasicExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=LOCALE, verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = fp.read()
+ po_contents = force_text(fp.read())
self.assertMsgId('I think that 100%% is more that 50%% of anything.', po_contents)
self.assertMsgId('I think that 100%% is more that 50%% of %(obj)s.', po_contents)
self.assertMsgId("Blocktrans extraction shouldn't double escape this: %%, a=%(a)s", po_contents)
@@ -123,7 +126,7 @@ class BasicExtractorTests(ExtractorTests):
stdout = StringIO()
management.call_command('makemessages', locale=LOCALE, stdout=stdout)
os.remove('./code_sample.py')
- self.assertIn("code_sample.py:4", stdout.getvalue())
+ self.assertIn("code_sample.py:4", force_text(stdout.getvalue()))
def test_template_message_context_extractor(self):
"""
@@ -135,7 +138,7 @@ class BasicExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=LOCALE, verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = fp.read()
+ po_contents = force_text(fp.read())
# {% trans %}
self.assertTrue('msgctxt "Special trans context #1"' in po_contents)
self.assertTrue("Translatable literal #7a" in po_contents)
@@ -161,7 +164,7 @@ class BasicExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=LOCALE, verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = fp.read()
+ po_contents = force_text(fp.read())
# {% trans %}
self.assertTrue('msgctxt "Context wrapped in double quotes"' in po_contents)
self.assertTrue('msgctxt "Context wrapped in single quotes"' in po_contents)
@@ -216,7 +219,7 @@ class SymlinkExtractorTests(ExtractorTests):
def setUp(self):
self._cwd = os.getcwd()
- self.test_dir = os.path.abspath(os.path.dirname(__file__))
+ self.test_dir = os.path.abspath(os.path.dirname(upath(__file__)))
self.symlinked_dir = os.path.join(self.test_dir, 'templates_symlinked')
def tearDown(self):
@@ -238,7 +241,7 @@ class SymlinkExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=LOCALE, verbosity=0, symlinks=True)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = fp.read()
+ po_contents = force_text(fp.read())
self.assertMsgId('This literal should be included.', po_contents)
self.assertTrue('templates_symlinked/test.html' in po_contents)
@@ -250,7 +253,7 @@ class CopyPluralFormsExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=LOCALE, verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = fp.read()
+ po_contents = force_text(fp.read())
self.assertTrue('Plural-Forms: nplurals=2; plural=(n != 1)' in po_contents)
@@ -261,7 +264,7 @@ class NoWrapExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=True)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = fp.read()
+ po_contents = force_text(fp.read())
self.assertMsgId('This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option.', po_contents)
def test_no_wrap_disabled(self):
@@ -269,7 +272,7 @@ class NoWrapExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=False)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = fp.read()
+ po_contents = force_text(fp.read())
self.assertMsgId('""\n"This literal should also be included wrapped or not wrapped depending on the "\n"use of the --no-wrap option."', po_contents, use_quotes=False)
@@ -280,7 +283,7 @@ class NoLocationExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=True)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = fp.read()
+ po_contents = force_text(fp.read())
self.assertFalse('#: templates/test.html:55' in po_contents)
def test_no_location_disabled(self):
@@ -288,5 +291,5 @@ class NoLocationExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=False)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = fp.read()
+ po_contents = force_text(fp.read())
self.assertTrue('#: templates/test.html:55' in po_contents)
diff --git a/tests/regressiontests/i18n/contenttypes/tests.py b/tests/regressiontests/i18n/contenttypes/tests.py
index 178232f543..5e8a9823e1 100644
--- a/tests/regressiontests/i18n/contenttypes/tests.py
+++ b/tests/regressiontests/i18n/contenttypes/tests.py
@@ -6,6 +6,7 @@ import os
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from django.test.utils import override_settings
+from django.utils._os import upath
from django.utils import six
from django.utils import translation
@@ -13,7 +14,7 @@ from django.utils import translation
@override_settings(
USE_I18N=True,
LOCALE_PATHS=(
- os.path.join(os.path.dirname(__file__), 'locale'),
+ os.path.join(os.path.dirname(upath(__file__)), 'locale'),
),
LANGUAGE_CODE='en',
LANGUAGES=(
diff --git a/tests/regressiontests/i18n/patterns/tests.py b/tests/regressiontests/i18n/patterns/tests.py
index 73c9f56711..358cdf65db 100644
--- a/tests/regressiontests/i18n/patterns/tests.py
+++ b/tests/regressiontests/i18n/patterns/tests.py
@@ -7,16 +7,17 @@ from django.core.urlresolvers import reverse, clear_url_caches
from django.test import TestCase
from django.test.utils import override_settings
from django.template import Template, Context
+from django.utils._os import upath
from django.utils import translation
@override_settings(
USE_I18N=True,
LOCALE_PATHS=(
- os.path.join(os.path.dirname(__file__), 'locale'),
+ os.path.join(os.path.dirname(upath(__file__)), 'locale'),
),
TEMPLATE_DIRS=(
- os.path.join(os.path.dirname(__file__), 'templates'),
+ os.path.join(os.path.dirname(upath(__file__)), 'templates'),
),
LANGUAGE_CODE='en',
LANGUAGES=(
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
index 2e0c097a19..dcc288e600 100644
--- a/tests/regressiontests/i18n/tests.py
+++ b/tests/regressiontests/i18n/tests.py
@@ -18,6 +18,7 @@ from django.utils.formats import (get_format, date_format, time_format,
number_format)
from django.utils.importlib import import_module
from django.utils.numberformat import format as nformat
+from django.utils._os import upath
from django.utils.safestring import mark_safe, SafeBytes, SafeString, SafeText
from django.utils import six
from django.utils.six import PY3
@@ -44,7 +45,7 @@ from .patterns.tests import (URLRedirectWithoutTrailingSlashTests,
URLPrefixTests, URLResponseTests, URLRedirectTests, PathUnusedTests)
-here = os.path.dirname(os.path.abspath(__file__))
+here = os.path.dirname(os.path.abspath(upath(__file__)))
extended_locale_paths = settings.LOCALE_PATHS + (
os.path.join(here, 'other', 'locale'),
)
@@ -666,8 +667,8 @@ class FormattingTests(TestCase):
with self.settings(USE_L10N=True,
FORMAT_MODULE_PATH='regressiontests.i18n.other.locale'):
with translation.override('de', deactivate=True):
- old = "%r" % get_format_modules(reverse=True)
- new = "%r" % get_format_modules(reverse=True) # second try
+ old = str("%r") % get_format_modules(reverse=True)
+ new = str("%r") % get_format_modules(reverse=True) # second try
self.assertEqual(new, old, 'Value returned by get_formats_modules() must be preserved between calls.')
def test_localize_templatetag_and_filter(self):
diff --git a/tests/regressiontests/logging_tests/tests.py b/tests/regressiontests/logging_tests/tests.py
index 19ee06eccc..07804eb398 100644
--- a/tests/regressiontests/logging_tests/tests.py
+++ b/tests/regressiontests/logging_tests/tests.py
@@ -9,6 +9,7 @@ from django.conf import compat_patch_logging_config, LazySettings
from django.core import mail
from django.test import TestCase, RequestFactory
from django.test.utils import override_settings
+from django.utils.encoding import force_text
from django.utils.log import CallbackFilter, RequireDebugFalse
from django.utils.six import StringIO
from django.utils.unittest import skipUnless
@@ -154,13 +155,13 @@ class WarningLoggerTests(TestCase):
output = StringIO()
self.logger.handlers[0].stream = output
warnings.warn('Foo Deprecated', DeprecationWarning)
- self.assertTrue('Foo Deprecated' in output.getvalue())
+ self.assertTrue('Foo Deprecated' in force_text(output.getvalue()))
def test_warnings_capture_debug_false(self):
output = StringIO()
self.logger.handlers[0].stream = output
warnings.warn('Foo Deprecated', DeprecationWarning)
- self.assertFalse('Foo Deprecated' in output.getvalue())
+ self.assertFalse('Foo Deprecated' in force_text(output.getvalue()))
class CallbackFilterTest(TestCase):
diff --git a/tests/regressiontests/model_fields/imagefield.py b/tests/regressiontests/model_fields/imagefield.py
index 7446f222ff..df0215db3d 100644
--- a/tests/regressiontests/model_fields/imagefield.py
+++ b/tests/regressiontests/model_fields/imagefield.py
@@ -6,6 +6,7 @@ import shutil
from django.core.files import File
from django.core.files.images import ImageFile
from django.test import TestCase
+from django.utils._os import upath
from django.utils.unittest import skipIf
from .models import Image
@@ -43,10 +44,10 @@ class ImageFieldTestMixin(object):
shutil.rmtree(temp_storage_dir)
os.mkdir(temp_storage_dir)
- file_path1 = os.path.join(os.path.dirname(__file__), "4x8.png")
+ file_path1 = os.path.join(os.path.dirname(upath(__file__)), "4x8.png")
self.file1 = self.File(open(file_path1, 'rb'))
- file_path2 = os.path.join(os.path.dirname(__file__), "8x4.png")
+ file_path2 = os.path.join(os.path.dirname(upath(__file__)), "8x4.png")
self.file2 = self.File(open(file_path2, 'rb'))
def tearDown(self):
diff --git a/tests/regressiontests/model_forms_regress/models.py b/tests/regressiontests/model_forms_regress/models.py
index f6e08d24dc..2c2fd39158 100644
--- a/tests/regressiontests/model_forms_regress/models.py
+++ b/tests/regressiontests/model_forms_regress/models.py
@@ -5,6 +5,7 @@ import os
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
+from django.utils._os import upath
class Person(models.Model):
@@ -19,7 +20,7 @@ class Triple(models.Model):
unique_together = (('left', 'middle'), ('middle', 'right'))
class FilePathModel(models.Model):
- path = models.FilePathField(path=os.path.dirname(__file__), match=".*\.py$", blank=True)
+ path = models.FilePathField(path=os.path.dirname(upath(__file__)), match=".*\.py$", blank=True)
@python_2_unicode_compatible
class Publication(models.Model):
diff --git a/tests/regressiontests/servers/tests.py b/tests/regressiontests/servers/tests.py
index f54e34ce28..1a7552ed11 100644
--- a/tests/regressiontests/servers/tests.py
+++ b/tests/regressiontests/servers/tests.py
@@ -15,11 +15,12 @@ from django.test import LiveServerTestCase
from django.core.servers.basehttp import WSGIServerException
from django.test.utils import override_settings
from django.utils.http import urlencode
+from django.utils._os import upath
from .models import Person
-TEST_ROOT = os.path.dirname(__file__)
+TEST_ROOT = os.path.dirname(upath(__file__))
TEST_SETTINGS = {
'MEDIA_URL': '/media/',
'MEDIA_ROOT': os.path.join(TEST_ROOT, 'media'),
diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py
index 0c8e7db17d..90c8621d0b 100644
--- a/tests/regressiontests/staticfiles_tests/tests.py
+++ b/tests/regressiontests/staticfiles_tests/tests.py
@@ -15,14 +15,14 @@ from django.core.exceptions import ImproperlyConfigured
from django.core.management import call_command
from django.test import TestCase
from django.test.utils import override_settings
-from django.utils.encoding import smart_text
+from django.utils.encoding import force_text
from django.utils.functional import empty
-from django.utils._os import rmtree_errorhandler
+from django.utils._os import rmtree_errorhandler, upath
from django.utils import six
from django.contrib.staticfiles import finders, storage
-TEST_ROOT = os.path.dirname(__file__)
+TEST_ROOT = os.path.dirname(upath(__file__))
TEST_SETTINGS = {
'DEBUG': True,
'MEDIA_URL': '/media/',
@@ -77,7 +77,7 @@ class BaseStaticFilesTestCase(object):
os.unlink(self._backup_filepath)
def assertFileContains(self, filepath, text):
- self.assertIn(text, self._get_file(smart_text(filepath)),
+ self.assertIn(text, self._get_file(force_text(filepath)),
"'%s' not in '%s'" % (text, filepath))
def assertFileNotFound(self, filepath):
@@ -195,7 +195,7 @@ class TestFindStatic(CollectionTestCase, TestDefaults):
call_command('findstatic', filepath, all=False, verbosity=0, stdout=out)
out.seek(0)
lines = [l.strip() for l in out.readlines()]
- with codecs.open(smart_text(lines[1].strip()), "r", "utf-8") as f:
+ with codecs.open(force_text(lines[1].strip()), "r", "utf-8") as f:
return f.read()
def test_all_files(self):
@@ -207,8 +207,8 @@ class TestFindStatic(CollectionTestCase, TestDefaults):
out.seek(0)
lines = [l.strip() for l in out.readlines()]
self.assertEqual(len(lines), 3) # three because there is also the "Found <file> here" line
- self.assertIn('project', lines[1])
- self.assertIn('apps', lines[2])
+ self.assertIn('project', force_text(lines[1]))
+ self.assertIn('apps', force_text(lines[2]))
class TestCollection(CollectionTestCase, TestDefaults):
diff --git a/tests/regressiontests/templates/loaders.py b/tests/regressiontests/templates/loaders.py
index 7fbb0841f9..b77965203f 100644
--- a/tests/regressiontests/templates/loaders.py
+++ b/tests/regressiontests/templates/loaders.py
@@ -18,6 +18,7 @@ from django.template import TemplateDoesNotExist, Context
from django.template.loaders.eggs import Loader as EggLoader
from django.template import loader
from django.utils import unittest, six
+from django.utils._os import upath
from django.utils.six import StringIO
@@ -111,9 +112,9 @@ class CachedLoader(unittest.TestCase):
def test_templatedir_caching(self):
"Check that the template directories form part of the template cache key. Refs #13573"
# Retrive a template specifying a template directory to check
- t1, name = loader.find_template('test.html', (os.path.join(os.path.dirname(__file__), 'templates', 'first'),))
+ t1, name = loader.find_template('test.html', (os.path.join(os.path.dirname(upath(__file__)), 'templates', 'first'),))
# Now retrieve the same template name, but from a different directory
- t2, name = loader.find_template('test.html', (os.path.join(os.path.dirname(__file__), 'templates', 'second'),))
+ t2, name = loader.find_template('test.html', (os.path.join(os.path.dirname(upath(__file__)), 'templates', 'second'),))
# The two templates should not have the same content
self.assertNotEqual(t1.render(Context({})), t2.render(Context({})))
@@ -123,7 +124,7 @@ class RenderToStringTest(unittest.TestCase):
def setUp(self):
self._old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
settings.TEMPLATE_DIRS = (
- os.path.join(os.path.dirname(__file__), 'templates'),
+ os.path.join(os.path.dirname(upath(__file__)), 'templates'),
)
def tearDown(self):
diff --git a/tests/regressiontests/templates/response.py b/tests/regressiontests/templates/response.py
index a2a76a3310..c4da50af6b 100644
--- a/tests/regressiontests/templates/response.py
+++ b/tests/regressiontests/templates/response.py
@@ -11,6 +11,7 @@ from django.template import Template, Context
from django.template.response import (TemplateResponse, SimpleTemplateResponse,
ContentNotRenderedError)
from django.test.utils import override_settings
+from django.utils._os import upath
def test_processor(request):
return {'processors': 'yes'}
@@ -206,7 +207,7 @@ class SimpleTemplateResponseTest(TestCase):
@override_settings(
TEMPLATE_CONTEXT_PROCESSORS=[test_processor_name],
- TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__),'templates')),
+ TEMPLATE_DIRS=(os.path.join(os.path.dirname(upath(__file__)), 'templates')),
)
class TemplateResponseTest(TestCase):
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 65d6e727e1..9ec487d06c 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -30,6 +30,7 @@ from django.test.utils import (setup_test_template_loader,
from django.utils import unittest
from django.utils.encoding import python_2_unicode_compatible
from django.utils.formats import date_format
+from django.utils._os import upath
from django.utils.translation import activate, deactivate, ugettext as _
from django.utils.safestring import mark_safe
from django.utils import six
@@ -423,7 +424,7 @@ class Templates(TestCase):
# Set ALLOWED_INCLUDE_ROOTS so that ssi works.
old_allowed_include_roots = settings.ALLOWED_INCLUDE_ROOTS
settings.ALLOWED_INCLUDE_ROOTS = (
- os.path.dirname(os.path.abspath(__file__)),
+ os.path.dirname(os.path.abspath(upath(__file__))),
)
# Warm the URL reversing cache. This ensures we don't pay the cost
@@ -514,7 +515,7 @@ class Templates(TestCase):
def get_template_tests(self):
# SYNTAX --
# 'template_name': ('template contents', 'context dict', 'expected string output' or Exception class)
- basedir = os.path.dirname(os.path.abspath(__file__))
+ basedir = os.path.dirname(os.path.abspath(upath(__file__)))
tests = {
### BASIC SYNTAX ################################################
@@ -1649,7 +1650,7 @@ class TemplateTagLoading(unittest.TestCase):
def setUp(self):
self.old_path = sys.path[:]
self.old_apps = settings.INSTALLED_APPS
- self.egg_dir = '%s/eggs' % os.path.dirname(__file__)
+ self.egg_dir = '%s/eggs' % os.path.dirname(upath(__file__))
self.old_tag_modules = template_base.templatetags_modules
template_base.templatetags_modules = []
diff --git a/tests/regressiontests/test_client_regress/tests.py b/tests/regressiontests/test_client_regress/tests.py
index f424321663..5ba5d3c4b3 100644
--- a/tests/regressiontests/test_client_regress/tests.py
+++ b/tests/regressiontests/test_client_regress/tests.py
@@ -16,12 +16,13 @@ from django.test import Client, TestCase
from django.test.client import encode_file, RequestFactory
from django.test.utils import ContextList, override_settings, str_prefix
from django.template.response import SimpleTemplateResponse
+from django.utils._os import upath
from django.utils.translation import ugettext_lazy
from django.http import HttpResponse
@override_settings(
- TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),)
+ TEMPLATE_DIRS=(os.path.join(os.path.dirname(upath(__file__)), 'templates'),)
)
class AssertContainsTests(TestCase):
def test_contains(self):
@@ -629,7 +630,7 @@ class TemplateExceptionTests(TestCase):
template_loader.reset()
@override_settings(
- TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'bad_templates'),)
+ TEMPLATE_DIRS=(os.path.join(os.path.dirname(upath(__file__)), 'bad_templates'),)
)
def test_bad_404_template(self):
"Errors found when rendering 404 error templates are re-raised"
diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
index 85f18db4c5..eb3afe8201 100644
--- a/tests/regressiontests/urlpatterns_reverse/tests.py
+++ b/tests/regressiontests/urlpatterns_reverse/tests.py
@@ -237,7 +237,7 @@ class ResolverTests(unittest.TestCase):
self.assertEqual(len(e.args[0]['tried']), len(url_types_names), 'Wrong number of tried URLs returned. Expected %s, got %s.' % (len(url_types_names), len(e.args[0]['tried'])))
for tried, expected in zip(e.args[0]['tried'], url_types_names):
for t, e in zip(tried, expected):
- self.assertTrue(isinstance(t, e['type']), '%s is not an instance of %s' % (t, e['type']))
+ self.assertTrue(isinstance(t, e['type']), str('%s is not an instance of %s') % (t, e['type']))
if 'name' in e:
if not e['name']:
self.assertTrue(t.name is None, 'Expected no URL name but found %s.' % t.name)
diff --git a/tests/regressiontests/utils/archive.py b/tests/regressiontests/utils/archive.py
index 5575f340f6..8861b4a577 100644
--- a/tests/regressiontests/utils/archive.py
+++ b/tests/regressiontests/utils/archive.py
@@ -4,9 +4,10 @@ import tempfile
from django.utils import unittest
from django.utils.archive import Archive, extract
+from django.utils._os import upath
-TEST_DIR = os.path.join(os.path.dirname(__file__), 'archives')
+TEST_DIR = os.path.join(os.path.dirname(upath(__file__)), 'archives')
class ArchiveTester(object):
diff --git a/tests/regressiontests/utils/module_loading.py b/tests/regressiontests/utils/module_loading.py
index dffb51966c..3fc92b0862 100644
--- a/tests/regressiontests/utils/module_loading.py
+++ b/tests/regressiontests/utils/module_loading.py
@@ -6,6 +6,7 @@ from zipimport import zipimporter
from django.utils import unittest
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule
+from django.utils._os import upath
class DefaultLoader(unittest.TestCase):
@@ -50,7 +51,7 @@ class DefaultLoader(unittest.TestCase):
class EggLoader(unittest.TestCase):
def setUp(self):
self.old_path = sys.path[:]
- self.egg_dir = '%s/eggs' % os.path.dirname(__file__)
+ self.egg_dir = '%s/eggs' % os.path.dirname(upath(__file__))
def tearDown(self):
sys.path = self.old_path
diff --git a/tests/regressiontests/views/tests/debug.py b/tests/regressiontests/views/tests/debug.py
index e616d184b8..4fdaad5010 100644
--- a/tests/regressiontests/views/tests/debug.py
+++ b/tests/regressiontests/views/tests/debug.py
@@ -14,6 +14,7 @@ from django.core.urlresolvers import reverse
from django.test import TestCase, RequestFactory
from django.test.utils import (override_settings, setup_test_template_loader,
restore_template_loaders)
+from django.utils.encoding import force_text
from django.views.debug import ExceptionReporter
from .. import BrokenException, except_args
@@ -306,15 +307,16 @@ class ExceptionReportTestMixin(object):
self.assertEqual(len(mail.outbox), 1)
email = mail.outbox[0]
# Frames vars are never shown in plain text email reports.
- self.assertNotIn('cooked_eggs', email.body)
- self.assertNotIn('scrambled', email.body)
- self.assertNotIn('sauce', email.body)
- self.assertNotIn('worcestershire', email.body)
+ body = force_text(email.body)
+ self.assertNotIn('cooked_eggs', body)
+ self.assertNotIn('scrambled', body)
+ self.assertNotIn('sauce', body)
+ self.assertNotIn('worcestershire', body)
if check_for_POST_params:
for k, v in self.breakfast_data.items():
# All POST parameters are shown.
- self.assertIn(k, email.body)
- self.assertIn(v, email.body)
+ self.assertIn(k, body)
+ self.assertIn(v, body)
def verify_safe_email(self, view, check_for_POST_params=True):
"""
@@ -327,20 +329,21 @@ class ExceptionReportTestMixin(object):
self.assertEqual(len(mail.outbox), 1)
email = mail.outbox[0]
# Frames vars are never shown in plain text email reports.
- self.assertNotIn('cooked_eggs', email.body)
- self.assertNotIn('scrambled', email.body)
- self.assertNotIn('sauce', email.body)
- self.assertNotIn('worcestershire', email.body)
+ body = force_text(email.body)
+ self.assertNotIn('cooked_eggs', body)
+ self.assertNotIn('scrambled', body)
+ self.assertNotIn('sauce', body)
+ self.assertNotIn('worcestershire', body)
if check_for_POST_params:
for k, v in self.breakfast_data.items():
# All POST parameters' names are shown.
- self.assertIn(k, email.body)
+ self.assertIn(k, body)
# Non-sensitive POST parameters' values are shown.
- self.assertIn('baked-beans-value', email.body)
- self.assertIn('hash-brown-value', email.body)
+ self.assertIn('baked-beans-value', body)
+ self.assertIn('hash-brown-value', body)
# Sensitive POST parameters' values are not shown.
- self.assertNotIn('sausage-value', email.body)
- self.assertNotIn('bacon-value', email.body)
+ self.assertNotIn('sausage-value', body)
+ self.assertNotIn('bacon-value', body)
def verify_paranoid_email(self, view):
"""
@@ -353,15 +356,16 @@ class ExceptionReportTestMixin(object):
self.assertEqual(len(mail.outbox), 1)
email = mail.outbox[0]
# Frames vars are never shown in plain text email reports.
- self.assertNotIn('cooked_eggs', email.body)
- self.assertNotIn('scrambled', email.body)
- self.assertNotIn('sauce', email.body)
- self.assertNotIn('worcestershire', email.body)
+ body = force_text(email.body)
+ self.assertNotIn('cooked_eggs', body)
+ self.assertNotIn('scrambled', body)
+ self.assertNotIn('sauce', body)
+ self.assertNotIn('worcestershire', body)
for k, v in self.breakfast_data.items():
# All POST parameters' names are shown.
- self.assertIn(k, email.body)
+ self.assertIn(k, body)
# No POST parameters' values are shown.
- self.assertNotIn(v, email.body)
+ self.assertNotIn(v, body)
class ExceptionReporterFilterTests(TestCase, ExceptionReportTestMixin):
diff --git a/tests/regressiontests/views/tests/i18n.py b/tests/regressiontests/views/tests/i18n.py
index 671becbbc9..f1f5b175c8 100644
--- a/tests/regressiontests/views/tests/i18n.py
+++ b/tests/regressiontests/views/tests/i18n.py
@@ -9,6 +9,7 @@ from django.core.urlresolvers import reverse
from django.test import LiveServerTestCase, TestCase
from django.test.utils import override_settings
from django.utils import six, unittest
+from django.utils._os import upath
from django.utils.translation import override
from django.utils.text import javascript_quote
@@ -152,7 +153,7 @@ class JsI18NTestsMultiPackage(TestCase):
def testI18NWithLocalePaths(self):
extended_locale_paths = settings.LOCALE_PATHS + (
path.join(path.dirname(
- path.dirname(path.abspath(__file__))), 'app3', 'locale'),)
+ path.dirname(path.abspath(upath(__file__)))), 'app3', 'locale'),)
with self.settings(LANGUAGE_CODE='es-ar', LOCALE_PATHS=extended_locale_paths):
with override('es-ar'):
response = self.client.get('/views/jsi18n/')
diff --git a/tests/regressiontests/views/urls.py b/tests/regressiontests/views/urls.py
index ae3b9c0a9e..2c06557ae9 100644
--- a/tests/regressiontests/views/urls.py
+++ b/tests/regressiontests/views/urls.py
@@ -4,11 +4,12 @@ from __future__ import absolute_import
from os import path
from django.conf.urls import patterns, url, include
+from django.utils._os import upath
from . import views
-base_dir = path.dirname(path.abspath(__file__))
+base_dir = path.dirname(path.abspath(upath(__file__)))
media_dir = path.join(base_dir, 'media')
locale_dir = path.join(base_dir, 'locale')
diff --git a/tests/runtests.py b/tests/runtests.py
index 90e2dc2d65..8c56e273b5 100755
--- a/tests/runtests.py
+++ b/tests/runtests.py
@@ -7,6 +7,7 @@ import tempfile
import warnings
from django import contrib
+from django.utils._os import upath
from django.utils import six
# databrowse is deprecated, but we still want to run its tests
@@ -19,8 +20,8 @@ REGRESSION_TESTS_DIR_NAME = 'regressiontests'
TEST_TEMPLATE_DIR = 'templates'
-RUNTESTS_DIR = os.path.dirname(__file__)
-CONTRIB_DIR = os.path.dirname(contrib.__file__)
+RUNTESTS_DIR = os.path.dirname(upath(__file__))
+CONTRIB_DIR = os.path.dirname(upath(contrib.__file__))
MODEL_TEST_DIR = os.path.join(RUNTESTS_DIR, MODEL_TESTS_DIR_NAME)
REGRESSION_TEST_DIR = os.path.join(RUNTESTS_DIR, REGRESSION_TESTS_DIR_NAME)
TEMP_DIR = tempfile.mkdtemp(prefix='django_')
@@ -192,7 +193,7 @@ def bisect_tests(bisection_label, options, test_labels):
pass
subprocess_args = [
- sys.executable, __file__, '--settings=%s' % options.settings]
+ sys.executable, upath(__file__), '--settings=%s' % options.settings]
if options.failfast:
subprocess_args.append('--failfast')
if options.verbosity:
@@ -253,7 +254,7 @@ def paired_tests(paired_test, options, test_labels):
pass
subprocess_args = [
- sys.executable, __file__, '--settings=%s' % options.settings]
+ sys.executable, upath(__file__), '--settings=%s' % options.settings]
if options.failfast:
subprocess_args.append('--failfast')
if options.verbosity: