-
diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py
index 94963b4..cb0c116 100644
a
|
b
|
from django.core import urlresolvers
|
14 | 14 | from django.contrib.admindocs import utils |
15 | 15 | from django.contrib.sites.models import Site |
16 | 16 | from django.utils.importlib import import_module |
| 17 | from django.utils._os import upath |
17 | 18 | from django.utils import six |
18 | 19 | from django.utils.translation import ugettext as _ |
19 | 20 | from django.utils.safestring import mark_safe |
… |
… |
def load_all_installed_template_libraries():
|
311 | 312 | try: |
312 | 313 | libraries = [ |
313 | 314 | os.path.splitext(p)[0] |
314 | | for p in os.listdir(os.path.dirname(mod.__file__)) |
| 315 | for p in os.listdir(os.path.dirname(upath(mod.__file__))) |
315 | 316 | if p.endswith('.py') and p[0].isalpha() |
316 | 317 | ] |
317 | 318 | except OSError: |
-
diff --git a/django/contrib/auth/tests/context_processors.py b/django/contrib/auth/tests/context_processors.py
index 32fea8a..f846a82 100644
a
|
b
|
from django.contrib.auth.context_processors import PermWrapper, PermLookupDict
|
9 | 9 | from django.db.models import Q |
10 | 10 | from django.test import TestCase |
11 | 11 | from django.test.utils import override_settings |
| 12 | from django.utils._os import upath |
12 | 13 | |
13 | 14 | |
14 | 15 | class MockUser(object): |
… |
… |
class PermWrapperTests(TestCase):
|
63 | 64 | @skipIfCustomUser |
64 | 65 | @override_settings( |
65 | 66 | TEMPLATE_DIRS=( |
66 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 67 | os.path.join(os.path.dirname(upath(__file__)), 'templates'), |
67 | 68 | ), |
68 | 69 | USE_TZ=False, # required for loading the fixture |
69 | 70 | PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',), |
-
diff --git a/django/contrib/auth/tests/forms.py b/django/contrib/auth/tests/forms.py
index 286652e..2589068 100644
a
|
b
|
from django.forms.fields import Field, EmailField
|
11 | 11 | from django.test import TestCase |
12 | 12 | from django.test.utils import override_settings |
13 | 13 | from django.utils.encoding import force_text |
| 14 | from django.utils._os import upath |
14 | 15 | from django.utils import translation |
15 | 16 | from django.utils.translation import ugettext as _ |
16 | 17 | |
… |
… |
class PasswordResetFormTest(TestCase):
|
331 | 332 | self.assertEqual(form.cleaned_data['email'], email) |
332 | 333 | |
333 | 334 | def test_custom_email_subject(self): |
334 | | template_path = os.path.join(os.path.dirname(__file__), 'templates') |
| 335 | template_path = os.path.join(os.path.dirname(upath(__file__)), 'templates') |
335 | 336 | with self.settings(TEMPLATE_DIRS=(template_path,)): |
336 | 337 | data = {'email': 'testclient@example.com'} |
337 | 338 | form = PasswordResetForm(data) |
-
diff --git a/django/contrib/auth/tests/views.py b/django/contrib/auth/tests/views.py
index b97d4a7..0e83ca4 100644
a
|
b
|
from django.http import QueryDict
|
11 | 11 | from django.utils.encoding import force_text |
12 | 12 | from django.utils.html import escape |
13 | 13 | from django.utils.http import urlquote |
| 14 | from django.utils._os import upath |
14 | 15 | from django.test import TestCase |
15 | 16 | from django.test.utils import override_settings |
16 | 17 | |
… |
… |
from django.contrib.auth.tests.utils import skipIfCustomUser
|
27 | 28 | LANGUAGE_CODE='en', |
28 | 29 | TEMPLATE_LOADERS=global_settings.TEMPLATE_LOADERS, |
29 | 30 | TEMPLATE_DIRS=( |
30 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 31 | os.path.join(os.path.dirname(upath(__file__)), 'templates'), |
31 | 32 | ), |
32 | 33 | USE_TZ=False, |
33 | 34 | PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',), |
-
diff --git a/django/contrib/formtools/tests/__init__.py b/django/contrib/formtools/tests/__init__.py
index a21ffde..aa7d5ff 100644
a
|
b
|
from django.contrib.formtools.wizard import FormWizard
|
14 | 14 | from django.test import TestCase |
15 | 15 | from django.test.html import parse_html |
16 | 16 | from django.test.utils import override_settings |
| 17 | from django.utils._os import upath |
17 | 18 | from django.utils import unittest |
18 | 19 | |
19 | 20 | from django.contrib.formtools.tests.wizard import * |
… |
… |
class TestFormPreview(preview.FormPreview):
|
36 | 37 | |
37 | 38 | @override_settings( |
38 | 39 | TEMPLATE_DIRS=( |
39 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 40 | os.path.join(os.path.dirname(upath(__file__)), 'templates'), |
40 | 41 | ), |
41 | 42 | ) |
42 | 43 | class PreviewTests(TestCase): |
… |
… |
class DummyRequest(http.HttpRequest):
|
214 | 215 | @override_settings( |
215 | 216 | SECRET_KEY="123", |
216 | 217 | TEMPLATE_DIRS=( |
217 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 218 | os.path.join(os.path.dirname(upath(__file__)), 'templates'), |
218 | 219 | ), |
219 | 220 | ) |
220 | 221 | class WizardTests(TestCase): |
-
diff --git a/django/contrib/formtools/tests/wizard/wizardtests/tests.py b/django/contrib/formtools/tests/wizard/wizardtests/tests.py
index 6403a55..4aaea7d 100644
a
|
b
|
from django.conf import settings
|
9 | 9 | from django.contrib.auth.models import User |
10 | 10 | from django.contrib.formtools.wizard.views import CookieWizardView |
11 | 11 | from django.contrib.formtools.tests.wizard.forms import UserForm, UserFormSet |
| 12 | from django.utils._os import upath |
12 | 13 | |
13 | 14 | |
14 | 15 | class WizardTests(object): |
… |
… |
class WizardTests(object):
|
86 | 87 | self.assertEqual(response.context['wizard']['steps'].current, 'form2') |
87 | 88 | |
88 | 89 | post_data = self.wizard_step_data[1] |
89 | | post_data['form2-file1'] = open(__file__, 'rb') |
| 90 | post_data['form2-file1'] = open(upath(__file__), 'rb') |
90 | 91 | response = self.client.post(self.wizard_url, post_data) |
91 | 92 | self.assertEqual(response.status_code, 200) |
92 | 93 | self.assertEqual(response.context['wizard']['steps'].current, 'form3') |
… |
… |
class WizardTests(object):
|
99 | 100 | self.assertEqual(response.status_code, 200) |
100 | 101 | |
101 | 102 | all_data = response.context['form_list'] |
102 | | with open(__file__, 'rb') as f: |
| 103 | with open(upath(__file__), 'rb') as f: |
103 | 104 | self.assertEqual(all_data[1]['file1'].read(), f.read()) |
104 | 105 | all_data[1]['file1'].close() |
105 | 106 | del all_data[1]['file1'] |
… |
… |
class WizardTests(object):
|
118 | 119 | self.assertEqual(response.status_code, 200) |
119 | 120 | |
120 | 121 | post_data = self.wizard_step_data[1] |
121 | | with open(__file__, 'rb') as post_file: |
| 122 | with open(upath(__file__), 'rb') as post_file: |
122 | 123 | post_data['form2-file1'] = post_file |
123 | 124 | response = self.client.post(self.wizard_url, post_data) |
124 | 125 | self.assertEqual(response.status_code, 200) |
… |
… |
class WizardTests(object):
|
130 | 131 | self.assertEqual(response.status_code, 200) |
131 | 132 | |
132 | 133 | all_data = response.context['all_cleaned_data'] |
133 | | with open(__file__, 'rb') as f: |
| 134 | with open(upath(__file__), 'rb') as f: |
134 | 135 | self.assertEqual(all_data['file1'].read(), f.read()) |
135 | 136 | all_data['file1'].close() |
136 | 137 | del all_data['file1'] |
… |
… |
class WizardTests(object):
|
150 | 151 | |
151 | 152 | post_data = self.wizard_step_data[1] |
152 | 153 | post_data['form2-file1'].close() |
153 | | post_data['form2-file1'] = open(__file__, 'rb') |
| 154 | post_data['form2-file1'] = open(upath(__file__), 'rb') |
154 | 155 | response = self.client.post(self.wizard_url, post_data) |
155 | 156 | self.assertEqual(response.status_code, 200) |
156 | 157 | |
… |
… |
class WizardTests(object):
|
178 | 179 | |
179 | 180 | post_data = self.wizard_step_data[1] |
180 | 181 | post_data['form2-file1'].close() |
181 | | post_data['form2-file1'] = open(__file__, 'rb') |
| 182 | post_data['form2-file1'] = open(upath(__file__), 'rb') |
182 | 183 | response = self.client.post(self.wizard_url, post_data) |
183 | 184 | self.assertEqual(response.status_code, 200) |
184 | 185 | self.assertEqual(response.context['wizard']['steps'].current, 'form3') |
… |
… |
class WizardTestKwargs(TestCase):
|
291 | 292 | self.wizard_step_data[0]['form1-user'] = self.testuser.pk |
292 | 293 | |
293 | 294 | def test_template(self): |
294 | | templates = os.path.join(os.path.dirname(__file__), 'templates') |
| 295 | templates = os.path.join(os.path.dirname(upath(__file__)), 'templates') |
295 | 296 | with self.settings( |
296 | 297 | TEMPLATE_DIRS=list(settings.TEMPLATE_DIRS) + [templates]): |
297 | 298 | response = self.client.get(self.wizard_url) |
-
diff --git a/django/contrib/gis/geometry/test_data.py b/django/contrib/gis/geometry/test_data.py
index b0f6e1a..e13e858 100644
a
|
b
|
import os
|
7 | 7 | |
8 | 8 | from django.contrib import gis |
9 | 9 | from django.utils import six |
| 10 | from django.utils._os import upath |
10 | 11 | |
11 | 12 | |
12 | 13 | # This global used to store reference geometry data. |
13 | 14 | GEOMETRIES = None |
14 | 15 | |
15 | 16 | # Path where reference test data is located. |
16 | | TEST_DATA = os.path.join(os.path.dirname(gis.__file__), 'tests', 'data') |
| 17 | TEST_DATA = os.path.join(os.path.dirname(upath(gis.__file__)), 'tests', 'data') |
17 | 18 | |
18 | 19 | |
19 | 20 | def tuplize(seq): |
-
diff --git a/django/contrib/gis/tests/geo3d/tests.py b/django/contrib/gis/tests/geo3d/tests.py
index f7590fe..6b40164 100644
a
|
b
|
from django.contrib.gis.db.models import Union, Extent3D
|
7 | 7 | from django.contrib.gis.geos import GEOSGeometry, LineString, Point, Polygon |
8 | 8 | from django.contrib.gis.utils import LayerMapping, LayerMapError |
9 | 9 | from django.test import TestCase |
| 10 | from django.utils._os import upath |
10 | 11 | |
11 | 12 | from .models import (City3D, Interstate2D, Interstate3D, InterstateProj2D, |
12 | 13 | InterstateProj3D, Point2D, Point3D, MultiPoint3D, Polygon2D, Polygon3D) |
13 | 14 | |
14 | 15 | |
15 | | data_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'data')) |
| 16 | data_path = os.path.realpath(os.path.join(os.path.dirname(upath(__file__)), '..', 'data')) |
16 | 17 | city_file = os.path.join(data_path, 'cities', 'cities.shp') |
17 | 18 | vrt_file = os.path.join(data_path, 'test_vrt', 'test_vrt.vrt') |
18 | 19 | |
-
diff --git a/django/contrib/gis/tests/geogapp/tests.py b/django/contrib/gis/tests/geogapp/tests.py
index 2fd3560..a8c607c 100644
a
|
b
|
import os
|
8 | 8 | from django.contrib.gis import gdal |
9 | 9 | from django.contrib.gis.measure import D |
10 | 10 | from django.test import TestCase |
| 11 | from django.utils._os import upath |
11 | 12 | |
12 | 13 | from .models import City, County, Zipcode |
13 | 14 | |
… |
… |
class GeographyTest(TestCase):
|
61 | 62 | from django.contrib.gis.utils import LayerMapping |
62 | 63 | |
63 | 64 | # Getting the shapefile and mapping dictionary. |
64 | | shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'data')) |
| 65 | shp_path = os.path.realpath(os.path.join(os.path.dirname(upath(__file__)), '..', 'data')) |
65 | 66 | co_shp = os.path.join(shp_path, 'counties', 'counties.shp') |
66 | 67 | co_mapping = {'name' : 'Name', |
67 | 68 | 'state' : 'State', |
-
diff --git a/django/contrib/gis/tests/layermap/tests.py b/django/contrib/gis/tests/layermap/tests.py
index a976954..470e5be 100644
a
|
b
|
from django.db import router
|
13 | 13 | from django.conf import settings |
14 | 14 | from django.test import TestCase |
15 | 15 | from django.utils import unittest |
| 16 | from django.utils._os import upath |
16 | 17 | |
17 | 18 | from .models import ( |
18 | 19 | City, County, CountyFeat, Interstate, ICity1, ICity2, Invalid, State, |
19 | 20 | city_mapping, co_mapping, cofeat_mapping, inter_mapping) |
20 | 21 | |
21 | 22 | |
22 | | shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir, 'data')) |
| 23 | shp_path = os.path.realpath(os.path.join(os.path.dirname(upath(__file__)), os.pardir, 'data')) |
23 | 24 | city_shp = os.path.join(shp_path, 'cities', 'cities.shp') |
24 | 25 | co_shp = os.path.join(shp_path, 'counties', 'counties.shp') |
25 | 26 | inter_shp = os.path.join(shp_path, 'interstates', 'interstates.shp') |
-
diff --git a/django/contrib/sitemaps/tests/http.py b/django/contrib/sitemaps/tests/http.py
index 99042fe..4a1cf66 100644
a
|
b
|
from django.core.exceptions import ImproperlyConfigured
|
11 | 11 | from django.test.utils import override_settings |
12 | 12 | from django.utils.unittest import skipUnless |
13 | 13 | from django.utils.formats import localize |
| 14 | from django.utils._os import upath |
14 | 15 | from django.utils.translation import activate, deactivate |
15 | 16 | |
16 | 17 | from .base import SitemapTestsBase |
… |
… |
class HTTPSitemapTests(SitemapTestsBase):
|
29 | 30 | self.assertXMLEqual(response.content.decode('utf-8'), expected_content) |
30 | 31 | |
31 | 32 | @override_settings( |
32 | | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),) |
| 33 | TEMPLATE_DIRS=(os.path.join(os.path.dirname(upath(__file__)), 'templates'),) |
33 | 34 | ) |
34 | 35 | def test_simple_sitemap_custom_index(self): |
35 | 36 | "A simple sitemap index can be rendered with a custom template" |
… |
… |
class HTTPSitemapTests(SitemapTestsBase):
|
64 | 65 | self.assertXMLEqual(response.content.decode('utf-8'), expected_content) |
65 | 66 | |
66 | 67 | @override_settings( |
67 | | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),) |
| 68 | TEMPLATE_DIRS=(os.path.join(os.path.dirname(upath(__file__)), 'templates'),) |
68 | 69 | ) |
69 | 70 | def test_simple_custom_sitemap(self): |
70 | 71 | "A simple sitemap can be rendered with a custom template" |
-
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index 9691b78..7e87a89 100644
a
|
b
|
from django.utils.datastructures import SortedDict
|
19 | 19 | from django.utils.encoding import force_bytes, force_text |
20 | 20 | from django.utils.functional import LazyObject |
21 | 21 | from django.utils.importlib import import_module |
| 22 | from django.utils._os import upath |
22 | 23 | |
23 | 24 | from django.contrib.staticfiles.utils import check_settings, matches_patterns |
24 | 25 | |
… |
… |
class AppStaticStorage(FileSystemStorage):
|
296 | 297 | """ |
297 | 298 | # app is the actual app module |
298 | 299 | mod = import_module(app) |
299 | | mod_path = os.path.dirname(mod.__file__) |
| 300 | mod_path = os.path.dirname(upath(mod.__file__)) |
300 | 301 | location = os.path.join(mod_path, self.source_dir) |
301 | 302 | super(AppStaticStorage, self).__init__(location, *args, **kwargs) |
302 | 303 | |
-
diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
index bb26c20..fab5059 100644
a
|
b
|
from django.core.exceptions import ImproperlyConfigured
|
9 | 9 | from django.core.management.base import BaseCommand, CommandError, handle_default_options |
10 | 10 | from django.core.management.color import color_style |
11 | 11 | from django.utils.importlib import import_module |
| 12 | from django.utils._os import upath |
12 | 13 | from django.utils import six |
13 | 14 | |
14 | 15 | # For backwards compatibility: get_version() used to be in this module. |
… |
… |
def setup_environ(settings_mod, original_settings_path=None):
|
410 | 411 | # Add this project to sys.path so that it's importable in the conventional |
411 | 412 | # way. For example, if this file (manage.py) lives in a directory |
412 | 413 | # "myproject", this code would add "/path/to/myproject" to sys.path. |
413 | | if '__init__.py' in settings_mod.__file__: |
414 | | p = os.path.dirname(settings_mod.__file__) |
| 414 | if '__init__.py' in upath(settings_mod.__file__): |
| 415 | p = os.path.dirname(upath(settings_mod.__file__)) |
415 | 416 | else: |
416 | | p = settings_mod.__file__ |
| 417 | p = upath(settings_mod.__file__) |
417 | 418 | project_directory, settings_filename = os.path.split(p) |
418 | 419 | if project_directory == os.curdir or not project_directory: |
419 | 420 | project_directory = os.getcwd() |
-
diff --git a/django/core/management/commands/compilemessages.py b/django/core/management/commands/compilemessages.py
index b7392b9..7a1ae22 100644
a
|
b
|
import os
|
5 | 5 | import sys |
6 | 6 | from optparse import make_option |
7 | 7 | from django.core.management.base import BaseCommand, CommandError |
| 8 | from django.utils.encoding import force_str |
8 | 9 | |
9 | 10 | def has_bom(fn): |
10 | 11 | with open(fn, 'rb') as f: |
… |
… |
def compile_messages(stderr, locale=None):
|
41 | 42 | # command, so that we can take advantage of shell quoting, to |
42 | 43 | # quote any malicious characters/escaping. |
43 | 44 | # See http://cyberelk.net/tim/articles/cmdline/ar01s02.html |
44 | | os.environ['djangocompilemo'] = pf + '.mo' |
45 | | os.environ['djangocompilepo'] = pf + '.po' |
| 45 | os.environ['djangocompilemo'] = force_str(pf + '.mo') |
| 46 | os.environ['djangocompilepo'] = force_str(pf + '.po') |
46 | 47 | if sys.platform == 'win32': # Different shell-variable syntax |
47 | 48 | cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"' |
48 | 49 | else: |
-
diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py
index f6f1b10..ed47b8f 100644
a
|
b
|
from django.db import (connections, router, transaction, DEFAULT_DB_ALIAS,
|
13 | 13 | IntegrityError, DatabaseError) |
14 | 14 | from django.db.models import get_apps |
15 | 15 | from django.utils.encoding import force_text |
| 16 | from django.utils._os import upath |
16 | 17 | from itertools import product |
17 | 18 | |
18 | 19 | try: |
… |
… |
class Command(BaseCommand):
|
97 | 98 | if hasattr(app, '__path__'): |
98 | 99 | # It's a 'models/' subpackage |
99 | 100 | for path in app.__path__: |
100 | | app_module_paths.append(path) |
| 101 | app_module_paths.append(upath(path)) |
101 | 102 | else: |
102 | 103 | # It's a models.py module |
103 | | app_module_paths.append(app.__file__) |
| 104 | app_module_paths.append(upath(app.__file__)) |
104 | 105 | |
105 | 106 | app_fixtures = [os.path.join(os.path.dirname(path), 'fixtures') for path in app_module_paths] |
106 | 107 | |
-
diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
index 81c4fdf..606cbe0 100644
a
|
b
|
def make_messages(locale=None, domain='django', verbosity=1, all=False,
|
301 | 301 | |
302 | 302 | locales = [] |
303 | 303 | if locale is not None: |
304 | | locales.append(locale) |
| 304 | locales.append(str(locale)) |
305 | 305 | elif all: |
306 | 306 | locale_dirs = filter(os.path.isdir, glob.glob('%s/*' % localedir)) |
307 | 307 | locales = [os.path.basename(l) for l in locale_dirs] |
… |
… |
def make_messages(locale=None, domain='django', verbosity=1, all=False,
|
316 | 316 | if not os.path.isdir(basedir): |
317 | 317 | os.makedirs(basedir) |
318 | 318 | |
319 | | pofile = os.path.join(basedir, '%s.po' % domain) |
320 | | potfile = os.path.join(basedir, '%s.pot' % domain) |
| 319 | pofile = os.path.join(basedir, '%s.po' % str(domain)) |
| 320 | potfile = os.path.join(basedir, '%s.pot' % str(domain)) |
321 | 321 | |
322 | 322 | if os.path.exists(potfile): |
323 | 323 | os.unlink(potfile) |
-
diff --git a/django/core/management/sql.py b/django/core/management/sql.py
index 78cd17a..17e9315 100644
a
|
b
|
from django.conf import settings
|
8 | 8 | from django.core.management.base import CommandError |
9 | 9 | from django.db import models |
10 | 10 | from django.db.models import get_models |
| 11 | from django.utils._os import upath |
11 | 12 | |
12 | 13 | |
13 | 14 | def sql_create(app, style, connection): |
… |
… |
def _split_statements(content):
|
159 | 160 | |
160 | 161 | def custom_sql_for_model(model, style, connection): |
161 | 162 | opts = model._meta |
162 | | app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), 'sql')) |
| 163 | app_dir = os.path.normpath(os.path.join(os.path.dirname(upath(models.get_app(model._meta.app_label).__file__)), 'sql')) |
163 | 164 | output = [] |
164 | 165 | |
165 | 166 | # Post-creation SQL should come before any initial SQL data is loaded. |
-
diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
index 9c0b7b7..c657fd9 100644
a
|
b
|
class RegexURLResolver(LocaleRegexProvider):
|
251 | 251 | urlconf_repr = '<%s list>' % self.urlconf_name[0].__class__.__name__ |
252 | 252 | else: |
253 | 253 | urlconf_repr = repr(self.urlconf_name) |
254 | | return force_str('<%s %s (%s:%s) %s>' % ( |
| 254 | return str('<%s %s (%s:%s) %s>') % ( |
255 | 255 | self.__class__.__name__, urlconf_repr, self.app_name, |
256 | | self.namespace, self.regex.pattern)) |
| 256 | self.namespace, self.regex.pattern) |
257 | 257 | |
258 | 258 | def _populate(self): |
259 | 259 | lookups = MultiValueDict() |
-
diff --git a/django/db/models/loading.py b/django/db/models/loading.py
index a0510ac..56edc36 100644
a
|
b
|
from django.core.exceptions import ImproperlyConfigured
|
5 | 5 | from django.utils.datastructures import SortedDict |
6 | 6 | from django.utils.importlib import import_module |
7 | 7 | from django.utils.module_loading import module_has_submodule |
| 8 | from django.utils._os import upath |
8 | 9 | from django.utils import six |
9 | 10 | |
10 | 11 | import imp |
… |
… |
class AppCache(object):
|
244 | 245 | # The same model may be imported via different paths (e.g. |
245 | 246 | # appname.models and project.appname.models). We use the source |
246 | 247 | # filename as a means to detect identity. |
247 | | fname1 = os.path.abspath(sys.modules[model.__module__].__file__) |
248 | | fname2 = os.path.abspath(sys.modules[model_dict[model_name].__module__].__file__) |
| 248 | fname1 = os.path.abspath(upath(sys.modules[model.__module__].__file__)) |
| 249 | fname2 = os.path.abspath(upath(sys.modules[model_dict[model_name].__module__].__file__)) |
249 | 250 | # Since the filename extension could be .py the first time and |
250 | 251 | # .pyc or .pyo the second time, ignore the extension when |
251 | 252 | # comparing. |
-
diff --git a/django/db/utils.py b/django/db/utils.py
index a912986..842fd35 100644
a
|
b
|
from threading import local
|
5 | 5 | from django.conf import settings |
6 | 6 | from django.core.exceptions import ImproperlyConfigured |
7 | 7 | from django.utils.importlib import import_module |
| 8 | from django.utils._os import upath |
8 | 9 | from django.utils import six |
9 | 10 | |
10 | 11 | |
… |
… |
def load_backend(backend_name):
|
27 | 28 | except ImportError as e_user: |
28 | 29 | # The database backend wasn't found. Display a helpful error message |
29 | 30 | # listing all possible (built-in) database backends. |
30 | | backend_dir = os.path.join(os.path.dirname(__file__), 'backends') |
| 31 | backend_dir = os.path.join(os.path.dirname(upath(__file__)), 'backends') |
31 | 32 | try: |
32 | 33 | builtin_backends = [ |
33 | 34 | name for _, name, ispkg in pkgutil.iter_modules([backend_dir]) |
-
diff --git a/django/utils/_os.py b/django/utils/_os.py
index 1ea12ae..cc06dc2 100644
a
|
b
|
|
1 | 1 | import os |
2 | 2 | import stat |
| 3 | import sys |
3 | 4 | from os.path import join, normcase, normpath, abspath, isabs, sep, dirname |
| 5 | |
4 | 6 | from django.utils.encoding import force_text |
5 | 7 | from django.utils import six |
6 | 8 | |
… |
… |
def rmtree_errorhandler(func, path, exc_info):
|
75 | 77 | # use the original function to repeat the operation |
76 | 78 | func(path) |
77 | 79 | |
| 80 | def upath(path): |
| 81 | if not six.PY3: |
| 82 | return path.decode(sys.getfilesystemencoding()) |
| 83 | return path |
-
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index 1bcef2d..cf6270c 100644
a
|
b
|
from threading import local
|
10 | 10 | |
11 | 11 | from django.utils.importlib import import_module |
12 | 12 | from django.utils.encoding import force_str, force_text |
| 13 | from django.utils._os import upath |
13 | 14 | from django.utils.safestring import mark_safe, SafeData |
14 | 15 | from django.utils import six |
15 | 16 | from django.utils.six import StringIO |
… |
… |
def translation(language):
|
109 | 110 | |
110 | 111 | from django.conf import settings |
111 | 112 | |
112 | | globalpath = os.path.join(os.path.dirname(sys.modules[settings.__module__].__file__), 'locale') |
| 113 | globalpath = os.path.join(os.path.dirname(upath(sys.modules[settings.__module__].__file__)), 'locale') |
113 | 114 | |
114 | 115 | def _fetch(lang, fallback=None): |
115 | 116 | |
… |
… |
def translation(language):
|
151 | 152 | |
152 | 153 | for appname in reversed(settings.INSTALLED_APPS): |
153 | 154 | app = import_module(appname) |
154 | | apppath = os.path.join(os.path.dirname(app.__file__), 'locale') |
| 155 | apppath = os.path.join(os.path.dirname(upath(app.__file__)), 'locale') |
155 | 156 | |
156 | 157 | if os.path.isdir(apppath): |
157 | 158 | res = _merge(apppath) |
… |
… |
def all_locale_paths():
|
337 | 338 | """ |
338 | 339 | from django.conf import settings |
339 | 340 | globalpath = os.path.join( |
340 | | os.path.dirname(sys.modules[settings.__module__].__file__), 'locale') |
| 341 | os.path.dirname(upath(sys.modules[settings.__module__].__file__)), 'locale') |
341 | 342 | return [globalpath] + list(settings.LOCALE_PATHS) |
342 | 343 | |
343 | 344 | def check_for_language(lang_code): |
-
diff --git a/django/views/i18n.py b/django/views/i18n.py
index 96643f0..c1d456d 100644
a
|
b
|
from django.utils.translation import check_for_language, activate, to_locale, ge
|
8 | 8 | from django.utils.text import javascript_quote |
9 | 9 | from django.utils.encoding import smart_text |
10 | 10 | from django.utils.formats import get_format_modules, get_format |
| 11 | from django.utils._os import upath |
11 | 12 | from django.utils import six |
12 | 13 | |
13 | 14 | def set_language(request): |
… |
… |
def javascript_catalog(request, domain='djangojs', packages=None):
|
197 | 198 | # paths of requested packages |
198 | 199 | for package in packages: |
199 | 200 | p = importlib.import_module(package) |
200 | | path = os.path.join(os.path.dirname(p.__file__), 'locale') |
| 201 | path = os.path.join(os.path.dirname(upath(p.__file__)), 'locale') |
201 | 202 | paths.append(path) |
202 | 203 | # add the filesystem paths listed in the LOCALE_PATHS setting |
203 | 204 | paths.extend(list(reversed(settings.LOCALE_PATHS))) |
-
diff --git a/tests/modeltests/fixtures/tests.py b/tests/modeltests/fixtures/tests.py
index f9b0ac8..73bf292 100644
a
|
b
|
class FixtureLoadingTests(TestCase):
|
226 | 226 | |
227 | 227 | def test_ambiguous_compressed_fixture(self): |
228 | 228 | # The name "fixture5" is ambigous, so loading it will raise an error |
229 | | with six.assertRaisesRegex(self, management.CommandError, |
230 | | "Multiple fixtures named 'fixture5'"): |
| 229 | with self.assertRaises(management.CommandError) as cm: |
231 | 230 | management.call_command('loaddata', 'fixture5', verbosity=0, commit=False) |
| 231 | self.assertIn("Multiple fixtures named 'fixture5'", cm.exception.args[0]) |
232 | 232 | |
233 | 233 | def test_db_loading(self): |
234 | 234 | # Load db fixtures 1 and 2. These will load using the 'default' database identifier implicitly |
… |
… |
class FixtureLoadingTests(TestCase):
|
250 | 250 | # is closed at the end of each test. |
251 | 251 | if connection.vendor == 'mysql': |
252 | 252 | connection.cursor().execute("SET sql_mode = 'TRADITIONAL'") |
253 | | with six.assertRaisesRegex(self, IntegrityError, |
254 | | "Could not load fixtures.Article\(pk=1\): .*$"): |
| 253 | with self.assertRaises(IntegrityError) as cm: |
255 | 254 | management.call_command('loaddata', 'invalid.json', verbosity=0, commit=False) |
| 255 | self.assertIn("Could not load fixtures.Article(pk=1):", cm.exception.args[0]) |
256 | 256 | |
257 | 257 | def test_loading_using(self): |
258 | 258 | # Load db fixtures 1 and 2. These will load using the 'default' database identifier explicitly |
… |
… |
class FixtureTransactionTests(TransactionTestCase):
|
308 | 308 | |
309 | 309 | # Try to load fixture 2 using format discovery; this will fail |
310 | 310 | # because there are two fixture2's in the fixtures directory |
311 | | with six.assertRaisesRegex(self, management.CommandError, |
312 | | "Multiple fixtures named 'fixture2'"): |
| 311 | with self.assertRaises(management.CommandError) as cm: |
313 | 312 | management.call_command('loaddata', 'fixture2', verbosity=0) |
| 313 | self.assertIn("Multiple fixtures named 'fixture2'", cm.exception.args[0]) |
314 | 314 | |
315 | 315 | # object list is unaffected |
316 | 316 | self.assertQuerysetEqual(Article.objects.all(), [ |
-
diff --git a/tests/modeltests/model_forms/tests.py b/tests/modeltests/model_forms/tests.py
index c47de45..c008c00 100644
a
|
b
|
from django.core.validators import ValidationError
|
10 | 10 | from django.db import connection |
11 | 11 | from django.db.models.query import EmptyQuerySet |
12 | 12 | from django.forms.models import model_to_dict |
| 13 | from django.utils._os import upath |
13 | 14 | from django.utils.unittest import skipUnless |
14 | 15 | from django.test import TestCase |
15 | 16 | from django.utils import six |
… |
… |
class OldFormForXTests(TestCase):
|
1282 | 1283 | # it comes to validation. This specifically tests that #6302 is fixed for |
1283 | 1284 | # both file fields and image fields. |
1284 | 1285 | |
1285 | | with open(os.path.join(os.path.dirname(__file__), "test.png"), 'rb') as fp: |
| 1286 | with open(os.path.join(os.path.dirname(upath(__file__)), "test.png"), 'rb') as fp: |
1286 | 1287 | image_data = fp.read() |
1287 | | with open(os.path.join(os.path.dirname(__file__), "test2.png"), 'rb') as fp: |
| 1288 | with open(os.path.join(os.path.dirname(upath(__file__)), "test2.png"), 'rb') as fp: |
1288 | 1289 | image_data2 = fp.read() |
1289 | 1290 | |
1290 | 1291 | f = ImageFileForm( |
-
diff --git a/tests/modeltests/proxy_model_inheritance/tests.py b/tests/modeltests/proxy_model_inheritance/tests.py
index 39fee7e..239bc67 100644
a
|
b
|
from django.core.management import call_command
|
8 | 8 | from django.db.models.loading import cache, load_app |
9 | 9 | from django.test import TestCase, TransactionTestCase |
10 | 10 | from django.test.utils import override_settings |
| 11 | from django.utils._os import upath |
11 | 12 | |
12 | 13 | from .models import (ConcreteModel, ConcreteModelSubclass, |
13 | 14 | ConcreteModelSubclassProxy) |
… |
… |
class ProxyModelInheritanceTests(TransactionTestCase):
|
23 | 24 | |
24 | 25 | def setUp(self): |
25 | 26 | self.old_sys_path = sys.path[:] |
26 | | sys.path.append(os.path.dirname(os.path.abspath(__file__))) |
| 27 | sys.path.append(os.path.dirname(os.path.abspath(upath(__file__)))) |
27 | 28 | for app in settings.INSTALLED_APPS: |
28 | 29 | load_app(app) |
29 | 30 | |
-
diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
index a26d7a6..ad72bc7 100644
a
|
b
|
from django.conf import settings
|
19 | 19 | from django.db import connection |
20 | 20 | from django.test.simple import DjangoTestSuiteRunner |
21 | 21 | from django.utils import unittest |
| 22 | from django.utils.encoding import force_str, force_text |
| 23 | from django.utils._os import upath |
22 | 24 | from django.test import LiveServerTestCase |
23 | 25 | |
24 | | test_dir = os.path.dirname(os.path.dirname(__file__)) |
| 26 | test_dir = os.path.dirname(os.path.dirname(upath(__file__))) |
25 | 27 | |
26 | 28 | class AdminScriptTestCase(unittest.TestCase): |
27 | 29 | def write_settings(self, filename, apps=None, is_dir=False, sdict=None): |
28 | | test_dir = os.path.dirname(os.path.dirname(__file__)) |
| 30 | test_dir = os.path.dirname(os.path.dirname(upath(__file__))) |
29 | 31 | if is_dir: |
30 | 32 | settings_dir = os.path.join(test_dir, filename) |
31 | 33 | os.mkdir(settings_dir) |
… |
… |
class AdminScriptTestCase(unittest.TestCase):
|
89 | 91 | result = first_package_re.findall(backend['ENGINE']) |
90 | 92 | if result and result != 'django': |
91 | 93 | backend_pkg = __import__(result[0]) |
92 | | backend_dir = os.path.dirname(backend_pkg.__file__) |
| 94 | backend_dir = os.path.dirname(upath(backend_pkg.__file__)) |
93 | 95 | paths.append(os.path.dirname(backend_dir)) |
94 | 96 | return paths |
95 | 97 | |
… |
… |
class AdminScriptTestCase(unittest.TestCase):
|
115 | 117 | del os.environ['DJANGO_SETTINGS_MODULE'] |
116 | 118 | python_path = [project_dir, base_dir] |
117 | 119 | python_path.extend(ext_backend_base_dirs) |
118 | | os.environ[python_path_var_name] = os.pathsep.join(python_path) |
| 120 | os.environ[python_path_var_name] = force_str(os.pathsep.join(python_path)) |
119 | 121 | |
120 | 122 | # Move to the test directory and run |
121 | 123 | os.chdir(test_dir) |
… |
… |
class AdminScriptTestCase(unittest.TestCase):
|
134 | 136 | return out, err |
135 | 137 | |
136 | 138 | def run_django_admin(self, args, settings_file=None): |
137 | | bin_dir = os.path.abspath(os.path.dirname(bin.__file__)) |
| 139 | bin_dir = os.path.abspath(os.path.dirname(upath(bin.__file__))) |
138 | 140 | return self.run_test(os.path.join(bin_dir, 'django-admin.py'), args, settings_file) |
139 | 141 | |
140 | 142 | def run_manage(self, args, settings_file=None): |
… |
… |
class AdminScriptTestCase(unittest.TestCase):
|
144 | 146 | except OSError: |
145 | 147 | pass |
146 | 148 | |
147 | | conf_dir = os.path.dirname(conf.__file__) |
| 149 | conf_dir = os.path.dirname(upath(conf.__file__)) |
148 | 150 | template_manage_py = os.path.join(conf_dir, 'project_template', 'manage.py') |
149 | 151 | |
150 | 152 | test_manage_py = os.path.join(test_dir, 'manage.py') |
… |
… |
class AdminScriptTestCase(unittest.TestCase):
|
166 | 168 | |
167 | 169 | def assertOutput(self, stream, msg): |
168 | 170 | "Utility assertion: assert that the given message exists in the output" |
| 171 | stream = force_text(stream) |
169 | 172 | self.assertTrue(msg in stream, "'%s' does not match actual output text '%s'" % (msg, stream)) |
170 | 173 | |
171 | 174 | def assertNotInOutput(self, stream, msg): |
172 | 175 | "Utility assertion: assert that the given message doesn't exist in the output" |
| 176 | stream = force_text(stream) |
173 | 177 | self.assertFalse(msg in stream, "'%s' matches actual output text '%s'" % (msg, stream)) |
174 | 178 | |
175 | 179 | ########################################################################## |
… |
… |
class StartProject(LiveServerTestCase, AdminScriptTestCase):
|
1553 | 1557 | self.assertNoOutput(err) |
1554 | 1558 | test_manage_py = os.path.join(testproject_dir, 'manage.py') |
1555 | 1559 | with open(test_manage_py, 'r') as fp: |
1556 | | content = fp.read() |
| 1560 | content = force_text(fp.read()) |
1557 | 1561 | self.assertIn("project_name = 'another_project'", content) |
1558 | 1562 | self.assertIn("project_directory = '%s'" % testproject_dir, content) |
1559 | 1563 | |
-
diff --git a/tests/regressiontests/admin_scripts/urls.py b/tests/regressiontests/admin_scripts/urls.py
index 692638c..a45dc3e 100644
a
|
b
|
|
1 | 1 | import os |
2 | 2 | from django.conf.urls import patterns |
| 3 | from django.utils._os import upath |
3 | 4 | |
4 | | here = os.path.dirname(__file__) |
| 5 | here = os.path.dirname(upath(__file__)) |
5 | 6 | |
6 | 7 | urlpatterns = patterns('', |
7 | 8 | (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 62f69f6..ce934e8 100644
a
|
b
|
from django.utils.cache import get_max_age
|
33 | 33 | from django.utils.encoding import iri_to_uri, force_bytes |
34 | 34 | from django.utils.html import escape |
35 | 35 | from django.utils.http import urlencode |
| 36 | from django.utils._os import upath |
36 | 37 | from django.utils import six |
37 | 38 | from django.test.utils import override_settings |
38 | 39 | |
… |
… |
class AdminViewFormUrlTest(TestCase):
|
633 | 634 | Refs #17515. |
634 | 635 | """ |
635 | 636 | template_dirs = settings.TEMPLATE_DIRS + ( |
636 | | os.path.join(os.path.dirname(__file__), 'templates'),) |
| 637 | os.path.join(os.path.dirname(upath(__file__)), 'templates'),) |
637 | 638 | with self.settings(TEMPLATE_DIRS=template_dirs): |
638 | 639 | response = self.client.get("/test_admin/admin/admin_views/color2/") |
639 | 640 | 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 0e66a5a..6dd0be2 100644
a
|
b
|
import time
|
7 | 7 | |
8 | 8 | from django.conf import Settings |
9 | 9 | from django.db.models.loading import cache, load_app, get_model, get_models |
| 10 | from django.utils._os import upath |
10 | 11 | from django.utils.unittest import TestCase |
11 | 12 | |
12 | 13 | class EggLoadingTest(TestCase): |
13 | 14 | |
14 | 15 | def setUp(self): |
15 | 16 | self.old_path = sys.path[:] |
16 | | self.egg_dir = '%s/eggs' % os.path.dirname(__file__) |
| 17 | self.egg_dir = '%s/eggs' % os.path.dirname(upath(__file__)) |
17 | 18 | |
18 | 19 | # This test adds dummy applications to the app cache. These |
19 | 20 | # 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 b754769..fcc1e0f 100644
a
|
b
|
import shutil
|
11 | 11 | |
12 | 12 | from django.core.files.uploadedfile import SimpleUploadedFile |
13 | 13 | from django.utils import unittest |
| 14 | from django.utils._os import upath |
14 | 15 | |
15 | 16 | from .models import Photo, PhotoForm, temp_storage_dir |
16 | 17 | |
… |
… |
class Bug639Test(unittest.TestCase):
|
23 | 24 | called. |
24 | 25 | """ |
25 | 26 | # Grab an image for testing. |
26 | | filename = os.path.join(os.path.dirname(__file__), "test.jpg") |
| 27 | filename = os.path.join(os.path.dirname(upath(__file__)), "test.jpg") |
27 | 28 | with open(filename, "rb") as fp: |
28 | 29 | img = fp.read() |
29 | 30 | |
-
diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
index 595b65d..0197dbd 100644
a
|
b
|
from django.core.files.uploadedfile import UploadedFile
|
24 | 24 | from django.test import SimpleTestCase |
25 | 25 | from django.utils import six |
26 | 26 | from django.utils import unittest |
| 27 | from django.utils._os import upath |
27 | 28 | from django.test.utils import override_settings |
28 | 29 | from ..servers.tests import LiveServerBase |
29 | 30 | |
… |
… |
class FileStorageTests(unittest.TestCase):
|
104 | 105 | """ |
105 | 106 | storage = self.storage_class(location='') |
106 | 107 | self.assertEqual(storage.base_location, '') |
107 | | self.assertEqual(storage.location, os.getcwd()) |
| 108 | self.assertEqual(storage.location, upath(os.getcwd())) |
108 | 109 | |
109 | 110 | def test_file_access_options(self): |
110 | 111 | """ |
… |
… |
class DimensionClosingBug(unittest.TestCase):
|
534 | 535 | from django.core.files import images |
535 | 536 | images.open = catching_open |
536 | 537 | try: |
537 | | get_image_dimensions(os.path.join(os.path.dirname(__file__), "test1.png")) |
| 538 | get_image_dimensions(os.path.join(os.path.dirname(upath(__file__)), "test1.png")) |
538 | 539 | finally: |
539 | 540 | del images.open |
540 | 541 | self.assertTrue(FileWrapper._closed) |
… |
… |
class InconsistentGetImageDimensionsBug(unittest.TestCase):
|
551 | 552 | """ |
552 | 553 | from django.core.files.images import ImageFile |
553 | 554 | |
554 | | img_path = os.path.join(os.path.dirname(__file__), "test.png") |
| 555 | img_path = os.path.join(os.path.dirname(upath(__file__)), "test.png") |
555 | 556 | image = ImageFile(open(img_path, 'rb')) |
556 | 557 | image_pil = Image.open(img_path) |
557 | 558 | 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 55363bc..988c5ac 100644
a
|
b
|
from django.db.models import signals
|
14 | 14 | from django.test import (TestCase, TransactionTestCase, skipIfDBFeature, |
15 | 15 | skipUnlessDBFeature) |
16 | 16 | from django.test.utils import override_settings |
| 17 | from django.utils.encoding import force_text |
| 18 | from django.utils._os import upath |
17 | 19 | from django.utils import six |
18 | 20 | from django.utils.six import PY3, StringIO |
19 | 21 | |
… |
… |
class TestFixtures(TestCase):
|
126 | 128 | fixture directory. |
127 | 129 | """ |
128 | 130 | load_absolute_path = os.path.join( |
129 | | os.path.dirname(__file__), |
| 131 | os.path.dirname(upath(__file__)), |
130 | 132 | 'fixtures', |
131 | 133 | 'absolute.json' |
132 | 134 | ) |
… |
… |
class TestFixtures(TestCase):
|
388 | 390 | commit=False, |
389 | 391 | ) |
390 | 392 | |
391 | | _cur_dir = os.path.dirname(os.path.abspath(__file__)) |
| 393 | _cur_dir = os.path.dirname(os.path.abspath(upath(__file__))) |
392 | 394 | |
393 | 395 | @override_settings(FIXTURE_DIRS=[os.path.join(_cur_dir, 'fixtures_1'), |
394 | 396 | os.path.join(_cur_dir, 'fixtures_2')]) |
… |
… |
class TestFixtures(TestCase):
|
430 | 432 | stdout=stdout_output, |
431 | 433 | ) |
432 | 434 | self.assertTrue("No xml fixture 'this_fixture_doesnt_exist' in" in |
433 | | stdout_output.getvalue()) |
| 435 | force_text(stdout_output.getvalue())) |
434 | 436 | |
435 | 437 | |
436 | 438 | class NaturalKeyFixtureTests(TestCase): |
-
diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
index 1027afc..e17d976 100644
a
|
b
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
36 | 36 | from django.forms import * |
37 | 37 | from django.test import SimpleTestCase |
38 | 38 | from django.utils import six |
| 39 | from django.utils._os import upath |
39 | 40 | |
40 | 41 | |
41 | 42 | def fix_os_paths(x): |
… |
… |
class FieldsTests(SimpleTestCase):
|
928 | 929 | # FilePathField ############################################################### |
929 | 930 | |
930 | 931 | def test_filepathfield_1(self): |
931 | | path = os.path.abspath(forms.__file__) |
| 932 | path = os.path.abspath(upath(forms.__file__)) |
932 | 933 | path = os.path.dirname(path) + '/' |
933 | 934 | self.assertTrue(fix_os_paths(path).endswith('/django/forms/')) |
934 | 935 | |
935 | 936 | def test_filepathfield_2(self): |
936 | | path = forms.__file__ |
| 937 | path = upath(forms.__file__) |
937 | 938 | path = os.path.dirname(os.path.abspath(path)) + '/' |
938 | 939 | f = FilePathField(path=path) |
939 | 940 | f.choices = [p for p in f.choices if p[0].endswith('.py')] |
… |
… |
class FieldsTests(SimpleTestCase):
|
954 | 955 | assert fix_os_paths(f.clean(path + 'fields.py')).endswith('/django/forms/fields.py') |
955 | 956 | |
956 | 957 | def test_filepathfield_3(self): |
957 | | path = forms.__file__ |
| 958 | path = upath(forms.__file__) |
958 | 959 | path = os.path.dirname(os.path.abspath(path)) + '/' |
959 | 960 | f = FilePathField(path=path, match='^.*?\.py$') |
960 | 961 | f.choices.sort() |
… |
… |
class FieldsTests(SimpleTestCase):
|
972 | 973 | self.assertTrue(got[0].endswith(exp[0])) |
973 | 974 | |
974 | 975 | def test_filepathfield_4(self): |
975 | | path = os.path.abspath(forms.__file__) |
| 976 | path = os.path.abspath(upath(forms.__file__)) |
976 | 977 | path = os.path.dirname(path) + '/' |
977 | 978 | f = FilePathField(path=path, recursive=True, match='^.*?\.py$') |
978 | 979 | f.choices.sort() |
… |
… |
class FieldsTests(SimpleTestCase):
|
992 | 993 | self.assertTrue(got[0].endswith(exp[0])) |
993 | 994 | |
994 | 995 | def test_filepathfield_folders(self): |
995 | | path = os.path.dirname(__file__) + '/filepath_test_files/' |
| 996 | path = os.path.dirname(upath(__file__)) + '/filepath_test_files/' |
996 | 997 | f = FilePathField(path=path, allow_folders=True, allow_files=False) |
997 | 998 | f.choices.sort() |
998 | 999 | expected = [ |
-
diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
index 2d172ad..a601e54 100644
a
|
b
|
from django.http import (QueryDict, HttpResponse, HttpResponseRedirect,
|
14 | 14 | parse_cookie) |
15 | 15 | from django.test import TestCase |
16 | 16 | from django.utils.encoding import smart_str |
| 17 | from django.utils._os import upath |
17 | 18 | from django.utils import six |
18 | 19 | from django.utils import unittest |
19 | 20 | |
… |
… |
class StreamingHttpResponseTests(TestCase):
|
483 | 484 | |
484 | 485 | class FileCloseTests(TestCase): |
485 | 486 | def test_response(self): |
486 | | filename = os.path.join(os.path.dirname(__file__), 'abc.txt') |
| 487 | filename = os.path.join(os.path.dirname(upath(__file__)), 'abc.txt') |
487 | 488 | |
488 | 489 | # file isn't closed until we close the response. |
489 | 490 | file1 = open(filename) |
… |
… |
class FileCloseTests(TestCase):
|
516 | 517 | self.assertTrue(file2.closed) |
517 | 518 | |
518 | 519 | def test_streaming_response(self): |
519 | | filename = os.path.join(os.path.dirname(__file__), 'abc.txt') |
| 520 | filename = os.path.join(os.path.dirname(upath(__file__)), 'abc.txt') |
520 | 521 | |
521 | 522 | # file isn't closed until we close the response. |
522 | 523 | file1 = open(filename) |
-
diff --git a/tests/regressiontests/i18n/commands/compilation.py b/tests/regressiontests/i18n/commands/compilation.py
index c6ab779..2944469 100644
a
|
b
|
from django.core.management import call_command, CommandError
|
4 | 4 | from django.test import TestCase |
5 | 5 | from django.test.utils import override_settings |
6 | 6 | from django.utils import translation, six |
| 7 | from django.utils._os import upath |
7 | 8 | from django.utils.six import StringIO |
8 | 9 | |
9 | | test_dir = os.path.abspath(os.path.dirname(__file__)) |
| 10 | test_dir = os.path.abspath(os.path.dirname(upath(__file__))) |
10 | 11 | |
11 | 12 | |
12 | 13 | class MessageCompilationTests(TestCase): |
… |
… |
class PoFileTests(MessageCompilationTests):
|
25 | 26 | |
26 | 27 | def test_bom_rejection(self): |
27 | 28 | os.chdir(test_dir) |
28 | | with six.assertRaisesRegex(self, CommandError, |
29 | | "file has a BOM \(Byte Order Mark\)"): |
| 29 | with self.assertRaises(CommandError) as cm: |
30 | 30 | call_command('compilemessages', locale=self.LOCALE, stderr=StringIO()) |
| 31 | self.assertIn("file has a BOM (Byte Order Mark)", cm.exception.args[0]) |
31 | 32 | self.assertFalse(os.path.exists(self.MO_FILE)) |
32 | 33 | |
33 | 34 | |
-
diff --git a/tests/regressiontests/i18n/commands/extraction.py b/tests/regressiontests/i18n/commands/extraction.py
index ca2c3cc..aa5efe1 100644
a
|
b
|
|
1 | 1 | # -*- encoding: utf-8 -*- |
| 2 | from __future__ import unicode_literals |
2 | 3 | |
3 | 4 | import os |
4 | 5 | import re |
… |
… |
import shutil
|
6 | 7 | |
7 | 8 | from django.core import management |
8 | 9 | from django.test import TestCase |
| 10 | from django.utils.encoding import force_text |
| 11 | from django.utils._os import upath |
9 | 12 | from django.utils.six import StringIO |
10 | 13 | |
11 | 14 | |
… |
… |
class ExtractorTests(TestCase):
|
17 | 20 | |
18 | 21 | def setUp(self): |
19 | 22 | self._cwd = os.getcwd() |
20 | | self.test_dir = os.path.abspath(os.path.dirname(__file__)) |
| 23 | self.test_dir = os.path.abspath(os.path.dirname(upath(__file__))) |
21 | 24 | |
22 | 25 | def _rmrf(self, dname): |
23 | 26 | if os.path.commonprefix([self.test_dir, os.path.abspath(dname)]) != self.test_dir: |
… |
… |
class BasicExtractorTests(ExtractorTests):
|
55 | 58 | management.call_command('makemessages', locale=LOCALE, verbosity=0) |
56 | 59 | self.assertTrue(os.path.exists(self.PO_FILE)) |
57 | 60 | with open(self.PO_FILE, 'r') as fp: |
58 | | po_contents = fp.read() |
| 61 | po_contents = force_text(fp.read()) |
59 | 62 | self.assertTrue('#. Translators: This comment should be extracted' in po_contents) |
60 | 63 | self.assertTrue('This comment should not be extracted' not in po_contents) |
61 | 64 | # Comments in templates |
… |
… |
class BasicExtractorTests(ExtractorTests):
|
83 | 86 | management.call_command('makemessages', locale=LOCALE, verbosity=0) |
84 | 87 | self.assertTrue(os.path.exists(self.PO_FILE)) |
85 | 88 | with open(self.PO_FILE, 'r') as fp: |
86 | | po_contents = fp.read() |
| 89 | po_contents = force_text(fp.read()) |
87 | 90 | self.assertMsgId('Literal with a percent symbol at the end %%', po_contents) |
88 | 91 | self.assertMsgId('Literal with a percent %% symbol in the middle', po_contents) |
89 | 92 | self.assertMsgId('Completed 50%% of all the tasks', po_contents) |
… |
… |
class BasicExtractorTests(ExtractorTests):
|
99 | 102 | management.call_command('makemessages', locale=LOCALE, verbosity=0) |
100 | 103 | self.assertTrue(os.path.exists(self.PO_FILE)) |
101 | 104 | with open(self.PO_FILE, 'r') as fp: |
102 | | po_contents = fp.read() |
| 105 | po_contents = force_text(fp.read()) |
103 | 106 | self.assertMsgId('I think that 100%% is more that 50%% of anything.', po_contents) |
104 | 107 | self.assertMsgId('I think that 100%% is more that 50%% of %(obj)s.', po_contents) |
105 | 108 | self.assertMsgId("Blocktrans extraction shouldn't double escape this: %%, a=%(a)s", po_contents) |
… |
… |
class BasicExtractorTests(ExtractorTests):
|
123 | 126 | stdout = StringIO() |
124 | 127 | management.call_command('makemessages', locale=LOCALE, stdout=stdout) |
125 | 128 | os.remove('./code_sample.py') |
126 | | self.assertIn("code_sample.py:4", stdout.getvalue()) |
| 129 | self.assertIn("code_sample.py:4", force_text(stdout.getvalue())) |
127 | 130 | |
128 | 131 | def test_template_message_context_extractor(self): |
129 | 132 | """ |
… |
… |
class BasicExtractorTests(ExtractorTests):
|
135 | 138 | management.call_command('makemessages', locale=LOCALE, verbosity=0) |
136 | 139 | self.assertTrue(os.path.exists(self.PO_FILE)) |
137 | 140 | with open(self.PO_FILE, 'r') as fp: |
138 | | po_contents = fp.read() |
| 141 | po_contents = force_text(fp.read()) |
139 | 142 | # {% trans %} |
140 | 143 | self.assertTrue('msgctxt "Special trans context #1"' in po_contents) |
141 | 144 | self.assertTrue("Translatable literal #7a" in po_contents) |
… |
… |
class BasicExtractorTests(ExtractorTests):
|
161 | 164 | management.call_command('makemessages', locale=LOCALE, verbosity=0) |
162 | 165 | self.assertTrue(os.path.exists(self.PO_FILE)) |
163 | 166 | with open(self.PO_FILE, 'r') as fp: |
164 | | po_contents = fp.read() |
| 167 | po_contents = force_text(fp.read()) |
165 | 168 | # {% trans %} |
166 | 169 | self.assertTrue('msgctxt "Context wrapped in double quotes"' in po_contents) |
167 | 170 | self.assertTrue('msgctxt "Context wrapped in single quotes"' in po_contents) |
… |
… |
class SymlinkExtractorTests(ExtractorTests):
|
216 | 219 | |
217 | 220 | def setUp(self): |
218 | 221 | self._cwd = os.getcwd() |
219 | | self.test_dir = os.path.abspath(os.path.dirname(__file__)) |
| 222 | self.test_dir = os.path.abspath(os.path.dirname(upath(__file__))) |
220 | 223 | self.symlinked_dir = os.path.join(self.test_dir, 'templates_symlinked') |
221 | 224 | |
222 | 225 | def tearDown(self): |
… |
… |
class SymlinkExtractorTests(ExtractorTests):
|
238 | 241 | management.call_command('makemessages', locale=LOCALE, verbosity=0, symlinks=True) |
239 | 242 | self.assertTrue(os.path.exists(self.PO_FILE)) |
240 | 243 | with open(self.PO_FILE, 'r') as fp: |
241 | | po_contents = fp.read() |
| 244 | po_contents = force_text(fp.read()) |
242 | 245 | self.assertMsgId('This literal should be included.', po_contents) |
243 | 246 | self.assertTrue('templates_symlinked/test.html' in po_contents) |
244 | 247 | |
… |
… |
class CopyPluralFormsExtractorTests(ExtractorTests):
|
250 | 253 | management.call_command('makemessages', locale=LOCALE, verbosity=0) |
251 | 254 | self.assertTrue(os.path.exists(self.PO_FILE)) |
252 | 255 | with open(self.PO_FILE, 'r') as fp: |
253 | | po_contents = fp.read() |
| 256 | po_contents = force_text(fp.read()) |
254 | 257 | self.assertTrue('Plural-Forms: nplurals=2; plural=(n != 1)' in po_contents) |
255 | 258 | |
256 | 259 | |
… |
… |
class NoWrapExtractorTests(ExtractorTests):
|
261 | 264 | management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=True) |
262 | 265 | self.assertTrue(os.path.exists(self.PO_FILE)) |
263 | 266 | with open(self.PO_FILE, 'r') as fp: |
264 | | po_contents = fp.read() |
| 267 | po_contents = force_text(fp.read()) |
265 | 268 | self.assertMsgId('This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option.', po_contents) |
266 | 269 | |
267 | 270 | def test_no_wrap_disabled(self): |
… |
… |
class NoWrapExtractorTests(ExtractorTests):
|
269 | 272 | management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=False) |
270 | 273 | self.assertTrue(os.path.exists(self.PO_FILE)) |
271 | 274 | with open(self.PO_FILE, 'r') as fp: |
272 | | po_contents = fp.read() |
| 275 | po_contents = force_text(fp.read()) |
273 | 276 | 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) |
274 | 277 | |
275 | 278 | |
… |
… |
class NoLocationExtractorTests(ExtractorTests):
|
280 | 283 | management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=True) |
281 | 284 | self.assertTrue(os.path.exists(self.PO_FILE)) |
282 | 285 | with open(self.PO_FILE, 'r') as fp: |
283 | | po_contents = fp.read() |
| 286 | po_contents = force_text(fp.read()) |
284 | 287 | self.assertFalse('#: templates/test.html:55' in po_contents) |
285 | 288 | |
286 | 289 | def test_no_location_disabled(self): |
… |
… |
class NoLocationExtractorTests(ExtractorTests):
|
288 | 291 | management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=False) |
289 | 292 | self.assertTrue(os.path.exists(self.PO_FILE)) |
290 | 293 | with open(self.PO_FILE, 'r') as fp: |
291 | | po_contents = fp.read() |
| 294 | po_contents = force_text(fp.read()) |
292 | 295 | 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 178232f..5e8a982 100644
a
|
b
|
import os
|
6 | 6 | from django.contrib.contenttypes.models import ContentType |
7 | 7 | from django.test import TestCase |
8 | 8 | from django.test.utils import override_settings |
| 9 | from django.utils._os import upath |
9 | 10 | from django.utils import six |
10 | 11 | from django.utils import translation |
11 | 12 | |
… |
… |
from django.utils import translation
|
13 | 14 | @override_settings( |
14 | 15 | USE_I18N=True, |
15 | 16 | LOCALE_PATHS=( |
16 | | os.path.join(os.path.dirname(__file__), 'locale'), |
| 17 | os.path.join(os.path.dirname(upath(__file__)), 'locale'), |
17 | 18 | ), |
18 | 19 | LANGUAGE_CODE='en', |
19 | 20 | LANGUAGES=( |
-
diff --git a/tests/regressiontests/i18n/patterns/tests.py b/tests/regressiontests/i18n/patterns/tests.py
index 73c9f56..358cdf6 100644
a
|
b
|
from django.core.urlresolvers import reverse, clear_url_caches
|
7 | 7 | from django.test import TestCase |
8 | 8 | from django.test.utils import override_settings |
9 | 9 | from django.template import Template, Context |
| 10 | from django.utils._os import upath |
10 | 11 | from django.utils import translation |
11 | 12 | |
12 | 13 | |
13 | 14 | @override_settings( |
14 | 15 | USE_I18N=True, |
15 | 16 | LOCALE_PATHS=( |
16 | | os.path.join(os.path.dirname(__file__), 'locale'), |
| 17 | os.path.join(os.path.dirname(upath(__file__)), 'locale'), |
17 | 18 | ), |
18 | 19 | TEMPLATE_DIRS=( |
19 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 20 | os.path.join(os.path.dirname(upath(__file__)), 'templates'), |
20 | 21 | ), |
21 | 22 | LANGUAGE_CODE='en', |
22 | 23 | LANGUAGES=( |
-
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
index 2e0c097..dc6f1ce 100644
a
|
b
|
from django.utils.formats import (get_format, date_format, time_format,
|
18 | 18 | number_format) |
19 | 19 | from django.utils.importlib import import_module |
20 | 20 | from django.utils.numberformat import format as nformat |
| 21 | from django.utils._os import upath |
21 | 22 | from django.utils.safestring import mark_safe, SafeBytes, SafeString, SafeText |
22 | 23 | from django.utils import six |
23 | 24 | from django.utils.six import PY3 |
… |
… |
from .patterns.tests import (URLRedirectWithoutTrailingSlashTests,
|
44 | 45 | URLPrefixTests, URLResponseTests, URLRedirectTests, PathUnusedTests) |
45 | 46 | |
46 | 47 | |
47 | | here = os.path.dirname(os.path.abspath(__file__)) |
| 48 | here = os.path.dirname(os.path.abspath(upath(__file__))) |
48 | 49 | extended_locale_paths = settings.LOCALE_PATHS + ( |
49 | 50 | os.path.join(here, 'other', 'locale'), |
50 | 51 | ) |
… |
… |
class FormattingTests(TestCase):
|
666 | 667 | with self.settings(USE_L10N=True, |
667 | 668 | FORMAT_MODULE_PATH='regressiontests.i18n.other.locale'): |
668 | 669 | with translation.override('de', deactivate=True): |
669 | | old = "%r" % get_format_modules(reverse=True) |
670 | | new = "%r" % get_format_modules(reverse=True) # second try |
| 670 | old = str(get_format_modules(reverse=True)) |
| 671 | new = str(get_format_modules(reverse=True)) # second try |
671 | 672 | self.assertEqual(new, old, 'Value returned by get_formats_modules() must be preserved between calls.') |
672 | 673 | |
673 | 674 | def test_localize_templatetag_and_filter(self): |
-
diff --git a/tests/regressiontests/model_fields/imagefield.py b/tests/regressiontests/model_fields/imagefield.py
index 7446f22..df0215d 100644
a
|
b
|
import shutil
|
6 | 6 | from django.core.files import File |
7 | 7 | from django.core.files.images import ImageFile |
8 | 8 | from django.test import TestCase |
| 9 | from django.utils._os import upath |
9 | 10 | from django.utils.unittest import skipIf |
10 | 11 | |
11 | 12 | from .models import Image |
… |
… |
class ImageFieldTestMixin(object):
|
43 | 44 | shutil.rmtree(temp_storage_dir) |
44 | 45 | os.mkdir(temp_storage_dir) |
45 | 46 | |
46 | | file_path1 = os.path.join(os.path.dirname(__file__), "4x8.png") |
| 47 | file_path1 = os.path.join(os.path.dirname(upath(__file__)), "4x8.png") |
47 | 48 | self.file1 = self.File(open(file_path1, 'rb')) |
48 | 49 | |
49 | | file_path2 = os.path.join(os.path.dirname(__file__), "8x4.png") |
| 50 | file_path2 = os.path.join(os.path.dirname(upath(__file__)), "8x4.png") |
50 | 51 | self.file2 = self.File(open(file_path2, 'rb')) |
51 | 52 | |
52 | 53 | def tearDown(self): |
-
diff --git a/tests/regressiontests/model_forms_regress/models.py b/tests/regressiontests/model_forms_regress/models.py
index f6e08d2..2c2fd39 100644
a
|
b
|
import os
|
5 | 5 | from django.core.exceptions import ValidationError |
6 | 6 | from django.db import models |
7 | 7 | from django.utils.encoding import python_2_unicode_compatible |
| 8 | from django.utils._os import upath |
8 | 9 | |
9 | 10 | |
10 | 11 | class Person(models.Model): |
… |
… |
class Triple(models.Model):
|
19 | 20 | unique_together = (('left', 'middle'), ('middle', 'right')) |
20 | 21 | |
21 | 22 | class FilePathModel(models.Model): |
22 | | path = models.FilePathField(path=os.path.dirname(__file__), match=".*\.py$", blank=True) |
| 23 | path = models.FilePathField(path=os.path.dirname(upath(__file__)), match=".*\.py$", blank=True) |
23 | 24 | |
24 | 25 | @python_2_unicode_compatible |
25 | 26 | class Publication(models.Model): |
-
diff --git a/tests/regressiontests/servers/tests.py b/tests/regressiontests/servers/tests.py
index f54e34c..1a7552e 100644
a
|
b
|
from django.test import LiveServerTestCase
|
15 | 15 | from django.core.servers.basehttp import WSGIServerException |
16 | 16 | from django.test.utils import override_settings |
17 | 17 | from django.utils.http import urlencode |
| 18 | from django.utils._os import upath |
18 | 19 | |
19 | 20 | from .models import Person |
20 | 21 | |
21 | 22 | |
22 | | TEST_ROOT = os.path.dirname(__file__) |
| 23 | TEST_ROOT = os.path.dirname(upath(__file__)) |
23 | 24 | TEST_SETTINGS = { |
24 | 25 | 'MEDIA_URL': '/media/', |
25 | 26 | '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 0c8e7db..90c8621 100644
a
|
b
|
from django.core.exceptions import ImproperlyConfigured
|
15 | 15 | from django.core.management import call_command |
16 | 16 | from django.test import TestCase |
17 | 17 | from django.test.utils import override_settings |
18 | | from django.utils.encoding import smart_text |
| 18 | from django.utils.encoding import force_text |
19 | 19 | from django.utils.functional import empty |
20 | | from django.utils._os import rmtree_errorhandler |
| 20 | from django.utils._os import rmtree_errorhandler, upath |
21 | 21 | from django.utils import six |
22 | 22 | |
23 | 23 | from django.contrib.staticfiles import finders, storage |
24 | 24 | |
25 | | TEST_ROOT = os.path.dirname(__file__) |
| 25 | TEST_ROOT = os.path.dirname(upath(__file__)) |
26 | 26 | TEST_SETTINGS = { |
27 | 27 | 'DEBUG': True, |
28 | 28 | 'MEDIA_URL': '/media/', |
… |
… |
class BaseStaticFilesTestCase(object):
|
77 | 77 | os.unlink(self._backup_filepath) |
78 | 78 | |
79 | 79 | def assertFileContains(self, filepath, text): |
80 | | self.assertIn(text, self._get_file(smart_text(filepath)), |
| 80 | self.assertIn(text, self._get_file(force_text(filepath)), |
81 | 81 | "'%s' not in '%s'" % (text, filepath)) |
82 | 82 | |
83 | 83 | def assertFileNotFound(self, filepath): |
… |
… |
class TestFindStatic(CollectionTestCase, TestDefaults):
|
195 | 195 | call_command('findstatic', filepath, all=False, verbosity=0, stdout=out) |
196 | 196 | out.seek(0) |
197 | 197 | lines = [l.strip() for l in out.readlines()] |
198 | | with codecs.open(smart_text(lines[1].strip()), "r", "utf-8") as f: |
| 198 | with codecs.open(force_text(lines[1].strip()), "r", "utf-8") as f: |
199 | 199 | return f.read() |
200 | 200 | |
201 | 201 | def test_all_files(self): |
… |
… |
class TestFindStatic(CollectionTestCase, TestDefaults):
|
207 | 207 | out.seek(0) |
208 | 208 | lines = [l.strip() for l in out.readlines()] |
209 | 209 | self.assertEqual(len(lines), 3) # three because there is also the "Found <file> here" line |
210 | | self.assertIn('project', lines[1]) |
211 | | self.assertIn('apps', lines[2]) |
| 210 | self.assertIn('project', force_text(lines[1])) |
| 211 | self.assertIn('apps', force_text(lines[2])) |
212 | 212 | |
213 | 213 | |
214 | 214 | class TestCollection(CollectionTestCase, TestDefaults): |
-
diff --git a/tests/regressiontests/templates/loaders.py b/tests/regressiontests/templates/loaders.py
index 7fbb084..b779652 100644
a
|
b
|
from django.template import TemplateDoesNotExist, Context
|
18 | 18 | from django.template.loaders.eggs import Loader as EggLoader |
19 | 19 | from django.template import loader |
20 | 20 | from django.utils import unittest, six |
| 21 | from django.utils._os import upath |
21 | 22 | from django.utils.six import StringIO |
22 | 23 | |
23 | 24 | |
… |
… |
class CachedLoader(unittest.TestCase):
|
111 | 112 | def test_templatedir_caching(self): |
112 | 113 | "Check that the template directories form part of the template cache key. Refs #13573" |
113 | 114 | # Retrive a template specifying a template directory to check |
114 | | t1, name = loader.find_template('test.html', (os.path.join(os.path.dirname(__file__), 'templates', 'first'),)) |
| 115 | t1, name = loader.find_template('test.html', (os.path.join(os.path.dirname(upath(__file__)), 'templates', 'first'),)) |
115 | 116 | # Now retrieve the same template name, but from a different directory |
116 | | t2, name = loader.find_template('test.html', (os.path.join(os.path.dirname(__file__), 'templates', 'second'),)) |
| 117 | t2, name = loader.find_template('test.html', (os.path.join(os.path.dirname(upath(__file__)), 'templates', 'second'),)) |
117 | 118 | |
118 | 119 | # The two templates should not have the same content |
119 | 120 | self.assertNotEqual(t1.render(Context({})), t2.render(Context({}))) |
… |
… |
class RenderToStringTest(unittest.TestCase):
|
123 | 124 | def setUp(self): |
124 | 125 | self._old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS |
125 | 126 | settings.TEMPLATE_DIRS = ( |
126 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 127 | os.path.join(os.path.dirname(upath(__file__)), 'templates'), |
127 | 128 | ) |
128 | 129 | |
129 | 130 | def tearDown(self): |
-
diff --git a/tests/regressiontests/templates/response.py b/tests/regressiontests/templates/response.py
index a2a76a3..c4da50a 100644
a
|
b
|
from django.template import Template, Context
|
11 | 11 | from django.template.response import (TemplateResponse, SimpleTemplateResponse, |
12 | 12 | ContentNotRenderedError) |
13 | 13 | from django.test.utils import override_settings |
| 14 | from django.utils._os import upath |
14 | 15 | |
15 | 16 | def test_processor(request): |
16 | 17 | return {'processors': 'yes'} |
… |
… |
class SimpleTemplateResponseTest(TestCase):
|
206 | 207 | |
207 | 208 | @override_settings( |
208 | 209 | TEMPLATE_CONTEXT_PROCESSORS=[test_processor_name], |
209 | | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__),'templates')), |
| 210 | TEMPLATE_DIRS=(os.path.join(os.path.dirname(upath(__file__)), 'templates')), |
210 | 211 | ) |
211 | 212 | class TemplateResponseTest(TestCase): |
212 | 213 | |
-
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 65d6e72..9ec487d 100644
a
|
b
|
from django.test.utils import (setup_test_template_loader,
|
30 | 30 | from django.utils import unittest |
31 | 31 | from django.utils.encoding import python_2_unicode_compatible |
32 | 32 | from django.utils.formats import date_format |
| 33 | from django.utils._os import upath |
33 | 34 | from django.utils.translation import activate, deactivate, ugettext as _ |
34 | 35 | from django.utils.safestring import mark_safe |
35 | 36 | from django.utils import six |
… |
… |
class Templates(TestCase):
|
423 | 424 | # Set ALLOWED_INCLUDE_ROOTS so that ssi works. |
424 | 425 | old_allowed_include_roots = settings.ALLOWED_INCLUDE_ROOTS |
425 | 426 | settings.ALLOWED_INCLUDE_ROOTS = ( |
426 | | os.path.dirname(os.path.abspath(__file__)), |
| 427 | os.path.dirname(os.path.abspath(upath(__file__))), |
427 | 428 | ) |
428 | 429 | |
429 | 430 | # Warm the URL reversing cache. This ensures we don't pay the cost |
… |
… |
class Templates(TestCase):
|
514 | 515 | def get_template_tests(self): |
515 | 516 | # SYNTAX -- |
516 | 517 | # 'template_name': ('template contents', 'context dict', 'expected string output' or Exception class) |
517 | | basedir = os.path.dirname(os.path.abspath(__file__)) |
| 518 | basedir = os.path.dirname(os.path.abspath(upath(__file__))) |
518 | 519 | tests = { |
519 | 520 | ### BASIC SYNTAX ################################################ |
520 | 521 | |
… |
… |
class TemplateTagLoading(unittest.TestCase):
|
1649 | 1650 | def setUp(self): |
1650 | 1651 | self.old_path = sys.path[:] |
1651 | 1652 | self.old_apps = settings.INSTALLED_APPS |
1652 | | self.egg_dir = '%s/eggs' % os.path.dirname(__file__) |
| 1653 | self.egg_dir = '%s/eggs' % os.path.dirname(upath(__file__)) |
1653 | 1654 | self.old_tag_modules = template_base.templatetags_modules |
1654 | 1655 | template_base.templatetags_modules = [] |
1655 | 1656 | |
-
diff --git a/tests/regressiontests/test_client_regress/tests.py b/tests/regressiontests/test_client_regress/tests.py
index f424321..5ba5d3c 100644
a
|
b
|
from django.test import Client, TestCase
|
16 | 16 | from django.test.client import encode_file, RequestFactory |
17 | 17 | from django.test.utils import ContextList, override_settings, str_prefix |
18 | 18 | from django.template.response import SimpleTemplateResponse |
| 19 | from django.utils._os import upath |
19 | 20 | from django.utils.translation import ugettext_lazy |
20 | 21 | from django.http import HttpResponse |
21 | 22 | |
22 | 23 | |
23 | 24 | @override_settings( |
24 | | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),) |
| 25 | TEMPLATE_DIRS=(os.path.join(os.path.dirname(upath(__file__)), 'templates'),) |
25 | 26 | ) |
26 | 27 | class AssertContainsTests(TestCase): |
27 | 28 | def test_contains(self): |
… |
… |
class TemplateExceptionTests(TestCase):
|
629 | 630 | template_loader.reset() |
630 | 631 | |
631 | 632 | @override_settings( |
632 | | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'bad_templates'),) |
| 633 | TEMPLATE_DIRS=(os.path.join(os.path.dirname(upath(__file__)), 'bad_templates'),) |
633 | 634 | ) |
634 | 635 | def test_bad_404_template(self): |
635 | 636 | "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 85f18db..eb3afe8 100644
a
|
b
|
class ResolverTests(unittest.TestCase):
|
237 | 237 | 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']))) |
238 | 238 | for tried, expected in zip(e.args[0]['tried'], url_types_names): |
239 | 239 | for t, e in zip(tried, expected): |
240 | | self.assertTrue(isinstance(t, e['type']), '%s is not an instance of %s' % (t, e['type'])) |
| 240 | self.assertTrue(isinstance(t, e['type']), str('%s is not an instance of %s') % (t, e['type'])) |
241 | 241 | if 'name' in e: |
242 | 242 | if not e['name']: |
243 | 243 | 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 5575f34..8861b4a 100644
a
|
b
|
import tempfile
|
4 | 4 | from django.utils import unittest |
5 | 5 | |
6 | 6 | from django.utils.archive import Archive, extract |
| 7 | from django.utils._os import upath |
7 | 8 | |
8 | 9 | |
9 | | TEST_DIR = os.path.join(os.path.dirname(__file__), 'archives') |
| 10 | TEST_DIR = os.path.join(os.path.dirname(upath(__file__)), 'archives') |
10 | 11 | |
11 | 12 | |
12 | 13 | class ArchiveTester(object): |
-
diff --git a/tests/regressiontests/utils/module_loading.py b/tests/regressiontests/utils/module_loading.py
index dffb519..3fc92b0 100644
a
|
b
|
from zipimport import zipimporter
|
6 | 6 | from django.utils import unittest |
7 | 7 | from django.utils.importlib import import_module |
8 | 8 | from django.utils.module_loading import module_has_submodule |
| 9 | from django.utils._os import upath |
9 | 10 | |
10 | 11 | |
11 | 12 | class DefaultLoader(unittest.TestCase): |
… |
… |
class DefaultLoader(unittest.TestCase):
|
50 | 51 | class EggLoader(unittest.TestCase): |
51 | 52 | def setUp(self): |
52 | 53 | self.old_path = sys.path[:] |
53 | | self.egg_dir = '%s/eggs' % os.path.dirname(__file__) |
| 54 | self.egg_dir = '%s/eggs' % os.path.dirname(upath(__file__)) |
54 | 55 | |
55 | 56 | def tearDown(self): |
56 | 57 | sys.path = self.old_path |
-
diff --git a/tests/regressiontests/views/tests/debug.py b/tests/regressiontests/views/tests/debug.py
index e616d18..4fdaad5 100644
a
|
b
|
from django.core.urlresolvers import reverse
|
14 | 14 | from django.test import TestCase, RequestFactory |
15 | 15 | from django.test.utils import (override_settings, setup_test_template_loader, |
16 | 16 | restore_template_loaders) |
| 17 | from django.utils.encoding import force_text |
17 | 18 | from django.views.debug import ExceptionReporter |
18 | 19 | |
19 | 20 | from .. import BrokenException, except_args |
… |
… |
class ExceptionReportTestMixin(object):
|
306 | 307 | self.assertEqual(len(mail.outbox), 1) |
307 | 308 | email = mail.outbox[0] |
308 | 309 | # Frames vars are never shown in plain text email reports. |
309 | | self.assertNotIn('cooked_eggs', email.body) |
310 | | self.assertNotIn('scrambled', email.body) |
311 | | self.assertNotIn('sauce', email.body) |
312 | | self.assertNotIn('worcestershire', email.body) |
| 310 | body = force_text(email.body) |
| 311 | self.assertNotIn('cooked_eggs', body) |
| 312 | self.assertNotIn('scrambled', body) |
| 313 | self.assertNotIn('sauce', body) |
| 314 | self.assertNotIn('worcestershire', body) |
313 | 315 | if check_for_POST_params: |
314 | 316 | for k, v in self.breakfast_data.items(): |
315 | 317 | # All POST parameters are shown. |
316 | | self.assertIn(k, email.body) |
317 | | self.assertIn(v, email.body) |
| 318 | self.assertIn(k, body) |
| 319 | self.assertIn(v, body) |
318 | 320 | |
319 | 321 | def verify_safe_email(self, view, check_for_POST_params=True): |
320 | 322 | """ |
… |
… |
class ExceptionReportTestMixin(object):
|
327 | 329 | self.assertEqual(len(mail.outbox), 1) |
328 | 330 | email = mail.outbox[0] |
329 | 331 | # Frames vars are never shown in plain text email reports. |
330 | | self.assertNotIn('cooked_eggs', email.body) |
331 | | self.assertNotIn('scrambled', email.body) |
332 | | self.assertNotIn('sauce', email.body) |
333 | | self.assertNotIn('worcestershire', email.body) |
| 332 | body = force_text(email.body) |
| 333 | self.assertNotIn('cooked_eggs', body) |
| 334 | self.assertNotIn('scrambled', body) |
| 335 | self.assertNotIn('sauce', body) |
| 336 | self.assertNotIn('worcestershire', body) |
334 | 337 | if check_for_POST_params: |
335 | 338 | for k, v in self.breakfast_data.items(): |
336 | 339 | # All POST parameters' names are shown. |
337 | | self.assertIn(k, email.body) |
| 340 | self.assertIn(k, body) |
338 | 341 | # Non-sensitive POST parameters' values are shown. |
339 | | self.assertIn('baked-beans-value', email.body) |
340 | | self.assertIn('hash-brown-value', email.body) |
| 342 | self.assertIn('baked-beans-value', body) |
| 343 | self.assertIn('hash-brown-value', body) |
341 | 344 | # Sensitive POST parameters' values are not shown. |
342 | | self.assertNotIn('sausage-value', email.body) |
343 | | self.assertNotIn('bacon-value', email.body) |
| 345 | self.assertNotIn('sausage-value', body) |
| 346 | self.assertNotIn('bacon-value', body) |
344 | 347 | |
345 | 348 | def verify_paranoid_email(self, view): |
346 | 349 | """ |
… |
… |
class ExceptionReportTestMixin(object):
|
353 | 356 | self.assertEqual(len(mail.outbox), 1) |
354 | 357 | email = mail.outbox[0] |
355 | 358 | # Frames vars are never shown in plain text email reports. |
356 | | self.assertNotIn('cooked_eggs', email.body) |
357 | | self.assertNotIn('scrambled', email.body) |
358 | | self.assertNotIn('sauce', email.body) |
359 | | self.assertNotIn('worcestershire', email.body) |
| 359 | body = force_text(email.body) |
| 360 | self.assertNotIn('cooked_eggs', body) |
| 361 | self.assertNotIn('scrambled', body) |
| 362 | self.assertNotIn('sauce', body) |
| 363 | self.assertNotIn('worcestershire', body) |
360 | 364 | for k, v in self.breakfast_data.items(): |
361 | 365 | # All POST parameters' names are shown. |
362 | | self.assertIn(k, email.body) |
| 366 | self.assertIn(k, body) |
363 | 367 | # No POST parameters' values are shown. |
364 | | self.assertNotIn(v, email.body) |
| 368 | self.assertNotIn(v, body) |
365 | 369 | |
366 | 370 | |
367 | 371 | class ExceptionReporterFilterTests(TestCase, ExceptionReportTestMixin): |
-
diff --git a/tests/regressiontests/views/tests/i18n.py b/tests/regressiontests/views/tests/i18n.py
index 671becb..f1f5b17 100644
a
|
b
|
from django.core.urlresolvers import reverse
|
9 | 9 | from django.test import LiveServerTestCase, TestCase |
10 | 10 | from django.test.utils import override_settings |
11 | 11 | from django.utils import six, unittest |
| 12 | from django.utils._os import upath |
12 | 13 | from django.utils.translation import override |
13 | 14 | from django.utils.text import javascript_quote |
14 | 15 | |
… |
… |
class JsI18NTestsMultiPackage(TestCase):
|
152 | 153 | def testI18NWithLocalePaths(self): |
153 | 154 | extended_locale_paths = settings.LOCALE_PATHS + ( |
154 | 155 | path.join(path.dirname( |
155 | | path.dirname(path.abspath(__file__))), 'app3', 'locale'),) |
| 156 | path.dirname(path.abspath(upath(__file__)))), 'app3', 'locale'),) |
156 | 157 | with self.settings(LANGUAGE_CODE='es-ar', LOCALE_PATHS=extended_locale_paths): |
157 | 158 | with override('es-ar'): |
158 | 159 | response = self.client.get('/views/jsi18n/') |
-
diff --git a/tests/regressiontests/views/urls.py b/tests/regressiontests/views/urls.py
index ae3b9c0..2c06557 100644
a
|
b
|
from __future__ import absolute_import
|
4 | 4 | from os import path |
5 | 5 | |
6 | 6 | from django.conf.urls import patterns, url, include |
| 7 | from django.utils._os import upath |
7 | 8 | |
8 | 9 | from . import views |
9 | 10 | |
10 | 11 | |
11 | | base_dir = path.dirname(path.abspath(__file__)) |
| 12 | base_dir = path.dirname(path.abspath(upath(__file__))) |
12 | 13 | media_dir = path.join(base_dir, 'media') |
13 | 14 | locale_dir = path.join(base_dir, 'locale') |
14 | 15 | |
-
diff --git a/tests/runtests.py b/tests/runtests.py
index 90e2dc2..8c56e27 100755
a
|
b
|
import tempfile
|
7 | 7 | import warnings |
8 | 8 | |
9 | 9 | from django import contrib |
| 10 | from django.utils._os import upath |
10 | 11 | from django.utils import six |
11 | 12 | |
12 | 13 | # databrowse is deprecated, but we still want to run its tests |
… |
… |
REGRESSION_TESTS_DIR_NAME = 'regressiontests'
|
19 | 20 | |
20 | 21 | TEST_TEMPLATE_DIR = 'templates' |
21 | 22 | |
22 | | RUNTESTS_DIR = os.path.dirname(__file__) |
23 | | CONTRIB_DIR = os.path.dirname(contrib.__file__) |
| 23 | RUNTESTS_DIR = os.path.dirname(upath(__file__)) |
| 24 | CONTRIB_DIR = os.path.dirname(upath(contrib.__file__)) |
24 | 25 | MODEL_TEST_DIR = os.path.join(RUNTESTS_DIR, MODEL_TESTS_DIR_NAME) |
25 | 26 | REGRESSION_TEST_DIR = os.path.join(RUNTESTS_DIR, REGRESSION_TESTS_DIR_NAME) |
26 | 27 | TEMP_DIR = tempfile.mkdtemp(prefix='django_') |
… |
… |
def bisect_tests(bisection_label, options, test_labels):
|
192 | 193 | pass |
193 | 194 | |
194 | 195 | subprocess_args = [ |
195 | | sys.executable, __file__, '--settings=%s' % options.settings] |
| 196 | sys.executable, upath(__file__), '--settings=%s' % options.settings] |
196 | 197 | if options.failfast: |
197 | 198 | subprocess_args.append('--failfast') |
198 | 199 | if options.verbosity: |
… |
… |
def paired_tests(paired_test, options, test_labels):
|
253 | 254 | pass |
254 | 255 | |
255 | 256 | subprocess_args = [ |
256 | | sys.executable, __file__, '--settings=%s' % options.settings] |
| 257 | sys.executable, upath(__file__), '--settings=%s' % options.settings] |
257 | 258 | if options.failfast: |
258 | 259 | subprocess_args.append('--failfast') |
259 | 260 | if options.verbosity: |