Ticket #19357: 19357-upath.diff

File 19357-upath.diff, 76.4 KB (added by Claude Paroz, 12 years ago)

Wrapping file to return unicode

  • django/contrib/admindocs/views.py

    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  
    1414from django.contrib.admindocs import utils
    1515from django.contrib.sites.models import Site
    1616from django.utils.importlib import import_module
     17from django.utils._os import upath
    1718from django.utils import six
    1819from django.utils.translation import ugettext as _
    1920from django.utils.safestring import mark_safe
    def load_all_installed_template_libraries():  
    311312        try:
    312313            libraries = [
    313314                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__)))
    315316                if p.endswith('.py') and p[0].isalpha()
    316317            ]
    317318        except OSError:
  • django/contrib/auth/tests/context_processors.py

    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  
    99from django.db.models import Q
    1010from django.test import TestCase
    1111from django.test.utils import override_settings
     12from django.utils._os import upath
    1213
    1314
    1415class MockUser(object):
    class PermWrapperTests(TestCase):  
    6364@skipIfCustomUser
    6465@override_settings(
    6566    TEMPLATE_DIRS=(
    66             os.path.join(os.path.dirname(__file__), 'templates'),
     67            os.path.join(os.path.dirname(upath(__file__)), 'templates'),
    6768        ),
    6869    USE_TZ=False,                           # required for loading the fixture
    6970    PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
  • django/contrib/auth/tests/forms.py

    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  
    1111from django.test import TestCase
    1212from django.test.utils import override_settings
    1313from django.utils.encoding import force_text
     14from django.utils._os import upath
    1415from django.utils import translation
    1516from django.utils.translation import ugettext as _
    1617
    class PasswordResetFormTest(TestCase):  
    331332        self.assertEqual(form.cleaned_data['email'], email)
    332333
    333334    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')
    335336        with self.settings(TEMPLATE_DIRS=(template_path,)):
    336337            data = {'email': 'testclient@example.com'}
    337338            form = PasswordResetForm(data)
  • django/contrib/auth/tests/views.py

    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  
    1111from django.utils.encoding import force_text
    1212from django.utils.html import escape
    1313from django.utils.http import urlquote
     14from django.utils._os import upath
    1415from django.test import TestCase
    1516from django.test.utils import override_settings
    1617
    from django.contrib.auth.tests.utils import skipIfCustomUser  
    2728    LANGUAGE_CODE='en',
    2829    TEMPLATE_LOADERS=global_settings.TEMPLATE_LOADERS,
    2930    TEMPLATE_DIRS=(
    30         os.path.join(os.path.dirname(__file__), 'templates'),
     31        os.path.join(os.path.dirname(upath(__file__)), 'templates'),
    3132    ),
    3233    USE_TZ=False,
    3334    PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',),
  • django/contrib/formtools/tests/__init__.py

    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  
    1414from django.test import TestCase
    1515from django.test.html import parse_html
    1616from django.test.utils import override_settings
     17from django.utils._os import upath
    1718from django.utils import unittest
    1819
    1920from django.contrib.formtools.tests.wizard import *
    class TestFormPreview(preview.FormPreview):  
    3637
    3738@override_settings(
    3839    TEMPLATE_DIRS=(
    39         os.path.join(os.path.dirname(__file__), 'templates'),
     40        os.path.join(os.path.dirname(upath(__file__)), 'templates'),
    4041    ),
    4142)
    4243class PreviewTests(TestCase):
    class DummyRequest(http.HttpRequest):  
    214215@override_settings(
    215216    SECRET_KEY="123",
    216217    TEMPLATE_DIRS=(
    217         os.path.join(os.path.dirname(__file__), 'templates'),
     218        os.path.join(os.path.dirname(upath(__file__)), 'templates'),
    218219    ),
    219220)
    220221class WizardTests(TestCase):
  • django/contrib/formtools/tests/wizard/wizardtests/tests.py

    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  
    99from django.contrib.auth.models import User
    1010from django.contrib.formtools.wizard.views import CookieWizardView
    1111from django.contrib.formtools.tests.wizard.forms import UserForm, UserFormSet
     12from django.utils._os import upath
    1213
    1314
    1415class WizardTests(object):
    class WizardTests(object):  
    8687        self.assertEqual(response.context['wizard']['steps'].current, 'form2')
    8788
    8889        post_data = self.wizard_step_data[1]
    89         post_data['form2-file1'] = open(__file__, 'rb')
     90        post_data['form2-file1'] = open(upath(__file__), 'rb')
    9091        response = self.client.post(self.wizard_url, post_data)
    9192        self.assertEqual(response.status_code, 200)
    9293        self.assertEqual(response.context['wizard']['steps'].current, 'form3')
    class WizardTests(object):  
    99100        self.assertEqual(response.status_code, 200)
    100101
    101102        all_data = response.context['form_list']
    102         with open(__file__, 'rb') as f:
     103        with open(upath(__file__), 'rb') as f:
    103104            self.assertEqual(all_data[1]['file1'].read(), f.read())
    104105        all_data[1]['file1'].close()
    105106        del all_data[1]['file1']
    class WizardTests(object):  
    118119        self.assertEqual(response.status_code, 200)
    119120
    120121        post_data = self.wizard_step_data[1]
    121         with open(__file__, 'rb') as post_file:
     122        with open(upath(__file__), 'rb') as post_file:
    122123            post_data['form2-file1'] = post_file
    123124            response = self.client.post(self.wizard_url, post_data)
    124125        self.assertEqual(response.status_code, 200)
    class WizardTests(object):  
    130131        self.assertEqual(response.status_code, 200)
    131132
    132133        all_data = response.context['all_cleaned_data']
    133         with open(__file__, 'rb') as f:
     134        with open(upath(__file__), 'rb') as f:
    134135            self.assertEqual(all_data['file1'].read(), f.read())
    135136        all_data['file1'].close()
    136137        del all_data['file1']
    class WizardTests(object):  
    150151
    151152        post_data = self.wizard_step_data[1]
    152153        post_data['form2-file1'].close()
    153         post_data['form2-file1'] = open(__file__, 'rb')
     154        post_data['form2-file1'] = open(upath(__file__), 'rb')
    154155        response = self.client.post(self.wizard_url, post_data)
    155156        self.assertEqual(response.status_code, 200)
    156157
    class WizardTests(object):  
    178179
    179180        post_data = self.wizard_step_data[1]
    180181        post_data['form2-file1'].close()
    181         post_data['form2-file1'] = open(__file__, 'rb')
     182        post_data['form2-file1'] = open(upath(__file__), 'rb')
    182183        response = self.client.post(self.wizard_url, post_data)
    183184        self.assertEqual(response.status_code, 200)
    184185        self.assertEqual(response.context['wizard']['steps'].current, 'form3')
    class WizardTestKwargs(TestCase):  
    291292        self.wizard_step_data[0]['form1-user'] = self.testuser.pk
    292293
    293294    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')
    295296        with self.settings(
    296297                TEMPLATE_DIRS=list(settings.TEMPLATE_DIRS) + [templates]):
    297298            response = self.client.get(self.wizard_url)
  • django/contrib/gis/geometry/test_data.py

    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  
    77
    88from django.contrib import gis
    99from django.utils import six
     10from django.utils._os import upath
    1011
    1112
    1213# This global used to store reference geometry data.
    1314GEOMETRIES = None
    1415
    1516# Path where reference test data is located.
    16 TEST_DATA = os.path.join(os.path.dirname(gis.__file__), 'tests', 'data')
     17TEST_DATA = os.path.join(os.path.dirname(upath(gis.__file__)), 'tests', 'data')
    1718
    1819
    1920def tuplize(seq):
  • django/contrib/gis/tests/geo3d/tests.py

    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  
    77from django.contrib.gis.geos import GEOSGeometry, LineString, Point, Polygon
    88from django.contrib.gis.utils import LayerMapping, LayerMapError
    99from django.test import TestCase
     10from django.utils._os import upath
    1011
    1112from .models import (City3D, Interstate2D, Interstate3D, InterstateProj2D,
    1213    InterstateProj3D, Point2D, Point3D, MultiPoint3D, Polygon2D, Polygon3D)
    1314
    1415
    15 data_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'data'))
     16data_path = os.path.realpath(os.path.join(os.path.dirname(upath(__file__)), '..', 'data'))
    1617city_file = os.path.join(data_path, 'cities', 'cities.shp')
    1718vrt_file = os.path.join(data_path, 'test_vrt', 'test_vrt.vrt')
    1819
  • django/contrib/gis/tests/geogapp/tests.py

    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  
    88from django.contrib.gis import gdal
    99from django.contrib.gis.measure import D
    1010from django.test import TestCase
     11from django.utils._os import upath
    1112
    1213from .models import City, County, Zipcode
    1314
    class GeographyTest(TestCase):  
    6162        from django.contrib.gis.utils import LayerMapping
    6263
    6364        # 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'))
    6566        co_shp = os.path.join(shp_path, 'counties', 'counties.shp')
    6667        co_mapping = {'name' : 'Name',
    6768                      'state' : 'State',
  • django/contrib/gis/tests/layermap/tests.py

    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  
    1313from django.conf import settings
    1414from django.test import TestCase
    1515from django.utils import unittest
     16from django.utils._os import upath
    1617
    1718from .models import (
    1819    City, County, CountyFeat, Interstate, ICity1, ICity2, Invalid, State,
    1920    city_mapping, co_mapping, cofeat_mapping, inter_mapping)
    2021
    2122
    22 shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir, 'data'))
     23shp_path = os.path.realpath(os.path.join(os.path.dirname(upath(__file__)), os.pardir, 'data'))
    2324city_shp = os.path.join(shp_path, 'cities', 'cities.shp')
    2425co_shp = os.path.join(shp_path, 'counties', 'counties.shp')
    2526inter_shp = os.path.join(shp_path, 'interstates', 'interstates.shp')
  • django/contrib/sitemaps/tests/http.py

    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  
    1111from django.test.utils import override_settings
    1212from django.utils.unittest import skipUnless
    1313from django.utils.formats import localize
     14from django.utils._os import upath
    1415from django.utils.translation import activate, deactivate
    1516
    1617from .base import SitemapTestsBase
    class HTTPSitemapTests(SitemapTestsBase):  
    2930        self.assertXMLEqual(response.content.decode('utf-8'), expected_content)
    3031
    3132    @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'),)
    3334    )
    3435    def test_simple_sitemap_custom_index(self):
    3536        "A simple sitemap index can be rendered with a custom template"
    class HTTPSitemapTests(SitemapTestsBase):  
    6465        self.assertXMLEqual(response.content.decode('utf-8'), expected_content)
    6566
    6667    @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'),)
    6869    )
    6970    def test_simple_custom_sitemap(self):
    7071        "A simple sitemap can be rendered with a custom template"
  • django/contrib/staticfiles/storage.py

    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  
    1919from django.utils.encoding import force_bytes, force_text
    2020from django.utils.functional import LazyObject
    2121from django.utils.importlib import import_module
     22from django.utils._os import upath
    2223
    2324from django.contrib.staticfiles.utils import check_settings, matches_patterns
    2425
    class AppStaticStorage(FileSystemStorage):  
    296297        """
    297298        # app is the actual app module
    298299        mod = import_module(app)
    299         mod_path = os.path.dirname(mod.__file__)
     300        mod_path = os.path.dirname(upath(mod.__file__))
    300301        location = os.path.join(mod_path, self.source_dir)
    301302        super(AppStaticStorage, self).__init__(location, *args, **kwargs)
    302303
  • django/core/management/__init__.py

    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  
    99from django.core.management.base import BaseCommand, CommandError, handle_default_options
    1010from django.core.management.color import color_style
    1111from django.utils.importlib import import_module
     12from django.utils._os import upath
    1213from django.utils import six
    1314
    1415# For backwards compatibility: get_version() used to be in this module.
    def setup_environ(settings_mod, original_settings_path=None):  
    410411    # Add this project to sys.path so that it's importable in the conventional
    411412    # way. For example, if this file (manage.py) lives in a directory
    412413    # "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__))
    415416    else:
    416         p = settings_mod.__file__
     417        p = upath(settings_mod.__file__)
    417418    project_directory, settings_filename = os.path.split(p)
    418419    if project_directory == os.curdir or not project_directory:
    419420        project_directory = os.getcwd()
  • django/core/management/commands/compilemessages.py

    diff --git a/django/core/management/commands/compilemessages.py b/django/core/management/commands/compilemessages.py
    index b7392b9..7a1ae22 100644
    a b import os  
    55import sys
    66from optparse import make_option
    77from django.core.management.base import BaseCommand, CommandError
     8from django.utils.encoding import force_str
    89
    910def has_bom(fn):
    1011    with open(fn, 'rb') as f:
    def compile_messages(stderr, locale=None):  
    4142                    # command, so that we can take advantage of shell quoting, to
    4243                    # quote any malicious characters/escaping.
    4344                    # 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')
    4647                    if sys.platform == 'win32': # Different shell-variable syntax
    4748                        cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"'
    4849                    else:
  • django/core/management/commands/loaddata.py

    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,  
    1313      IntegrityError, DatabaseError)
    1414from django.db.models import get_apps
    1515from django.utils.encoding import force_text
     16from django.utils._os import upath
    1617from itertools import product
    1718
    1819try:
    class Command(BaseCommand):  
    9798            if hasattr(app, '__path__'):
    9899                # It's a 'models/' subpackage
    99100                for path in app.__path__:
    100                     app_module_paths.append(path)
     101                    app_module_paths.append(upath(path))
    101102            else:
    102103                # It's a models.py module
    103                 app_module_paths.append(app.__file__)
     104                app_module_paths.append(upath(app.__file__))
    104105
    105106        app_fixtures = [os.path.join(os.path.dirname(path), 'fixtures') for path in app_module_paths]
    106107
  • django/core/management/commands/makemessages.py

    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,  
    301301
    302302    locales = []
    303303    if locale is not None:
    304         locales.append(locale)
     304        locales.append(str(locale))
    305305    elif all:
    306306        locale_dirs = filter(os.path.isdir, glob.glob('%s/*' % localedir))
    307307        locales = [os.path.basename(l) for l in locale_dirs]
    def make_messages(locale=None, domain='django', verbosity=1, all=False,  
    316316        if not os.path.isdir(basedir):
    317317            os.makedirs(basedir)
    318318
    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))
    321321
    322322        if os.path.exists(potfile):
    323323            os.unlink(potfile)
  • django/core/management/sql.py

    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  
    88from django.core.management.base import CommandError
    99from django.db import models
    1010from django.db.models import get_models
     11from django.utils._os import upath
    1112
    1213
    1314def sql_create(app, style, connection):
    def _split_statements(content):  
    159160
    160161def custom_sql_for_model(model, style, connection):
    161162    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'))
    163164    output = []
    164165
    165166    # Post-creation SQL should come before any initial SQL data is loaded.
  • django/core/urlresolvers.py

    diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
    index 9c0b7b7..c657fd9 100644
    a b class RegexURLResolver(LocaleRegexProvider):  
    251251            urlconf_repr = '<%s list>' % self.urlconf_name[0].__class__.__name__
    252252        else:
    253253            urlconf_repr = repr(self.urlconf_name)
    254         return force_str('<%s %s (%s:%s) %s>' % (
     254        return str('<%s %s (%s:%s) %s>') % (
    255255            self.__class__.__name__, urlconf_repr, self.app_name,
    256             self.namespace, self.regex.pattern))
     256            self.namespace, self.regex.pattern)
    257257
    258258    def _populate(self):
    259259        lookups = MultiValueDict()
  • django/db/models/loading.py

    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  
    55from django.utils.datastructures import SortedDict
    66from django.utils.importlib import import_module
    77from django.utils.module_loading import module_has_submodule
     8from django.utils._os import upath
    89from django.utils import six
    910
    1011import imp
    class AppCache(object):  
    244245                # The same model may be imported via different paths (e.g.
    245246                # appname.models and project.appname.models). We use the source
    246247                # 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__))
    249250                # Since the filename extension could be .py the first time and
    250251                # .pyc or .pyo the second time, ignore the extension when
    251252                # comparing.
  • django/db/utils.py

    diff --git a/django/db/utils.py b/django/db/utils.py
    index a912986..842fd35 100644
    a b from threading import local  
    55from django.conf import settings
    66from django.core.exceptions import ImproperlyConfigured
    77from django.utils.importlib import import_module
     8from django.utils._os import upath
    89from django.utils import six
    910
    1011
    def load_backend(backend_name):  
    2728    except ImportError as e_user:
    2829        # The database backend wasn't found. Display a helpful error message
    2930        # 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')
    3132        try:
    3233            builtin_backends = [
    3334                name for _, name, ispkg in pkgutil.iter_modules([backend_dir])
  • django/utils/_os.py

    diff --git a/django/utils/_os.py b/django/utils/_os.py
    index 1ea12ae..cc06dc2 100644
    a b  
    11import os
    22import stat
     3import sys
    34from os.path import join, normcase, normpath, abspath, isabs, sep, dirname
     5
    46from django.utils.encoding import force_text
    57from django.utils import six
    68
    def rmtree_errorhandler(func, path, exc_info):  
    7577    # use the original function to repeat the operation
    7678    func(path)
    7779
     80def upath(path):
     81    if not six.PY3:
     82        return path.decode(sys.getfilesystemencoding())
     83    return path
  • django/utils/translation/trans_real.py

    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  
    1010
    1111from django.utils.importlib import import_module
    1212from django.utils.encoding import force_str, force_text
     13from django.utils._os import upath
    1314from django.utils.safestring import mark_safe, SafeData
    1415from django.utils import six
    1516from django.utils.six import StringIO
    def translation(language):  
    109110
    110111    from django.conf import settings
    111112
    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')
    113114
    114115    def _fetch(lang, fallback=None):
    115116
    def translation(language):  
    151152
    152153        for appname in reversed(settings.INSTALLED_APPS):
    153154            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')
    155156
    156157            if os.path.isdir(apppath):
    157158                res = _merge(apppath)
    def all_locale_paths():  
    337338    """
    338339    from django.conf import settings
    339340    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')
    341342    return [globalpath] + list(settings.LOCALE_PATHS)
    342343
    343344def check_for_language(lang_code):
  • django/views/i18n.py

    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  
    88from django.utils.text import javascript_quote
    99from django.utils.encoding import smart_text
    1010from django.utils.formats import get_format_modules, get_format
     11from django.utils._os import upath
    1112from django.utils import six
    1213
    1314def set_language(request):
    def javascript_catalog(request, domain='djangojs', packages=None):  
    197198    # paths of requested packages
    198199    for package in packages:
    199200        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')
    201202        paths.append(path)
    202203    # add the filesystem paths listed in the LOCALE_PATHS setting
    203204    paths.extend(list(reversed(settings.LOCALE_PATHS)))
  • tests/modeltests/fixtures/tests.py

    diff --git a/tests/modeltests/fixtures/tests.py b/tests/modeltests/fixtures/tests.py
    index f9b0ac8..73bf292 100644
    a b class FixtureLoadingTests(TestCase):  
    226226
    227227    def test_ambiguous_compressed_fixture(self):
    228228        # 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:
    231230            management.call_command('loaddata', 'fixture5', verbosity=0, commit=False)
     231        self.assertIn("Multiple fixtures named 'fixture5'", cm.exception.args[0])
    232232
    233233    def test_db_loading(self):
    234234        # Load db fixtures 1 and 2. These will load using the 'default' database identifier implicitly
    class FixtureLoadingTests(TestCase):  
    250250        # is closed at the end of each test.
    251251        if connection.vendor == 'mysql':
    252252            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:
    255254            management.call_command('loaddata', 'invalid.json', verbosity=0, commit=False)
     255        self.assertIn("Could not load fixtures.Article(pk=1):", cm.exception.args[0])
    256256
    257257    def test_loading_using(self):
    258258        # Load db fixtures 1 and 2. These will load using the 'default' database identifier explicitly
    class FixtureTransactionTests(TransactionTestCase):  
    308308
    309309        # Try to load fixture 2 using format discovery; this will fail
    310310        # 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:
    313312            management.call_command('loaddata', 'fixture2', verbosity=0)
     313        self.assertIn("Multiple fixtures named 'fixture2'", cm.exception.args[0])
    314314
    315315        # object list is unaffected
    316316        self.assertQuerysetEqual(Article.objects.all(), [
  • tests/modeltests/model_forms/tests.py

    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  
    1010from django.db import connection
    1111from django.db.models.query import EmptyQuerySet
    1212from django.forms.models import model_to_dict
     13from django.utils._os import upath
    1314from django.utils.unittest import skipUnless
    1415from django.test import TestCase
    1516from django.utils import six
    class OldFormForXTests(TestCase):  
    12821283        # it comes to validation. This specifically tests that #6302 is fixed for
    12831284        # both file fields and image fields.
    12841285
    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:
    12861287            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:
    12881289            image_data2 = fp.read()
    12891290
    12901291        f = ImageFileForm(
  • tests/modeltests/proxy_model_inheritance/tests.py

    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  
    88from django.db.models.loading import cache, load_app
    99from django.test import TestCase, TransactionTestCase
    1010from django.test.utils import override_settings
     11from django.utils._os import upath
    1112
    1213from .models import (ConcreteModel, ConcreteModelSubclass,
    1314    ConcreteModelSubclassProxy)
    class ProxyModelInheritanceTests(TransactionTestCase):  
    2324
    2425    def setUp(self):
    2526        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__))))
    2728        for app in settings.INSTALLED_APPS:
    2829            load_app(app)
    2930
  • tests/regressiontests/admin_scripts/tests.py

    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  
    1919from django.db import connection
    2020from django.test.simple import DjangoTestSuiteRunner
    2121from django.utils import unittest
     22from django.utils.encoding import force_str, force_text
     23from django.utils._os import upath
    2224from django.test import LiveServerTestCase
    2325
    24 test_dir = os.path.dirname(os.path.dirname(__file__))
     26test_dir = os.path.dirname(os.path.dirname(upath(__file__)))
    2527
    2628class AdminScriptTestCase(unittest.TestCase):
    2729    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__)))
    2931        if is_dir:
    3032            settings_dir = os.path.join(test_dir, filename)
    3133            os.mkdir(settings_dir)
    class AdminScriptTestCase(unittest.TestCase):  
    8991            result = first_package_re.findall(backend['ENGINE'])
    9092            if result and result != 'django':
    9193                backend_pkg = __import__(result[0])
    92                 backend_dir = os.path.dirname(backend_pkg.__file__)
     94                backend_dir = os.path.dirname(upath(backend_pkg.__file__))
    9395                paths.append(os.path.dirname(backend_dir))
    9496        return paths
    9597
    class AdminScriptTestCase(unittest.TestCase):  
    115117            del os.environ['DJANGO_SETTINGS_MODULE']
    116118        python_path = [project_dir, base_dir]
    117119        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))
    119121
    120122        # Move to the test directory and run
    121123        os.chdir(test_dir)
    class AdminScriptTestCase(unittest.TestCase):  
    134136        return out, err
    135137
    136138    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__)))
    138140        return self.run_test(os.path.join(bin_dir, 'django-admin.py'), args, settings_file)
    139141
    140142    def run_manage(self, args, settings_file=None):
    class AdminScriptTestCase(unittest.TestCase):  
    144146            except OSError:
    145147                pass
    146148
    147         conf_dir = os.path.dirname(conf.__file__)
     149        conf_dir = os.path.dirname(upath(conf.__file__))
    148150        template_manage_py = os.path.join(conf_dir, 'project_template', 'manage.py')
    149151
    150152        test_manage_py = os.path.join(test_dir, 'manage.py')
    class AdminScriptTestCase(unittest.TestCase):  
    166168
    167169    def assertOutput(self, stream, msg):
    168170        "Utility assertion: assert that the given message exists in the output"
     171        stream = force_text(stream)
    169172        self.assertTrue(msg in stream, "'%s' does not match actual output text '%s'" % (msg, stream))
    170173
    171174    def assertNotInOutput(self, stream, msg):
    172175        "Utility assertion: assert that the given message doesn't exist in the output"
     176        stream = force_text(stream)
    173177        self.assertFalse(msg in stream, "'%s' matches actual output text '%s'" % (msg, stream))
    174178
    175179##########################################################################
    class StartProject(LiveServerTestCase, AdminScriptTestCase):  
    15531557        self.assertNoOutput(err)
    15541558        test_manage_py = os.path.join(testproject_dir, 'manage.py')
    15551559        with open(test_manage_py, 'r') as fp:
    1556             content = fp.read()
     1560            content = force_text(fp.read())
    15571561            self.assertIn("project_name = 'another_project'", content)
    15581562            self.assertIn("project_directory = '%s'" % testproject_dir, content)
    15591563
  • tests/regressiontests/admin_scripts/urls.py

    diff --git a/tests/regressiontests/admin_scripts/urls.py b/tests/regressiontests/admin_scripts/urls.py
    index 692638c..a45dc3e 100644
    a b  
    11import os
    22from django.conf.urls import patterns
     3from django.utils._os import upath
    34
    4 here = os.path.dirname(__file__)
     5here = os.path.dirname(upath(__file__))
    56
    67urlpatterns = patterns('',
    78    (r'^custom_templates/(?P<path>.*)$', 'django.views.static.serve', {
  • tests/regressiontests/admin_views/tests.py

    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  
    3333from django.utils.encoding import iri_to_uri, force_bytes
    3434from django.utils.html import escape
    3535from django.utils.http import urlencode
     36from django.utils._os import upath
    3637from django.utils import six
    3738from django.test.utils import override_settings
    3839
    class AdminViewFormUrlTest(TestCase):  
    633634        Refs #17515.
    634635        """
    635636        template_dirs = settings.TEMPLATE_DIRS + (
    636             os.path.join(os.path.dirname(__file__), 'templates'),)
     637            os.path.join(os.path.dirname(upath(__file__)), 'templates'),)
    637638        with self.settings(TEMPLATE_DIRS=template_dirs):
    638639            response = self.client.get("/test_admin/admin/admin_views/color2/")
    639640            self.assertTrue('custom_filter_template.html' in [t.name for t in response.templates])
  • tests/regressiontests/app_loading/tests.py

    diff --git a/tests/regressiontests/app_loading/tests.py b/tests/regressiontests/app_loading/tests.py
    index 0e66a5a..6dd0be2 100644
    a b import time  
    77
    88from django.conf import Settings
    99from django.db.models.loading import cache, load_app, get_model, get_models
     10from django.utils._os import upath
    1011from django.utils.unittest import TestCase
    1112
    1213class EggLoadingTest(TestCase):
    1314
    1415    def setUp(self):
    1516        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__))
    1718
    1819        # This test adds dummy applications to the app cache. These
    1920        # need to be removed in order to prevent bad interactions
  • tests/regressiontests/bug639/tests.py

    diff --git a/tests/regressiontests/bug639/tests.py b/tests/regressiontests/bug639/tests.py
    index b754769..fcc1e0f 100644
    a b import shutil  
    1111
    1212from django.core.files.uploadedfile import SimpleUploadedFile
    1313from django.utils import unittest
     14from django.utils._os import upath
    1415
    1516from .models import Photo, PhotoForm, temp_storage_dir
    1617
    class Bug639Test(unittest.TestCase):  
    2324        called.
    2425        """
    2526        # 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")
    2728        with open(filename, "rb") as fp:
    2829            img = fp.read()
    2930
  • tests/regressiontests/file_storage/tests.py

    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  
    2424from django.test import SimpleTestCase
    2525from django.utils import six
    2626from django.utils import unittest
     27from django.utils._os import upath
    2728from django.test.utils import override_settings
    2829from ..servers.tests import LiveServerBase
    2930
    class FileStorageTests(unittest.TestCase):  
    104105        """
    105106        storage = self.storage_class(location='')
    106107        self.assertEqual(storage.base_location, '')
    107         self.assertEqual(storage.location, os.getcwd())
     108        self.assertEqual(storage.location, upath(os.getcwd()))
    108109
    109110    def test_file_access_options(self):
    110111        """
    class DimensionClosingBug(unittest.TestCase):  
    534535        from django.core.files import images
    535536        images.open = catching_open
    536537        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"))
    538539        finally:
    539540            del images.open
    540541        self.assertTrue(FileWrapper._closed)
    class InconsistentGetImageDimensionsBug(unittest.TestCase):  
    551552        """
    552553        from django.core.files.images import ImageFile
    553554
    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")
    555556        image = ImageFile(open(img_path, 'rb'))
    556557        image_pil = Image.open(img_path)
    557558        size_1, size_2 = get_image_dimensions(image), get_image_dimensions(image)
  • tests/regressiontests/fixtures_regress/tests.py

    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  
    1414from django.test import (TestCase, TransactionTestCase, skipIfDBFeature,
    1515    skipUnlessDBFeature)
    1616from django.test.utils import override_settings
     17from django.utils.encoding import force_text
     18from django.utils._os import upath
    1719from django.utils import six
    1820from django.utils.six import PY3, StringIO
    1921
    class TestFixtures(TestCase):  
    126128        fixture directory.
    127129        """
    128130        load_absolute_path = os.path.join(
    129             os.path.dirname(__file__),
     131            os.path.dirname(upath(__file__)),
    130132            'fixtures',
    131133            'absolute.json'
    132134        )
    class TestFixtures(TestCase):  
    388390                commit=False,
    389391            )
    390392
    391     _cur_dir = os.path.dirname(os.path.abspath(__file__))
     393    _cur_dir = os.path.dirname(os.path.abspath(upath(__file__)))
    392394
    393395    @override_settings(FIXTURE_DIRS=[os.path.join(_cur_dir, 'fixtures_1'),
    394396                                     os.path.join(_cur_dir, 'fixtures_2')])
    class TestFixtures(TestCase):  
    430432            stdout=stdout_output,
    431433        )
    432434        self.assertTrue("No xml fixture 'this_fixture_doesnt_exist' in" in
    433             stdout_output.getvalue())
     435            force_text(stdout_output.getvalue()))
    434436
    435437
    436438class NaturalKeyFixtureTests(TestCase):
  • tests/regressiontests/forms/tests/fields.py

    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  
    3636from django.forms import *
    3737from django.test import SimpleTestCase
    3838from django.utils import six
     39from django.utils._os import upath
    3940
    4041
    4142def fix_os_paths(x):
    class FieldsTests(SimpleTestCase):  
    928929    # FilePathField ###############################################################
    929930
    930931    def test_filepathfield_1(self):
    931         path = os.path.abspath(forms.__file__)
     932        path = os.path.abspath(upath(forms.__file__))
    932933        path = os.path.dirname(path) + '/'
    933934        self.assertTrue(fix_os_paths(path).endswith('/django/forms/'))
    934935
    935936    def test_filepathfield_2(self):
    936         path = forms.__file__
     937        path = upath(forms.__file__)
    937938        path = os.path.dirname(os.path.abspath(path)) + '/'
    938939        f = FilePathField(path=path)
    939940        f.choices = [p for p in f.choices if p[0].endswith('.py')]
    class FieldsTests(SimpleTestCase):  
    954955        assert fix_os_paths(f.clean(path + 'fields.py')).endswith('/django/forms/fields.py')
    955956
    956957    def test_filepathfield_3(self):
    957         path = forms.__file__
     958        path = upath(forms.__file__)
    958959        path = os.path.dirname(os.path.abspath(path)) + '/'
    959960        f = FilePathField(path=path, match='^.*?\.py$')
    960961        f.choices.sort()
    class FieldsTests(SimpleTestCase):  
    972973            self.assertTrue(got[0].endswith(exp[0]))
    973974
    974975    def test_filepathfield_4(self):
    975         path = os.path.abspath(forms.__file__)
     976        path = os.path.abspath(upath(forms.__file__))
    976977        path = os.path.dirname(path) + '/'
    977978        f = FilePathField(path=path, recursive=True, match='^.*?\.py$')
    978979        f.choices.sort()
    class FieldsTests(SimpleTestCase):  
    992993            self.assertTrue(got[0].endswith(exp[0]))
    993994
    994995    def test_filepathfield_folders(self):
    995         path = os.path.dirname(__file__) + '/filepath_test_files/'
     996        path = os.path.dirname(upath(__file__)) + '/filepath_test_files/'
    996997        f = FilePathField(path=path, allow_folders=True, allow_files=False)
    997998        f.choices.sort()
    998999        expected = [
  • tests/regressiontests/httpwrappers/tests.py

    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,  
    1414                         parse_cookie)
    1515from django.test import TestCase
    1616from django.utils.encoding import smart_str
     17from django.utils._os import upath
    1718from django.utils import six
    1819from django.utils import unittest
    1920
    class StreamingHttpResponseTests(TestCase):  
    483484
    484485class FileCloseTests(TestCase):
    485486    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')
    487488
    488489        # file isn't closed until we close the response.
    489490        file1 = open(filename)
    class FileCloseTests(TestCase):  
    516517        self.assertTrue(file2.closed)
    517518
    518519    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')
    520521
    521522        # file isn't closed until we close the response.
    522523        file1 = open(filename)
  • tests/regressiontests/i18n/commands/compilation.py

    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  
    44from django.test import TestCase
    55from django.test.utils import override_settings
    66from django.utils import translation, six
     7from django.utils._os import upath
    78from django.utils.six import StringIO
    89
    9 test_dir = os.path.abspath(os.path.dirname(__file__))
     10test_dir = os.path.abspath(os.path.dirname(upath(__file__)))
    1011
    1112
    1213class MessageCompilationTests(TestCase):
    class PoFileTests(MessageCompilationTests):  
    2526
    2627    def test_bom_rejection(self):
    2728        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:
    3030            call_command('compilemessages', locale=self.LOCALE, stderr=StringIO())
     31        self.assertIn("file has a BOM (Byte Order Mark)", cm.exception.args[0])
    3132        self.assertFalse(os.path.exists(self.MO_FILE))
    3233
    3334
  • tests/regressiontests/i18n/commands/extraction.py

    diff --git a/tests/regressiontests/i18n/commands/extraction.py b/tests/regressiontests/i18n/commands/extraction.py
    index ca2c3cc..aa5efe1 100644
    a b  
    11# -*- encoding: utf-8 -*-
     2from __future__ import unicode_literals
    23
    34import os
    45import re
    import shutil  
    67
    78from django.core import management
    89from django.test import TestCase
     10from django.utils.encoding import force_text
     11from django.utils._os import upath
    912from django.utils.six import StringIO
    1013
    1114
    class ExtractorTests(TestCase):  
    1720
    1821    def setUp(self):
    1922        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__)))
    2124
    2225    def _rmrf(self, dname):
    2326        if os.path.commonprefix([self.test_dir, os.path.abspath(dname)]) != self.test_dir:
    class BasicExtractorTests(ExtractorTests):  
    5558        management.call_command('makemessages', locale=LOCALE, verbosity=0)
    5659        self.assertTrue(os.path.exists(self.PO_FILE))
    5760        with open(self.PO_FILE, 'r') as fp:
    58             po_contents = fp.read()
     61            po_contents = force_text(fp.read())
    5962            self.assertTrue('#. Translators: This comment should be extracted' in po_contents)
    6063            self.assertTrue('This comment should not be extracted' not in po_contents)
    6164            # Comments in templates
    class BasicExtractorTests(ExtractorTests):  
    8386        management.call_command('makemessages', locale=LOCALE, verbosity=0)
    8487        self.assertTrue(os.path.exists(self.PO_FILE))
    8588        with open(self.PO_FILE, 'r') as fp:
    86             po_contents = fp.read()
     89            po_contents = force_text(fp.read())
    8790            self.assertMsgId('Literal with a percent symbol at the end %%', po_contents)
    8891            self.assertMsgId('Literal with a percent %% symbol in the middle', po_contents)
    8992            self.assertMsgId('Completed 50%% of all the tasks', po_contents)
    class BasicExtractorTests(ExtractorTests):  
    99102        management.call_command('makemessages', locale=LOCALE, verbosity=0)
    100103        self.assertTrue(os.path.exists(self.PO_FILE))
    101104        with open(self.PO_FILE, 'r') as fp:
    102             po_contents = fp.read()
     105            po_contents = force_text(fp.read())
    103106            self.assertMsgId('I think that 100%% is more that 50%% of anything.', po_contents)
    104107            self.assertMsgId('I think that 100%% is more that 50%% of %(obj)s.', po_contents)
    105108            self.assertMsgId("Blocktrans extraction shouldn't double escape this: %%, a=%(a)s", po_contents)
    class BasicExtractorTests(ExtractorTests):  
    123126        stdout = StringIO()
    124127        management.call_command('makemessages', locale=LOCALE, stdout=stdout)
    125128        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()))
    127130
    128131    def test_template_message_context_extractor(self):
    129132        """
    class BasicExtractorTests(ExtractorTests):  
    135138        management.call_command('makemessages', locale=LOCALE, verbosity=0)
    136139        self.assertTrue(os.path.exists(self.PO_FILE))
    137140        with open(self.PO_FILE, 'r') as fp:
    138             po_contents = fp.read()
     141            po_contents = force_text(fp.read())
    139142            # {% trans %}
    140143            self.assertTrue('msgctxt "Special trans context #1"' in po_contents)
    141144            self.assertTrue("Translatable literal #7a" in po_contents)
    class BasicExtractorTests(ExtractorTests):  
    161164        management.call_command('makemessages', locale=LOCALE, verbosity=0)
    162165        self.assertTrue(os.path.exists(self.PO_FILE))
    163166        with open(self.PO_FILE, 'r') as fp:
    164             po_contents = fp.read()
     167            po_contents = force_text(fp.read())
    165168            # {% trans %}
    166169            self.assertTrue('msgctxt "Context wrapped in double quotes"' in po_contents)
    167170            self.assertTrue('msgctxt "Context wrapped in single quotes"' in po_contents)
    class SymlinkExtractorTests(ExtractorTests):  
    216219
    217220    def setUp(self):
    218221        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__)))
    220223        self.symlinked_dir = os.path.join(self.test_dir, 'templates_symlinked')
    221224
    222225    def tearDown(self):
    class SymlinkExtractorTests(ExtractorTests):  
    238241            management.call_command('makemessages', locale=LOCALE, verbosity=0, symlinks=True)
    239242            self.assertTrue(os.path.exists(self.PO_FILE))
    240243            with open(self.PO_FILE, 'r') as fp:
    241                 po_contents = fp.read()
     244                po_contents = force_text(fp.read())
    242245                self.assertMsgId('This literal should be included.', po_contents)
    243246                self.assertTrue('templates_symlinked/test.html' in po_contents)
    244247
    class CopyPluralFormsExtractorTests(ExtractorTests):  
    250253        management.call_command('makemessages', locale=LOCALE, verbosity=0)
    251254        self.assertTrue(os.path.exists(self.PO_FILE))
    252255        with open(self.PO_FILE, 'r') as fp:
    253             po_contents = fp.read()
     256            po_contents = force_text(fp.read())
    254257            self.assertTrue('Plural-Forms: nplurals=2; plural=(n != 1)' in po_contents)
    255258
    256259
    class NoWrapExtractorTests(ExtractorTests):  
    261264        management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=True)
    262265        self.assertTrue(os.path.exists(self.PO_FILE))
    263266        with open(self.PO_FILE, 'r') as fp:
    264             po_contents = fp.read()
     267            po_contents = force_text(fp.read())
    265268            self.assertMsgId('This literal should also be included wrapped or not wrapped depending on the use of the --no-wrap option.', po_contents)
    266269
    267270    def test_no_wrap_disabled(self):
    class NoWrapExtractorTests(ExtractorTests):  
    269272        management.call_command('makemessages', locale=LOCALE, verbosity=0, no_wrap=False)
    270273        self.assertTrue(os.path.exists(self.PO_FILE))
    271274        with open(self.PO_FILE, 'r') as fp:
    272             po_contents = fp.read()
     275            po_contents = force_text(fp.read())
    273276            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)
    274277
    275278
    class NoLocationExtractorTests(ExtractorTests):  
    280283        management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=True)
    281284        self.assertTrue(os.path.exists(self.PO_FILE))
    282285        with open(self.PO_FILE, 'r') as fp:
    283             po_contents = fp.read()
     286            po_contents = force_text(fp.read())
    284287            self.assertFalse('#: templates/test.html:55' in po_contents)
    285288
    286289    def test_no_location_disabled(self):
    class NoLocationExtractorTests(ExtractorTests):  
    288291        management.call_command('makemessages', locale=LOCALE, verbosity=0, no_location=False)
    289292        self.assertTrue(os.path.exists(self.PO_FILE))
    290293        with open(self.PO_FILE, 'r') as fp:
    291             po_contents = fp.read()
     294            po_contents = force_text(fp.read())
    292295            self.assertTrue('#: templates/test.html:55' in po_contents)
  • tests/regressiontests/i18n/contenttypes/tests.py

    diff --git a/tests/regressiontests/i18n/contenttypes/tests.py b/tests/regressiontests/i18n/contenttypes/tests.py
    index 178232f..5e8a982 100644
    a b import os  
    66from django.contrib.contenttypes.models import ContentType
    77from django.test import TestCase
    88from django.test.utils import override_settings
     9from django.utils._os import upath
    910from django.utils import six
    1011from django.utils import translation
    1112
    from django.utils import translation  
    1314@override_settings(
    1415    USE_I18N=True,
    1516    LOCALE_PATHS=(
    16         os.path.join(os.path.dirname(__file__), 'locale'),
     17        os.path.join(os.path.dirname(upath(__file__)), 'locale'),
    1718    ),
    1819    LANGUAGE_CODE='en',
    1920    LANGUAGES=(
  • tests/regressiontests/i18n/patterns/tests.py

    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  
    77from django.test import TestCase
    88from django.test.utils import override_settings
    99from django.template import Template, Context
     10from django.utils._os import upath
    1011from django.utils import translation
    1112
    1213
    1314@override_settings(
    1415    USE_I18N=True,
    1516    LOCALE_PATHS=(
    16         os.path.join(os.path.dirname(__file__), 'locale'),
     17        os.path.join(os.path.dirname(upath(__file__)), 'locale'),
    1718    ),
    1819    TEMPLATE_DIRS=(
    19         os.path.join(os.path.dirname(__file__), 'templates'),
     20        os.path.join(os.path.dirname(upath(__file__)), 'templates'),
    2021    ),
    2122    LANGUAGE_CODE='en',
    2223    LANGUAGES=(
  • tests/regressiontests/i18n/tests.py

    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,  
    1818    number_format)
    1919from django.utils.importlib import import_module
    2020from django.utils.numberformat import format as nformat
     21from django.utils._os import upath
    2122from django.utils.safestring import mark_safe, SafeBytes, SafeString, SafeText
    2223from django.utils import six
    2324from django.utils.six import PY3
    from .patterns.tests import (URLRedirectWithoutTrailingSlashTests,  
    4445    URLPrefixTests, URLResponseTests, URLRedirectTests, PathUnusedTests)
    4546
    4647
    47 here = os.path.dirname(os.path.abspath(__file__))
     48here = os.path.dirname(os.path.abspath(upath(__file__)))
    4849extended_locale_paths = settings.LOCALE_PATHS + (
    4950    os.path.join(here, 'other', 'locale'),
    5051)
    class FormattingTests(TestCase):  
    666667        with self.settings(USE_L10N=True,
    667668                FORMAT_MODULE_PATH='regressiontests.i18n.other.locale'):
    668669            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
    671672                self.assertEqual(new, old, 'Value returned by get_formats_modules() must be preserved between calls.')
    672673
    673674    def test_localize_templatetag_and_filter(self):
  • tests/regressiontests/model_fields/imagefield.py

    diff --git a/tests/regressiontests/model_fields/imagefield.py b/tests/regressiontests/model_fields/imagefield.py
    index 7446f22..df0215d 100644
    a b import shutil  
    66from django.core.files import File
    77from django.core.files.images import ImageFile
    88from django.test import TestCase
     9from django.utils._os import upath
    910from django.utils.unittest import skipIf
    1011
    1112from .models import Image
    class ImageFieldTestMixin(object):  
    4344            shutil.rmtree(temp_storage_dir)
    4445        os.mkdir(temp_storage_dir)
    4546
    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")
    4748        self.file1 = self.File(open(file_path1, 'rb'))
    4849
    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")
    5051        self.file2 = self.File(open(file_path2, 'rb'))
    5152
    5253    def tearDown(self):
  • tests/regressiontests/model_forms_regress/models.py

    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  
    55from django.core.exceptions import ValidationError
    66from django.db import models
    77from django.utils.encoding import python_2_unicode_compatible
     8from django.utils._os import upath
    89
    910
    1011class Person(models.Model):
    class Triple(models.Model):  
    1920        unique_together = (('left', 'middle'), ('middle', 'right'))
    2021
    2122class 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)
    2324
    2425@python_2_unicode_compatible
    2526class Publication(models.Model):
  • tests/regressiontests/servers/tests.py

    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  
    1515from django.core.servers.basehttp import WSGIServerException
    1616from django.test.utils import override_settings
    1717from django.utils.http import urlencode
     18from django.utils._os import upath
    1819
    1920from .models import Person
    2021
    2122
    22 TEST_ROOT = os.path.dirname(__file__)
     23TEST_ROOT = os.path.dirname(upath(__file__))
    2324TEST_SETTINGS = {
    2425    'MEDIA_URL': '/media/',
    2526    'MEDIA_ROOT': os.path.join(TEST_ROOT, 'media'),
  • tests/regressiontests/staticfiles_tests/tests.py

    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  
    1515from django.core.management import call_command
    1616from django.test import TestCase
    1717from django.test.utils import override_settings
    18 from django.utils.encoding import smart_text
     18from django.utils.encoding import force_text
    1919from django.utils.functional import empty
    20 from django.utils._os import rmtree_errorhandler
     20from django.utils._os import rmtree_errorhandler, upath
    2121from django.utils import six
    2222
    2323from django.contrib.staticfiles import finders, storage
    2424
    25 TEST_ROOT = os.path.dirname(__file__)
     25TEST_ROOT = os.path.dirname(upath(__file__))
    2626TEST_SETTINGS = {
    2727    'DEBUG': True,
    2828    'MEDIA_URL': '/media/',
    class BaseStaticFilesTestCase(object):  
    7777        os.unlink(self._backup_filepath)
    7878
    7979    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)),
    8181                        "'%s' not in '%s'" % (text, filepath))
    8282
    8383    def assertFileNotFound(self, filepath):
    class TestFindStatic(CollectionTestCase, TestDefaults):  
    195195        call_command('findstatic', filepath, all=False, verbosity=0, stdout=out)
    196196        out.seek(0)
    197197        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:
    199199            return f.read()
    200200
    201201    def test_all_files(self):
    class TestFindStatic(CollectionTestCase, TestDefaults):  
    207207        out.seek(0)
    208208        lines = [l.strip() for l in out.readlines()]
    209209        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]))
    212212
    213213
    214214class TestCollection(CollectionTestCase, TestDefaults):
  • tests/regressiontests/templates/loaders.py

    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  
    1818from django.template.loaders.eggs import Loader as EggLoader
    1919from django.template import loader
    2020from django.utils import unittest, six
     21from django.utils._os import upath
    2122from django.utils.six import StringIO
    2223
    2324
    class CachedLoader(unittest.TestCase):  
    111112    def test_templatedir_caching(self):
    112113        "Check that the template directories form part of the template cache key. Refs #13573"
    113114        # 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'),))
    115116        # 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'),))
    117118
    118119        # The two templates should not have the same content
    119120        self.assertNotEqual(t1.render(Context({})), t2.render(Context({})))
    class RenderToStringTest(unittest.TestCase):  
    123124    def setUp(self):
    124125        self._old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS
    125126        settings.TEMPLATE_DIRS = (
    126             os.path.join(os.path.dirname(__file__), 'templates'),
     127            os.path.join(os.path.dirname(upath(__file__)), 'templates'),
    127128        )
    128129
    129130    def tearDown(self):
  • tests/regressiontests/templates/response.py

    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  
    1111from django.template.response import (TemplateResponse, SimpleTemplateResponse,
    1212                                      ContentNotRenderedError)
    1313from django.test.utils import override_settings
     14from django.utils._os import upath
    1415
    1516def test_processor(request):
    1617    return {'processors': 'yes'}
    class SimpleTemplateResponseTest(TestCase):  
    206207
    207208@override_settings(
    208209    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')),
    210211)
    211212class TemplateResponseTest(TestCase):
    212213
  • tests/regressiontests/templates/tests.py

    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,  
    3030from django.utils import unittest
    3131from django.utils.encoding import python_2_unicode_compatible
    3232from django.utils.formats import date_format
     33from django.utils._os import upath
    3334from django.utils.translation import activate, deactivate, ugettext as _
    3435from django.utils.safestring import mark_safe
    3536from django.utils import six
    class Templates(TestCase):  
    423424        # Set ALLOWED_INCLUDE_ROOTS so that ssi works.
    424425        old_allowed_include_roots = settings.ALLOWED_INCLUDE_ROOTS
    425426        settings.ALLOWED_INCLUDE_ROOTS = (
    426             os.path.dirname(os.path.abspath(__file__)),
     427            os.path.dirname(os.path.abspath(upath(__file__))),
    427428        )
    428429
    429430        # Warm the URL reversing cache. This ensures we don't pay the cost
    class Templates(TestCase):  
    514515    def get_template_tests(self):
    515516        # SYNTAX --
    516517        # '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__)))
    518519        tests = {
    519520            ### BASIC SYNTAX ################################################
    520521
    class TemplateTagLoading(unittest.TestCase):  
    16491650    def setUp(self):
    16501651        self.old_path = sys.path[:]
    16511652        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__))
    16531654        self.old_tag_modules = template_base.templatetags_modules
    16541655        template_base.templatetags_modules = []
    16551656
  • tests/regressiontests/test_client_regress/tests.py

    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  
    1616from django.test.client import encode_file, RequestFactory
    1717from django.test.utils import ContextList, override_settings, str_prefix
    1818from django.template.response import SimpleTemplateResponse
     19from django.utils._os import upath
    1920from django.utils.translation import ugettext_lazy
    2021from django.http import HttpResponse
    2122
    2223
    2324@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'),)
    2526)
    2627class AssertContainsTests(TestCase):
    2728    def test_contains(self):
    class TemplateExceptionTests(TestCase):  
    629630                    template_loader.reset()
    630631
    631632    @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'),)
    633634    )
    634635    def test_bad_404_template(self):
    635636        "Errors found when rendering 404 error templates are re-raised"
  • tests/regressiontests/urlpatterns_reverse/tests.py

    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):  
    237237            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'])))
    238238            for tried, expected in zip(e.args[0]['tried'], url_types_names):
    239239                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']))
    241241                    if 'name' in e:
    242242                        if not e['name']:
    243243                            self.assertTrue(t.name is None, 'Expected no URL name but found %s.' % t.name)
  • tests/regressiontests/utils/archive.py

    diff --git a/tests/regressiontests/utils/archive.py b/tests/regressiontests/utils/archive.py
    index 5575f34..8861b4a 100644
    a b import tempfile  
    44from django.utils import unittest
    55
    66from django.utils.archive import Archive, extract
     7from django.utils._os import upath
    78
    89
    9 TEST_DIR = os.path.join(os.path.dirname(__file__), 'archives')
     10TEST_DIR = os.path.join(os.path.dirname(upath(__file__)), 'archives')
    1011
    1112
    1213class ArchiveTester(object):
  • tests/regressiontests/utils/module_loading.py

    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  
    66from django.utils import unittest
    77from django.utils.importlib import import_module
    88from django.utils.module_loading import module_has_submodule
     9from django.utils._os import upath
    910
    1011
    1112class DefaultLoader(unittest.TestCase):
    class DefaultLoader(unittest.TestCase):  
    5051class EggLoader(unittest.TestCase):
    5152    def setUp(self):
    5253        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__))
    5455
    5556    def tearDown(self):
    5657        sys.path = self.old_path
  • tests/regressiontests/views/tests/debug.py

    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  
    1414from django.test import TestCase, RequestFactory
    1515from django.test.utils import (override_settings, setup_test_template_loader,
    1616    restore_template_loaders)
     17from django.utils.encoding import force_text
    1718from django.views.debug import ExceptionReporter
    1819
    1920from .. import BrokenException, except_args
    class ExceptionReportTestMixin(object):  
    306307            self.assertEqual(len(mail.outbox), 1)
    307308            email = mail.outbox[0]
    308309            # 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)
    313315            if check_for_POST_params:
    314316                for k, v in self.breakfast_data.items():
    315317                    # 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)
    318320
    319321    def verify_safe_email(self, view, check_for_POST_params=True):
    320322        """
    class ExceptionReportTestMixin(object):  
    327329            self.assertEqual(len(mail.outbox), 1)
    328330            email = mail.outbox[0]
    329331            # 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)
    334337            if check_for_POST_params:
    335338                for k, v in self.breakfast_data.items():
    336339                    # All POST parameters' names are shown.
    337                     self.assertIn(k, email.body)
     340                    self.assertIn(k, body)
    338341                # 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)
    341344                # 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)
    344347
    345348    def verify_paranoid_email(self, view):
    346349        """
    class ExceptionReportTestMixin(object):  
    353356            self.assertEqual(len(mail.outbox), 1)
    354357            email = mail.outbox[0]
    355358            # 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)
    360364            for k, v in self.breakfast_data.items():
    361365                # All POST parameters' names are shown.
    362                 self.assertIn(k, email.body)
     366                self.assertIn(k, body)
    363367                # No POST parameters' values are shown.
    364                 self.assertNotIn(v, email.body)
     368                self.assertNotIn(v, body)
    365369
    366370
    367371class ExceptionReporterFilterTests(TestCase, ExceptionReportTestMixin):
  • tests/regressiontests/views/tests/i18n.py

    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  
    99from django.test import LiveServerTestCase, TestCase
    1010from django.test.utils import override_settings
    1111from django.utils import six, unittest
     12from django.utils._os import upath
    1213from django.utils.translation import override
    1314from django.utils.text import javascript_quote
    1415
    class JsI18NTestsMultiPackage(TestCase):  
    152153    def testI18NWithLocalePaths(self):
    153154        extended_locale_paths = settings.LOCALE_PATHS + (
    154155            path.join(path.dirname(
    155                 path.dirname(path.abspath(__file__))), 'app3', 'locale'),)
     156                path.dirname(path.abspath(upath(__file__)))), 'app3', 'locale'),)
    156157        with self.settings(LANGUAGE_CODE='es-ar', LOCALE_PATHS=extended_locale_paths):
    157158            with override('es-ar'):
    158159                response = self.client.get('/views/jsi18n/')
  • tests/regressiontests/views/urls.py

    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  
    44from os import path
    55
    66from django.conf.urls import patterns, url, include
     7from django.utils._os import upath
    78
    89from . import views
    910
    1011
    11 base_dir = path.dirname(path.abspath(__file__))
     12base_dir = path.dirname(path.abspath(upath(__file__)))
    1213media_dir = path.join(base_dir, 'media')
    1314locale_dir = path.join(base_dir, 'locale')
    1415
  • tests/runtests.py

    diff --git a/tests/runtests.py b/tests/runtests.py
    index 90e2dc2..8c56e27 100755
    a b import tempfile  
    77import warnings
    88
    99from django import contrib
     10from django.utils._os import upath
    1011from django.utils import six
    1112
    1213# databrowse is deprecated, but we still want to run its tests
    REGRESSION_TESTS_DIR_NAME = 'regressiontests'  
    1920
    2021TEST_TEMPLATE_DIR = 'templates'
    2122
    22 RUNTESTS_DIR = os.path.dirname(__file__)
    23 CONTRIB_DIR = os.path.dirname(contrib.__file__)
     23RUNTESTS_DIR = os.path.dirname(upath(__file__))
     24CONTRIB_DIR = os.path.dirname(upath(contrib.__file__))
    2425MODEL_TEST_DIR = os.path.join(RUNTESTS_DIR, MODEL_TESTS_DIR_NAME)
    2526REGRESSION_TEST_DIR = os.path.join(RUNTESTS_DIR, REGRESSION_TESTS_DIR_NAME)
    2627TEMP_DIR = tempfile.mkdtemp(prefix='django_')
    def bisect_tests(bisection_label, options, test_labels):  
    192193            pass
    193194
    194195    subprocess_args = [
    195         sys.executable, __file__, '--settings=%s' % options.settings]
     196        sys.executable, upath(__file__), '--settings=%s' % options.settings]
    196197    if options.failfast:
    197198        subprocess_args.append('--failfast')
    198199    if options.verbosity:
    def paired_tests(paired_test, options, test_labels):  
    253254            pass
    254255
    255256    subprocess_args = [
    256         sys.executable, __file__, '--settings=%s' % options.settings]
     257        sys.executable, upath(__file__), '--settings=%s' % options.settings]
    257258    if options.failfast:
    258259        subprocess_args.append('--failfast')
    259260    if options.verbosity:
Back to Top