Refs #23919 -- Removed django.utils._os.upath()/npath()/abspathu() usage.

These functions do nothing on Python 3.
This commit is contained in:
Tim Graham 2017-01-20 08:01:02 -05:00 committed by GitHub
parent ec4c1d6717
commit 4e729feaa6
64 changed files with 108 additions and 178 deletions

View File

@ -2,7 +2,6 @@ import os
from importlib import import_module
from django.core.exceptions import ImproperlyConfigured
from django.utils._os import upath
from django.utils.module_loading import module_has_submodule
MODELS_MODULE_NAME = 'models'
@ -80,7 +79,7 @@ class AppConfig:
"The app module %r has no filesystem location, "
"you must configure this app with an AppConfig subclass "
"with a 'path' class attribute." % (module,))
return upath(paths[0])
return paths[0]
@classmethod
def create(cls, entry):

View File

@ -8,7 +8,6 @@ from django.conf import settings
from django.core.exceptions import (
FieldDoesNotExist, ImproperlyConfigured, ValidationError,
)
from django.utils._os import upath
from django.utils.encoding import force_text
from django.utils.functional import lazy
from django.utils.html import format_html
@ -168,7 +167,7 @@ class CommonPasswordValidator:
https://xato.net/passwords/more-top-worst-passwords/
"""
DEFAULT_PASSWORD_LIST_PATH = os.path.join(
os.path.dirname(os.path.realpath(upath(__file__))), 'common-passwords.txt.gz'
os.path.dirname(os.path.realpath(__file__)), 'common-passwords.txt.gz'
)
def __init__(self, password_list_path=DEFAULT_PASSWORD_LIST_PATH):

View File

@ -9,7 +9,7 @@ from django.core.files import File, locks
from django.core.files.move import file_move_safe
from django.core.signals import setting_changed
from django.utils import timezone
from django.utils._os import abspathu, safe_join
from django.utils._os import safe_join
from django.utils.crypto import get_random_string
from django.utils.deconstruct import deconstructible
from django.utils.encoding import filepath_to_uri, force_text
@ -201,7 +201,7 @@ class FileSystemStorage(Storage):
@cached_property
def location(self):
return abspathu(self.base_location)
return os.path.abspath(self.base_location)
@cached_property
def base_url(self):

View File

@ -14,7 +14,6 @@ from django.core.management.base import (
)
from django.core.management.color import color_style
from django.utils import autoreload
from django.utils._os import npath, upath
from django.utils.encoding import force_text
@ -26,7 +25,7 @@ def find_commands(management_dir):
Returns an empty list if no commands are defined.
"""
command_dir = os.path.join(management_dir, 'commands')
return [name for _, name, is_pkg in pkgutil.iter_modules([npath(command_dir)])
return [name for _, name, is_pkg in pkgutil.iter_modules([command_dir])
if not is_pkg and not name.startswith('_')]
@ -63,7 +62,7 @@ def get_commands():
The dictionary is cached on the first call and reused on subsequent
calls.
"""
commands = {name: 'django.core' for name in find_commands(upath(__path__[0]))}
commands = {name: 'django.core' for name in find_commands(__path__[0])}
if not settings.configured:
return commands

View File

@ -4,7 +4,6 @@ import os
from django.core.management.base import BaseCommand, CommandError
from django.core.management.utils import find_command, popen_wrapper
from django.utils._os import npath, upath
def has_bom(fn):
@ -62,7 +61,7 @@ class Command(BaseCommand):
basedirs = [os.path.join('conf', 'locale'), 'locale']
if os.environ.get('DJANGO_SETTINGS_MODULE'):
from django.conf import settings
basedirs.extend(upath(path) for path in settings.LOCALE_PATHS)
basedirs.extend(settings.LOCALE_PATHS)
# Walk entire tree, looking for locale directories
for dirpath, dirnames, filenames in os.walk('.', topdown=True):
@ -115,13 +114,13 @@ class Command(BaseCommand):
base_path = os.path.splitext(po_path)[0]
# Check writability on first location
if i == 0 and not is_writable(npath(base_path + '.mo')):
if i == 0 and not is_writable(base_path + '.mo'):
self.stderr.write("The po files under %s are in a seemingly not writable location. "
"mo files will not be updated/created." % dirpath)
return
args = [self.program] + self.program_options + [
'-o', npath(base_path + '.mo'), npath(base_path + '.po')
'-o', base_path + '.mo', base_path + '.po'
]
output, errors, status = popen_wrapper(args)
if status:

View File

@ -17,7 +17,6 @@ from django.db import (
DEFAULT_DB_ALIAS, DatabaseError, IntegrityError, connections, router,
transaction,
)
from django.utils._os import upath
from django.utils.encoding import force_text
from django.utils.functional import cached_property
@ -287,7 +286,7 @@ class Command(BaseCommand):
dirs.append(app_dir)
dirs.extend(list(fixture_dirs))
dirs.append('')
dirs = [upath(os.path.abspath(os.path.realpath(d))) for d in dirs]
dirs = [os.path.abspath(os.path.realpath(d)) for d in dirs]
return dirs
def parse_name(self, fixture_name):

View File

@ -14,7 +14,6 @@ from django.core.management.base import BaseCommand, CommandError
from django.core.management.utils import (
find_command, handle_extensions, popen_wrapper,
)
from django.utils._os import upath
from django.utils.encoding import DEFAULT_LOCALE_ENCODING
from django.utils.functional import cached_property
from django.utils.jslex import prepare_js_for_gettext
@ -638,7 +637,7 @@ class Command(BaseCommand):
the msgs string, inserting it at the right place. msgs should be the
contents of a newly created .po file.
"""
django_dir = os.path.normpath(os.path.join(os.path.dirname(upath(django.__file__))))
django_dir = os.path.normpath(os.path.join(os.path.dirname(django.__file__)))
if self.domain == 'djangojs':
domains = ('djangojs', 'django')
else:

View File

@ -7,7 +7,6 @@ from django.apps import apps
from django.db import migrations
from django.db.migrations.loader import MigrationLoader
from django.db.migrations.serializer import serializer_factory
from django.utils._os import upath
from django.utils.encoding import force_text
from django.utils.inspect import get_func_args
from django.utils.module_loading import module_dir
@ -229,7 +228,7 @@ class MigrationWriter:
pass
else:
try:
return upath(module_dir(migrations_module))
return module_dir(migrations_module)
except ValueError:
pass
@ -250,7 +249,7 @@ class MigrationWriter:
continue
else:
try:
base_dir = upath(module_dir(base_module))
base_dir = module_dir(base_module)
except ValueError:
continue
else:

View File

@ -6,7 +6,6 @@ from threading import local
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils import six
from django.utils._os import npath, upath
from django.utils.functional import cached_property
from django.utils.module_loading import import_string
@ -116,10 +115,10 @@ def load_backend(backend_name):
except ImportError as e_user:
# The database backend wasn't found. Display a helpful error message
# listing all possible (built-in) database backends.
backend_dir = os.path.join(os.path.dirname(upath(__file__)), 'backends')
backend_dir = os.path.join(os.path.dirname(__file__), 'backends')
try:
builtin_backends = [
name for _, name, ispkg in pkgutil.iter_modules([npath(backend_dir)])
name for _, name, ispkg in pkgutil.iter_modules([backend_dir])
if ispkg and name not in {'base', 'dummy', 'postgresql_psycopg2'}
]
except EnvironmentError:

View File

@ -4,7 +4,6 @@ import os
from django.conf import settings
from django.template.backends.django import DjangoTemplates
from django.template.loader import get_template
from django.utils._os import upath
from django.utils.functional import cached_property
from django.utils.module_loading import import_string
@ -14,7 +13,7 @@ except ImportError:
def Jinja2(params):
raise ImportError("jinja2 isn't installed")
ROOT = upath(os.path.dirname(__file__))
ROOT = os.path.dirname(__file__)
@functools.lru_cache()

View File

@ -5,7 +5,6 @@ from collections import Counter, OrderedDict
from django.apps import apps
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils._os import upath
from django.utils.functional import cached_property
from django.utils.module_loading import import_string
@ -103,6 +102,6 @@ def get_app_template_dirs(dirname):
continue
template_dir = os.path.join(app_config.path, dirname)
if os.path.isdir(template_dir):
template_dirs.append(upath(template_dir))
template_dirs.append(template_dir)
# Immutable return value because it will be cached and shared by callers.
return tuple(template_dirs)

View File

@ -5,20 +5,19 @@ from os.path import abspath, dirname, join, normcase, sep
from django.core.exceptions import SuspiciousFileOperation
from django.utils.encoding import force_text
# For backwards-compatibility in Django 2.0
abspathu = abspath
def upath(path):
"""
Always return a unicode path.
"""
"""Always return a unicode path (did something for Python 2)."""
return path
def npath(path):
"""
Always return a native path, that is unicode on Python 3 and bytestring on
Python 2.
Python 2. Noop for Python 3.
"""
return path
@ -33,8 +32,8 @@ def safe_join(base, *paths):
"""
base = force_text(base)
paths = [force_text(p) for p in paths]
final_path = abspathu(join(base, *paths))
base_path = abspathu(base)
final_path = abspath(join(base, *paths))
base_path = abspath(base)
# Ensure final_path starts with base_path (using normcase to ensure we
# don't false-negative on case insensitive operating systems like Windows),
# further, one of the following conditions must be true:

View File

@ -41,7 +41,6 @@ from django.apps import apps
from django.conf import settings
from django.core.signals import request_finished
from django.utils import six
from django.utils._os import npath
# This import does nothing, but it's necessary to avoid some race conditions
# in the threading module. See http://code.djangoproject.com/ticket/2330 .
@ -111,7 +110,7 @@ def gen_filenames(only_new=False):
'conf', 'locale'),
'locale']
for app_config in reversed(list(apps.get_app_configs())):
basedirs.append(os.path.join(npath(app_config.path), 'locale'))
basedirs.append(os.path.join(app_config.path, 'locale'))
basedirs.extend(settings.LOCALE_PATHS)
basedirs = [os.path.abspath(basedir) for basedir in basedirs
if os.path.isdir(basedir)]

View File

@ -14,7 +14,6 @@ from django.conf.locale import LANG_INFO
from django.core.exceptions import AppRegistryNotReady
from django.core.signals import setting_changed
from django.dispatch import receiver
from django.utils._os import upath
from django.utils.encoding import force_text
from django.utils.safestring import SafeData, mark_safe
from django.utils.translation import LANGUAGE_SESSION_KEY
@ -155,7 +154,7 @@ class DjangoTranslation(gettext_module.GNUTranslations):
def _init_translation_catalog(self):
"""Creates a base catalog using global django translations."""
settingsfile = upath(sys.modules[settings.__module__].__file__)
settingsfile = sys.modules[settings.__module__].__file__
localedir = os.path.join(os.path.dirname(settingsfile), 'locale')
translation = self._new_gnu_trans(localedir)
self.merge(translation)
@ -399,7 +398,7 @@ def all_locale_paths():
Returns a list of paths to user-provides languages files.
"""
globalpath = os.path.join(
os.path.dirname(upath(sys.modules[settings.__module__].__file__)), 'locale')
os.path.dirname(sys.modules[settings.__module__].__file__), 'locale')
return [globalpath] + list(settings.LOCALE_PATHS)

View File

@ -26,10 +26,9 @@ from django.db.migrations.recorder import MigrationRecorder
from django.test import (
LiveServerTestCase, SimpleTestCase, TestCase, mock, override_settings,
)
from django.utils._os import npath, upath
from django.utils.encoding import force_text
custom_templates_dir = os.path.join(os.path.dirname(upath(__file__)), 'custom_templates')
custom_templates_dir = os.path.join(os.path.dirname(__file__), 'custom_templates')
PY36 = sys.version_info >= (3, 6)
SYSTEM_CHECK_MSG = 'System check identified no issues'
@ -128,7 +127,7 @@ class AdminScriptTestCase(unittest.TestCase):
def run_test(self, script, args, settings_file=None, apps=None):
base_dir = os.path.dirname(self.test_dir)
# The base dir for Django's tests is one level up.
tests_dir = os.path.dirname(os.path.dirname(upath(__file__)))
tests_dir = os.path.dirname(os.path.dirname(__file__))
# The base dir for Django is one level above the test dir. We don't use
# `import django` to figure that out, so we don't pick up a Django
# from site-packages or similar.
@ -152,7 +151,7 @@ class AdminScriptTestCase(unittest.TestCase):
python_path = [base_dir, django_dir, tests_dir]
python_path.extend(ext_backend_base_dirs)
# Use native strings for better compatibility
test_environ[str(python_path_var_name)] = npath(os.pathsep.join(python_path))
test_environ[str(python_path_var_name)] = os.pathsep.join(python_path)
test_environ[str('PYTHONWARNINGS')] = str('')
# Move to the test directory and run
@ -168,7 +167,7 @@ class AdminScriptTestCase(unittest.TestCase):
return out, err
def run_django_admin(self, args, settings_file=None):
script_dir = os.path.abspath(os.path.join(os.path.dirname(upath(django.__file__)), 'bin'))
script_dir = os.path.abspath(os.path.join(os.path.dirname(django.__file__), 'bin'))
return self.run_test(os.path.join(script_dir, 'django-admin.py'), args, settings_file)
def run_manage(self, args, settings_file=None):
@ -178,7 +177,7 @@ class AdminScriptTestCase(unittest.TestCase):
except OSError:
pass
conf_dir = os.path.dirname(upath(conf.__file__))
conf_dir = os.path.dirname(conf.__file__)
template_manage_py = os.path.join(conf_dir, 'project_template', 'manage.py-tpl')
test_manage_py = os.path.join(self.test_dir, 'manage.py')

View File

@ -1,10 +1,9 @@
import os
from django.conf.urls import url
from django.utils._os import upath
from django.views.static import serve
here = os.path.dirname(upath(__file__))
here = os.path.dirname(__file__)
urlpatterns = [
url(r'^custom_templates/(?P<path>.*)$', serve, {

View File

@ -31,7 +31,6 @@ from django.test import (
from django.test.utils import override_script_prefix, patch_logger
from django.urls import NoReverseMatch, resolve, reverse
from django.utils import formats, translation
from django.utils._os import upath
from django.utils.cache import get_max_age
from django.utils.deprecation import RemovedInDjango21Warning
from django.utils.encoding import force_bytes, force_text, iri_to_uri
@ -919,8 +918,8 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
# Put this app's and the shared tests templates dirs in DIRS to take precedence
# over the admin's templates dir.
'DIRS': [
os.path.join(os.path.dirname(upath(__file__)), 'templates'),
os.path.join(os.path.dirname(os.path.dirname(upath(__file__))), 'templates'),
os.path.join(os.path.dirname(__file__), 'templates'),
os.path.join(os.path.dirname(os.path.dirname(__file__)), 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {

View File

@ -3,13 +3,12 @@ import os
from django.apps import apps
from django.test import SimpleTestCase
from django.test.utils import extend_sys_path
from django.utils._os import upath
class EggLoadingTest(SimpleTestCase):
def setUp(self):
self.egg_dir = '%s/eggs' % os.path.dirname(upath(__file__))
self.egg_dir = '%s/eggs' % os.path.dirname(__file__)
def tearDown(self):
apps.clear_cache()

View File

@ -1,9 +1,8 @@
import os
from django.apps import AppConfig
from django.utils._os import upath
class NSAppConfig(AppConfig):
name = 'nsapp'
path = upath(os.path.dirname(__file__))
path = os.path.dirname(__file__)

View File

@ -7,7 +7,6 @@ from django.core.exceptions import AppRegistryNotReady, ImproperlyConfigured
from django.db import models
from django.test import SimpleTestCase, override_settings
from django.test.utils import extend_sys_path, isolate_apps
from django.utils._os import upath
from .default_config_app.apps import CustomConfig
from .models import SoAlternative, TotallyNormal, new_apps
@ -29,7 +28,7 @@ SOME_INSTALLED_APPS_NAMES = [
'django.contrib.auth',
] + SOME_INSTALLED_APPS[2:]
HERE = os.path.dirname(upath(__file__))
HERE = os.path.dirname(__file__)
class AppsTests(SimpleTestCase):
@ -385,7 +384,7 @@ class NamespacePackageAppTests(SimpleTestCase):
with extend_sys_path(self.base_location):
with self.settings(INSTALLED_APPS=['nsapp']):
app_config = apps.get_app_config('nsapp')
self.assertEqual(app_config.path, upath(self.app_path))
self.assertEqual(app_config.path, self.app_path)
def test_multiple_paths(self):
"""
@ -410,4 +409,4 @@ class NamespacePackageAppTests(SimpleTestCase):
with extend_sys_path(self.base_location, self.other_location):
with self.settings(INSTALLED_APPS=['nsapp.apps.NSAppConfig']):
app_config = apps.get_app_config('nsapp')
self.assertEqual(app_config.path, upath(self.app_path))
self.assertEqual(app_config.path, self.app_path)

View File

@ -1,7 +1,5 @@
import os
from django.utils._os import upath
AUTH_MIDDLEWARE = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
@ -9,7 +7,7 @@ AUTH_MIDDLEWARE = [
AUTH_TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(upath(__file__)), 'templates')],
'DIRS': [os.path.join(os.path.dirname(__file__), 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [

View File

@ -13,7 +13,6 @@ from django.core.exceptions import ValidationError
from django.db import models
from django.test import TestCase, override_settings
from django.test.utils import isolate_apps
from django.utils._os import upath
@override_settings(AUTH_PASSWORD_VALIDATORS=[
@ -171,7 +170,7 @@ class CommonPasswordValidatorTest(TestCase):
self.assertEqual(cm.exception.messages, [expected_error])
def test_validate_custom_list(self):
path = os.path.join(os.path.dirname(os.path.realpath(upath(__file__))), 'common-passwords-custom.txt')
path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'common-passwords-custom.txt')
validator = CommonPasswordValidator(password_list_path=path)
expected_error = "This password is too common."
self.assertIsNone(validator.validate('a-safe-password'))

View File

@ -24,7 +24,6 @@ from django.test import (
from django.test.utils import requires_tz_support
from django.urls import NoReverseMatch, reverse_lazy
from django.utils import timezone
from django.utils._os import upath
from .models import Storage, temp_storage, temp_storage_location
@ -108,7 +107,7 @@ class FileStorageTests(SimpleTestCase):
"""
storage = self.storage_class(location='')
self.assertEqual(storage.base_location, '')
self.assertEqual(storage.location, upath(os.getcwd()))
self.assertEqual(storage.location, os.getcwd())
def test_file_access_options(self):
"""

View File

@ -11,7 +11,6 @@ from django.core.files.move import file_move_safe
from django.core.files.temp import NamedTemporaryFile
from django.core.files.uploadedfile import SimpleUploadedFile, UploadedFile
from django.test import mock
from django.utils._os import upath
try:
from PIL import Image
@ -227,7 +226,7 @@ class DimensionClosingBug(unittest.TestCase):
images.open = catching_open
try:
images.get_image_dimensions(os.path.join(os.path.dirname(upath(__file__)), "test1.png"))
images.get_image_dimensions(os.path.join(os.path.dirname(__file__), "test1.png"))
finally:
del images.open
self.assertTrue(FileWrapper._closed)
@ -243,7 +242,7 @@ class InconsistentGetImageDimensionsBug(unittest.TestCase):
"""
Multiple calls of get_image_dimensions() should return the same size.
"""
img_path = os.path.join(os.path.dirname(upath(__file__)), "test.png")
img_path = os.path.join(os.path.dirname(__file__), "test.png")
with open(img_path, 'rb') as fh:
image = images.ImageFile(fh)
image_pil = Image.open(fh)
@ -258,7 +257,7 @@ class InconsistentGetImageDimensionsBug(unittest.TestCase):
Regression test for #19457
get_image_dimensions fails on some pngs, while Image.size is working good on them
"""
img_path = os.path.join(os.path.dirname(upath(__file__)), "magic.png")
img_path = os.path.join(os.path.dirname(__file__), "magic.png")
size = images.get_image_dimensions(img_path)
with open(img_path, 'rb') as fh:
self.assertEqual(size, Image.open(fh).size)
@ -275,7 +274,7 @@ class GetImageDimensionsTests(unittest.TestCase):
brokenimg.png is not a valid image and it has been generated by:
$ echo "123" > brokenimg.png
"""
img_path = os.path.join(os.path.dirname(upath(__file__)), "brokenimg.png")
img_path = os.path.join(os.path.dirname(__file__), "brokenimg.png")
with open(img_path, 'rb') as fh:
size = images.get_image_dimensions(fh)
self.assertEqual(size, (None, None))
@ -288,7 +287,7 @@ class GetImageDimensionsTests(unittest.TestCase):
Emulates the Parser feed error. Since the error is raised on every feed
attempt, the resulting image size should be invalid: (None, None).
"""
img_path = os.path.join(os.path.dirname(upath(__file__)), "test.png")
img_path = os.path.join(os.path.dirname(__file__), "test.png")
with mock.patch('PIL.ImageFile.Parser.feed', side_effect=struct.error):
with open(img_path, 'rb') as fh:
size = images.get_image_dimensions(fh)

View File

@ -14,7 +14,6 @@ from django.test import (
TestCase, TransactionTestCase, override_settings, skipIfDBFeature,
skipUnlessDBFeature,
)
from django.utils._os import upath
from .models import (
Absolute, Animal, Article, Book, Child, Circle1, Circle2, Circle3,
@ -26,7 +25,7 @@ from .models import (
Person, RefToNKChild, Store, Stuff, Thingy, Widget,
)
_cur_dir = os.path.dirname(os.path.abspath(upath(__file__)))
_cur_dir = os.path.dirname(os.path.abspath(__file__))
class TestFixtures(TestCase):
@ -142,7 +141,7 @@ class TestFixtures(TestCase):
fixture directory.
"""
load_absolute_path = os.path.join(
os.path.dirname(upath(__file__)),
os.path.dirname(__file__),
'fixtures',
'absolute.json'
)

View File

@ -2,7 +2,6 @@ import os.path
from django.forms import FilePathField, ValidationError, forms
from django.test import SimpleTestCase
from django.utils._os import upath
def fix_os_paths(x):
@ -19,13 +18,11 @@ def fix_os_paths(x):
class FilePathFieldTest(SimpleTestCase):
def test_filepathfield_1(self):
path = os.path.abspath(upath(forms.__file__))
path = os.path.dirname(path) + '/'
path = os.path.dirname(os.path.abspath(forms.__file__)) + '/'
self.assertTrue(fix_os_paths(path).endswith('/django/forms/'))
def test_filepathfield_2(self):
path = upath(forms.__file__)
path = os.path.dirname(os.path.abspath(path)) + '/'
path = os.path.dirname(os.path.abspath(forms.__file__)) + '/'
f = FilePathField(path=path)
f.choices = [p for p in f.choices if p[0].endswith('.py')]
f.choices.sort()
@ -49,8 +46,7 @@ class FilePathFieldTest(SimpleTestCase):
self.assertTrue(fix_os_paths(f.clean(path + 'fields.py')).endswith('/django/forms/fields.py'))
def test_filepathfield_3(self):
path = upath(forms.__file__)
path = os.path.dirname(os.path.abspath(path)) + '/'
path = os.path.dirname(os.path.abspath(forms.__file__)) + '/'
f = FilePathField(path=path, match=r'^.*?\.py$')
f.choices.sort()
expected = [
@ -69,8 +65,7 @@ class FilePathFieldTest(SimpleTestCase):
self.assertTrue(got[0].endswith(exp[0]))
def test_filepathfield_4(self):
path = os.path.abspath(upath(forms.__file__))
path = os.path.dirname(path) + '/'
path = os.path.dirname(os.path.abspath(forms.__file__)) + '/'
f = FilePathField(path=path, recursive=True, match=r'^.*?\.py$')
f.choices.sort()
expected = [
@ -89,7 +84,7 @@ class FilePathFieldTest(SimpleTestCase):
self.assertTrue(got[0].endswith(exp[0]))
def test_filepathfield_folders(self):
path = os.path.abspath(os.path.join(upath(__file__), '..', '..')) + '/tests/filepath_test_files/'
path = os.path.abspath(os.path.join(__file__, '..', '..')) + '/tests/filepath_test_files/'
f = FilePathField(path=path, allow_folders=True, allow_files=False)
f.choices.sort()
expected = [

View File

@ -4,7 +4,6 @@ import unittest
from django.core.files.uploadedfile import SimpleUploadedFile
from django.forms import ImageField
from django.test import SimpleTestCase
from django.utils._os import upath
try:
from PIL import Image
@ -13,7 +12,7 @@ except ImportError:
def get_img_path(path):
return os.path.join(os.path.abspath(os.path.join(upath(__file__), '..', '..')), 'tests', path)
return os.path.join(os.path.abspath(os.path.join(__file__, '..', '..')), 'tests', path)
@unittest.skipUnless(Image, "Pillow is required to test ImageField")

View File

@ -5,7 +5,6 @@ from django.forms.renderers import (
BaseRenderer, DjangoTemplates, Jinja2, TemplatesSetting,
)
from django.test import SimpleTestCase
from django.utils._os import upath
try:
import jinja2
@ -23,12 +22,12 @@ class SharedTests:
tpl = renderer.get_template('forms_tests/custom_widget.html')
expected_path = os.path.abspath(
os.path.join(
upath(os.path.dirname(__file__)),
os.path.dirname(__file__),
'..',
self.expected_widget_dir + '/forms_tests/custom_widget.html',
)
)
self.assertEqual(upath(tpl.origin.name), expected_path)
self.assertEqual(tpl.origin.name, expected_path)
class BaseTemplateRendererTests(SimpleTestCase):

View File

@ -49,7 +49,6 @@ from django.contrib.gis.gdal import HAS_GDAL
from django.contrib.gis.gdal.error import GDALException
from django.contrib.gis.shortcuts import numpy
from django.test import SimpleTestCase
from django.utils._os import upath
from ..data.rasters.textrasters import JSON_RASTER
@ -64,8 +63,7 @@ class GDALRasterTests(SimpleTestCase):
Test a GDALRaster instance created from a file (GeoTiff).
"""
def setUp(self):
self.rs_path = os.path.join(os.path.dirname(upath(__file__)),
'../data/rasters/raster.tif')
self.rs_path = os.path.join(os.path.dirname(__file__), '../data/rasters/raster.tif')
self.rs = GDALRaster(self.rs_path)
def test_rs_name_repr(self):
@ -388,7 +386,7 @@ class GDALRasterTests(SimpleTestCase):
@unittest.skipUnless(HAS_GDAL, "GDAL is required")
class GDALBandTests(SimpleTestCase):
def setUp(self):
self.rs_path = os.path.join(os.path.dirname(upath(__file__)), '../data/rasters/raster.tif')
self.rs_path = os.path.join(os.path.dirname(__file__), '../data/rasters/raster.tif')
rs = GDALRaster(self.rs_path)
self.band = rs.bands[0]
@ -403,7 +401,7 @@ class GDALBandTests(SimpleTestCase):
if numpy:
data = self.band.data()
assert_array = numpy.loadtxt(
os.path.join(os.path.dirname(upath(__file__)), '../data/rasters/raster.numpy.txt')
os.path.join(os.path.dirname(__file__), '../data/rasters/raster.numpy.txt')
)
numpy.testing.assert_equal(data, assert_array)
self.assertEqual(data.shape, (self.band.height, self.band.width))

View File

@ -7,14 +7,13 @@ from django.contrib.gis.db.models.functions import (
)
from django.contrib.gis.geos import GEOSGeometry, LineString, Point, Polygon
from django.test import TestCase, skipUnlessDBFeature
from django.utils._os import upath
from .models import (
City3D, Interstate2D, Interstate3D, InterstateProj2D, InterstateProj3D,
MultiPoint3D, Point2D, Point3D, Polygon2D, Polygon3D,
)
data_path = os.path.realpath(os.path.join(os.path.dirname(upath(__file__)), '..', 'data'))
data_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'data'))
city_file = os.path.join(data_path, 'cities', 'cities.shp')
vrt_file = os.path.join(data_path, 'test_vrt', 'test_vrt.vrt')

View File

@ -10,7 +10,6 @@ from django.contrib.gis.measure import D
from django.db import connection
from django.db.models.functions import Cast
from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature
from django.utils._os import upath
from ..utils import oracle, postgis, spatialite
from .models import City, County, Zipcode
@ -66,7 +65,7 @@ class GeographyTest(TestCase):
from django.contrib.gis.utils import LayerMapping
# Getting the shapefile and mapping dictionary.
shp_path = os.path.realpath(os.path.join(os.path.dirname(upath(__file__)), '..', 'data'))
shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'data'))
co_shp = os.path.join(shp_path, 'counties', 'counties.shp')
co_mapping = {'name': 'Name',
'state': 'State',

View File

@ -8,7 +8,6 @@ from django.contrib.gis.gdal import HAS_GDAL
from django.contrib.gis.geos import HAS_GEOS
from django.db import connection
from django.test import TestCase, override_settings, skipUnlessDBFeature
from django.utils._os import upath
if HAS_GEOS and HAS_GDAL:
from django.contrib.gis.utils.layermapping import (
@ -23,7 +22,7 @@ if HAS_GEOS and HAS_GDAL:
)
shp_path = os.path.realpath(os.path.join(os.path.dirname(upath(__file__)), os.pardir, 'data'))
shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir, 'data'))
city_shp = os.path.join(shp_path, 'cities', 'cities.shp')
co_shp = os.path.join(shp_path, 'counties', 'counties.shp')
inter_shp = os.path.join(shp_path, 'interstates', 'interstates.shp')

View File

@ -5,11 +5,10 @@ for the GEOS and GDAL tests.
import json
import os
from django.utils._os import upath
from django.utils.functional import cached_property
# Path where reference test data is located.
TEST_DATA = os.path.join(os.path.dirname(upath(__file__)), 'data')
TEST_DATA = os.path.join(os.path.dirname(__file__), 'data')
def tuplize(seq):

View File

@ -16,7 +16,6 @@ from django.http import (
StreamingHttpResponse, parse_cookie,
)
from django.test import SimpleTestCase
from django.utils._os import upath
from django.utils.functional import lazystr
@ -634,7 +633,7 @@ class FileCloseTests(SimpleTestCase):
request_finished.connect(close_old_connections)
def test_response(self):
filename = os.path.join(os.path.dirname(upath(__file__)), 'abc.txt')
filename = os.path.join(os.path.dirname(__file__), 'abc.txt')
# file isn't closed until we close the response.
file1 = open(filename)
@ -652,7 +651,7 @@ class FileCloseTests(SimpleTestCase):
self.assertTrue(file2.closed)
def test_streaming_response(self):
filename = os.path.join(os.path.dirname(upath(__file__)), 'abc.txt')
filename = os.path.join(os.path.dirname(__file__), 'abc.txt')
# file isn't closed until we close the response.
file1 = open(filename)

View File

@ -3,13 +3,12 @@ import os
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase, override_settings
from django.utils import translation
from django.utils._os import upath
@override_settings(
USE_I18N=True,
LOCALE_PATHS=[
os.path.join(os.path.dirname(upath(__file__)), 'locale'),
os.path.join(os.path.dirname(__file__), 'locale'),
],
LANGUAGE_CODE='en',
LANGUAGES=[

View File

@ -10,7 +10,6 @@ from django.test.client import RequestFactory
from django.test.utils import override_script_prefix
from django.urls import clear_url_caches, reverse, translate_url
from django.utils import translation
from django.utils._os import upath
class PermanentRedirectLocaleMiddleWare(LocaleMiddleware):
@ -20,7 +19,7 @@ class PermanentRedirectLocaleMiddleWare(LocaleMiddleware):
@override_settings(
USE_I18N=True,
LOCALE_PATHS=[
os.path.join(os.path.dirname(upath(__file__)), 'locale'),
os.path.join(os.path.dirname(__file__), 'locale'),
],
LANGUAGE_CODE='en-us',
LANGUAGES=[
@ -35,7 +34,7 @@ class PermanentRedirectLocaleMiddleWare(LocaleMiddleware):
ROOT_URLCONF='i18n.patterns.urls.default',
TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(upath(__file__)), 'templates')],
'DIRS': [os.path.join(os.path.dirname(__file__), 'templates')],
'OPTIONS': {
'context_processors': [
'django.template.context_processors.i18n',

View File

@ -2,13 +2,12 @@ import os
from django.template import Context, Template
from django.test import SimpleTestCase, override_settings
from django.utils._os import upath
from django.utils.encoding import force_text
from django.utils.translation import activate, get_language, trans_real
from .utils import POFileAssertionMixin
SAMPLEPROJECT_DIR = os.path.join(os.path.dirname(os.path.abspath(upath(__file__))), 'sampleproject')
SAMPLEPROJECT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'sampleproject')
SAMPLEPROJECT_LOCALE = os.path.join(SAMPLEPROJECT_DIR, 'locale')

View File

@ -15,7 +15,6 @@ from django.test import (
RequestFactory, SimpleTestCase, TestCase, override_settings,
)
from django.utils import translation
from django.utils._os import upath
from django.utils.formats import (
date_format, get_format, get_format_modules, iter_format_modules, localize,
localize_input, reset_format_cache, sanitize_separators, time_format,
@ -32,7 +31,7 @@ from django.utils.translation import (
from .forms import CompanyForm, I18nForm, SelectDateForm
from .models import Company, TestModel
here = os.path.dirname(os.path.abspath(upath(__file__)))
here = os.path.dirname(os.path.abspath(__file__))
extended_locale_paths = settings.LOCALE_PATHS + [
os.path.join(here, 'other', 'locale'),
]

View File

@ -3,9 +3,7 @@ import re
import shutil
import tempfile
from django.utils._os import upath
source_code_dir = os.path.dirname(upath(__file__))
source_code_dir = os.path.dirname(__file__)
def copytree(src, dst):

View File

@ -25,7 +25,6 @@ from django.core.mail.backends import console, dummy, filebased, locmem, smtp
from django.core.mail.message import BadHeaderError, sanitize_address
from django.test import SimpleTestCase, override_settings
from django.test.utils import requires_tz_support
from django.utils._os import upath
from django.utils.encoding import force_bytes, force_text
from django.utils.translation import ugettext_lazy
@ -411,7 +410,7 @@ class MailTests(HeadersCheckMixin, SimpleTestCase):
email = EmailMessage('subject', 'body', 'from@example.com', ['to@example.com'])
self.assertEqual(mimetypes.guess_type(basename)[0], real_mimetype)
self.assertEqual(email.attachments, [])
file_path = os.path.join(os.path.dirname(upath(__file__)), 'attachments', basename)
file_path = os.path.join(os.path.dirname(__file__), 'attachments', basename)
email.attach_file(file_path, mimetype=mimetype)
self.assertEqual(len(email.attachments), 1)
self.assertIn(basename, email.attachments[0])

View File

@ -22,7 +22,6 @@ from django.db.migrations.writer import (
)
from django.test import SimpleTestCase, ignore_warnings, mock
from django.utils import datetime_safe
from django.utils._os import upath
from django.utils.deconstruct import deconstructible
from django.utils.functional import SimpleLazyObject
from django.utils.timezone import FixedOffset, get_default_timezone, utc
@ -576,7 +575,7 @@ class WriterTests(SimpleTestCase):
'migrations.migrations_test_apps.without_init_file',
]
base_dir = os.path.dirname(os.path.dirname(upath(__file__)))
base_dir = os.path.dirname(os.path.dirname(__file__))
for app in test_apps:
with self.modify_settings(INSTALLED_APPS={'append': app}):

View File

@ -7,7 +7,6 @@ from django.core.files import File
from django.core.files.images import ImageFile
from django.test import TestCase
from django.test.testcases import SerializeMixin
from django.utils._os import upath
try:
from .models import Image
@ -51,10 +50,10 @@ class ImageFieldTestMixin(SerializeMixin):
shutil.rmtree(temp_storage_dir)
os.mkdir(temp_storage_dir)
file_path1 = os.path.join(os.path.dirname(upath(__file__)), "4x8.png")
file_path1 = os.path.join(os.path.dirname(__file__), '4x8.png')
self.file1 = self.File(open(file_path1, 'rb'), name='4x8.png')
file_path2 = os.path.join(os.path.dirname(upath(__file__)), "8x4.png")
file_path2 = os.path.join(os.path.dirname(__file__), '8x4.png')
self.file2 = self.File(open(file_path2, 'rb'), name='8x4.png')
def tearDown(self):

View File

@ -15,7 +15,6 @@ from django.core import validators
from django.core.exceptions import ValidationError
from django.core.files.storage import FileSystemStorage
from django.db import models
from django.utils._os import upath
temp_storage_dir = tempfile.mkdtemp()
temp_storage = FileSystemStorage(temp_storage_dir)
@ -160,7 +159,7 @@ class CustomFF(models.Model):
class FilePathModel(models.Model):
path = models.FilePathField(path=os.path.dirname(upath(__file__)), match=r".*\.py$", blank=True)
path = models.FilePathField(path=os.path.dirname(__file__), match=r".*\.py$", blank=True)
try:

View File

@ -17,7 +17,6 @@ from django.forms.models import (
)
from django.template import Context, Template
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
from django.utils._os import upath
from .models import (
Article, ArticleStatus, Author, Author1, Award, BetterWriter, BigInt, Book,
@ -2221,7 +2220,7 @@ class FileAndImageFieldTests(TestCase):
fields = '__all__'
# Grab an image for testing.
filename = os.path.join(os.path.dirname(upath(__file__)), "test.png")
filename = os.path.join(os.path.dirname(__file__), 'test.png')
with open(filename, "rb") as fp:
img = fp.read()
@ -2260,9 +2259,9 @@ class FileAndImageFieldTests(TestCase):
# it comes to validation. This specifically tests that #6302 is fixed for
# both file fields and image fields.
with open(os.path.join(os.path.dirname(upath(__file__)), "test.png"), 'rb') as fp:
with open(os.path.join(os.path.dirname(__file__), 'test.png'), 'rb') as fp:
image_data = fp.read()
with open(os.path.join(os.path.dirname(upath(__file__)), "test2.png"), 'rb') as fp:
with open(os.path.join(os.path.dirname(__file__), 'test2.png'), 'rb') as fp:
image_data2 = fp.read()
f = ImageFileForm(

View File

@ -3,14 +3,13 @@ import shutil
from django import conf
from django.test import TestCase
from django.utils._os import upath
class TestStartProjectSettings(TestCase):
def setUp(self):
# Ensure settings.py exists
project_dir = os.path.join(
os.path.dirname(upath(conf.__file__)),
os.path.dirname(conf.__file__),
'project_template',
'project_name',
)

View File

@ -3,7 +3,6 @@ import os
from django.core.management import call_command
from django.test import TestCase, TransactionTestCase
from django.test.utils import extend_sys_path
from django.utils._os import upath
from .models import (
ConcreteModel, ConcreteModelSubclass, ConcreteModelSubclassProxy,
@ -20,7 +19,7 @@ class ProxyModelInheritanceTests(TransactionTestCase):
available_apps = []
def test_table_exists(self):
with extend_sys_path(os.path.dirname(os.path.abspath(upath(__file__)))):
with extend_sys_path(os.path.dirname(os.path.abspath(__file__))):
with self.modify_settings(INSTALLED_APPS={'append': ['app1', 'app2']}):
call_command('migrate', verbosity=0, run_syncdb=True)
from app1.models import ProxyModel

View File

@ -17,7 +17,6 @@ from django.test import TestCase, TransactionTestCase
from django.test.runner import default_test_processes
from django.test.selenium import SeleniumTestCaseBase
from django.test.utils import get_runner
from django.utils._os import upath
from django.utils.deprecation import (
RemovedInDjango21Warning, RemovedInDjango30Warning,
)
@ -31,7 +30,7 @@ warnings.simplefilter("error", RuntimeWarning)
# Ignore known warnings in test dependencies.
warnings.filterwarnings("ignore", "'U' mode is deprecated", DeprecationWarning, module='docutils.io')
RUNTESTS_DIR = os.path.abspath(os.path.dirname(upath(__file__)))
RUNTESTS_DIR = os.path.abspath(os.path.dirname(__file__))
TEMPLATE_DIR = os.path.join(RUNTESTS_DIR, 'templates')
@ -276,7 +275,7 @@ def django_tests(verbosity, interactive, failfast, keepdb, reverse,
def get_subprocess_args(options):
subprocess_args = [
sys.executable, upath(__file__), '--settings=%s' % options.settings
sys.executable, __file__, '--settings=%s' % options.settings
]
if options.failfast:
subprocess_args.append('--failfast')

View File

@ -8,12 +8,11 @@ from urllib.error import HTTPError
from urllib.request import urlopen
from django.test import LiveServerTestCase, override_settings
from django.utils._os import upath
from django.utils.http import urlencode
from .models import Person
TEST_ROOT = os.path.dirname(upath(__file__))
TEST_ROOT = os.path.dirname(__file__)
TEST_SETTINGS = {
'MEDIA_URL': '/media/',
'MEDIA_ROOT': os.path.join(TEST_ROOT, 'media'),

View File

@ -8,7 +8,6 @@ from django.contrib.sitemaps import GenericSitemap, Sitemap
from django.contrib.sites.models import Site
from django.core.exceptions import ImproperlyConfigured
from django.test import modify_settings, override_settings
from django.utils._os import upath
from django.utils.formats import localize
from django.utils.translation import activate, deactivate
@ -30,7 +29,7 @@ class HTTPSitemapTests(SitemapTestsBase):
@override_settings(TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(upath(__file__)), 'templates')],
'DIRS': [os.path.join(os.path.dirname(__file__), 'templates')],
}])
def test_simple_sitemap_custom_index(self):
"A simple sitemap index can be rendered with a custom template"
@ -65,7 +64,7 @@ class HTTPSitemapTests(SitemapTestsBase):
@override_settings(TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(upath(__file__)), 'templates')],
'DIRS': [os.path.join(os.path.dirname(__file__), 'templates')],
}])
def test_simple_custom_sitemap(self):
"A simple sitemap can be rendered with a custom template"

View File

@ -1,8 +1,6 @@
import os.path
from django.utils._os import upath
TEST_ROOT = os.path.dirname(upath(__file__))
TEST_ROOT = os.path.dirname(__file__)
TEST_SETTINGS = {
'MEDIA_URL': '/media/',

View File

@ -10,9 +10,8 @@ from urllib.request import urlopen
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from django.core.exceptions import ImproperlyConfigured
from django.test import modify_settings, override_settings
from django.utils._os import upath
TEST_ROOT = os.path.dirname(upath(__file__))
TEST_ROOT = os.path.dirname(__file__)
TEST_SETTINGS = {
'MEDIA_URL': '/media/',
'STATIC_URL': '/static/',

View File

@ -2,10 +2,9 @@ import os
from django.conf import settings
from django.test import SimpleTestCase
from django.utils._os import upath
from django.utils.translation import activate, get_language
here = os.path.dirname(os.path.dirname(os.path.abspath(upath(__file__))))
here = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
pdir = os.path.split(os.path.split(os.path.abspath(here))[0])[0]
extended_locale_paths = settings.LOCALE_PATHS + [
os.path.join(pdir, 'i18n', 'other', 'locale'),

View File

@ -3,10 +3,9 @@ import os
from django.template.engine import Engine
from django.test.utils import override_settings
from django.utils._os import upath
from django.utils.safestring import mark_safe
ROOT = os.path.dirname(os.path.abspath(upath(__file__)))
ROOT = os.path.dirname(os.path.abspath(__file__))
TEMPLATE_DIR = os.path.join(ROOT, 'templates')

View File

@ -17,7 +17,6 @@ from django.test import (
from django.test.client import RedirectCycleError, RequestFactory, encode_file
from django.test.utils import ContextList, str_prefix
from django.urls import NoReverseMatch, reverse
from django.utils._os import upath
from django.utils.translation import ugettext_lazy
from .models import CustomUser
@ -874,7 +873,7 @@ class TemplateExceptionTests(SimpleTestCase):
@override_settings(TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(os.path.dirname(upath(__file__)), 'bad_templates')],
'DIRS': [os.path.join(os.path.dirname(__file__), 'bad_templates')],
}])
def test_bad_404_template(self):
"Errors found when rendering 404 error templates are re-raised"

View File

@ -1,3 +1,4 @@
import os
import sys
import unittest
from io import StringIO
@ -19,7 +20,6 @@ from django.test.utils import (
setup_test_environment,
)
from django.urls import NoReverseMatch, reverse
from django.utils._os import abspathu
from .models import Car, Person, PossessedCar
from .views import empty_response
@ -968,7 +968,7 @@ class OverrideSettingsTests(SimpleTestCase):
django.contrib.staticfiles.storage.staticfiles_storage.
"""
with self.settings(STATIC_ROOT='/tmp/test'):
self.assertEqual(staticfiles_storage.location, abspathu('/tmp/test'))
self.assertEqual(staticfiles_storage.location, os.path.abspath('/tmp/test'))
def test_override_staticfiles_storage(self):
"""

View File

@ -5,9 +5,8 @@ from django.test import SimpleTestCase, mock, override_settings
from django.urls import LocaleRegexProvider
from django.urls.resolvers import LocaleRegexDescriptor
from django.utils import translation
from django.utils._os import upath
here = os.path.dirname(upath(os.path.abspath(__file__)))
here = os.path.dirname(os.path.abspath(__file__))
@override_settings(LOCALE_PATHS=[os.path.join(here, 'translations', 'locale')])

View File

@ -11,7 +11,6 @@ from django.db import connection
from django.test import SimpleTestCase, mock, override_settings
from django.test.utils import captured_stderr, extend_sys_path
from django.utils import translation
from django.utils._os import upath
from .management.commands import dance
@ -92,7 +91,7 @@ class CommandTests(SimpleTestCase):
"""
Management commands can also be loaded from Python eggs.
"""
egg_dir = '%s/eggs' % os.path.dirname(upath(__file__))
egg_dir = '%s/eggs' % os.path.dirname(__file__)
egg_name = '%s/basic.egg' % egg_dir
with extend_sys_path(egg_name):
with self.settings(INSTALLED_APPS=['commandegg']):

View File

@ -5,10 +5,9 @@ import sys
import tempfile
import unittest
from django.utils._os import upath
from django.utils.archive import Archive, extract
TEST_DIR = os.path.join(os.path.dirname(upath(__file__)), 'archives')
TEST_DIR = os.path.join(os.path.dirname(__file__), 'archives')
class ArchiveTester:

View File

@ -11,7 +11,6 @@ from django.contrib import admin
from django.test import SimpleTestCase, mock, override_settings
from django.test.utils import extend_sys_path
from django.utils import autoreload
from django.utils._os import npath
from django.utils.translation import trans_real
LOCALE_PATH = os.path.join(os.path.dirname(__file__), 'locale')
@ -26,23 +25,23 @@ class TestFilenameGenerator(SimpleTestCase):
def assertFileFound(self, filename):
self.clear_autoreload_caches()
# Test uncached access
self.assertIn(npath(filename), autoreload.gen_filenames())
self.assertIn(filename, autoreload.gen_filenames())
# Test cached access
self.assertIn(npath(filename), autoreload.gen_filenames())
self.assertIn(filename, autoreload.gen_filenames())
def assertFileNotFound(self, filename):
self.clear_autoreload_caches()
# Test uncached access
self.assertNotIn(npath(filename), autoreload.gen_filenames())
self.assertNotIn(filename, autoreload.gen_filenames())
# Test cached access
self.assertNotIn(npath(filename), autoreload.gen_filenames())
self.assertNotIn(filename, autoreload.gen_filenames())
def assertFileFoundOnlyNew(self, filename):
self.clear_autoreload_caches()
# Test uncached access
self.assertIn(npath(filename), autoreload.gen_filenames(only_new=True))
self.assertIn(filename, autoreload.gen_filenames(only_new=True))
# Test cached access
self.assertNotIn(npath(filename), autoreload.gen_filenames(only_new=True))
self.assertNotIn(filename, autoreload.gen_filenames(only_new=True))
def test_django_locales(self):
"""
@ -122,7 +121,7 @@ class TestFilenameGenerator(SimpleTestCase):
with extend_sys_path(dirname):
import_module('test_only_new_module')
filenames = set(autoreload.gen_filenames(only_new=True))
self.assertEqual(filenames, {npath(filename)})
self.assertEqual(filenames, {filename})
def test_deleted_removed(self):
"""

View File

@ -3,7 +3,6 @@ from datetime import datetime
from django.test import SimpleTestCase
from django.utils import html, safestring
from django.utils._os import upath
from django.utils.encoding import force_text
from django.utils.functional import lazystr
@ -98,7 +97,7 @@ class TestUtilsHtml(SimpleTestCase):
# Test with more lengthy content (also catching performance regressions)
for filename in ('strip_tags1.html', 'strip_tags2.txt'):
path = os.path.join(os.path.dirname(upath(__file__)), 'files', filename)
path = os.path.join(os.path.dirname(__file__), 'files', filename)
with open(path, 'r') as fp:
content = force_text(fp.read())
start = datetime.now()

View File

@ -7,7 +7,6 @@ from zipimport import zipimporter
from django.test import SimpleTestCase, TestCase, modify_settings
from django.test.utils import extend_sys_path
from django.utils._os import upath
from django.utils.module_loading import (
autodiscover_modules, import_string, module_has_submodule,
)
@ -58,7 +57,7 @@ class DefaultLoader(unittest.TestCase):
class EggLoader(unittest.TestCase):
def setUp(self):
self.egg_dir = '%s/eggs' % os.path.dirname(upath(__file__))
self.egg_dir = '%s/eggs' % os.path.dirname(__file__)
def tearDown(self):
sys.path_importer_cache.clear()

View File

@ -17,7 +17,6 @@ from django.core.validators import (
)
from django.test import SimpleTestCase
from django.test.utils import str_prefix
from django.utils._os import upath
try:
from PIL import Image # noqa
@ -263,7 +262,7 @@ TEST_DATA = [
def create_path(filename):
return os.path.abspath(os.path.join(os.path.dirname(upath(__file__)), filename))
return os.path.abspath(os.path.join(os.path.dirname(__file__), filename))
# Add valid and invalid URL tests.

View File

@ -8,7 +8,6 @@ from django.test import (
)
from django.test.selenium import SeleniumTestCase
from django.urls import reverse
from django.utils._os import upath
from django.utils.translation import (
LANGUAGE_SESSION_KEY, get_language, override,
)
@ -373,7 +372,7 @@ class JsI18NTestsMultiPackage(SimpleTestCase):
def test_i18n_with_locale_paths(self):
extended_locale_paths = settings.LOCALE_PATHS + [
path.join(
path.dirname(path.dirname(path.abspath(upath(__file__)))),
path.dirname(path.dirname(path.abspath(__file__))),
'app3',
'locale',
),

View File

@ -3,13 +3,12 @@ from os import path
from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
from django.utils._os import upath
from django.utils.translation import ugettext_lazy as _
from django.views import defaults, i18n, static
from . import views
base_dir = path.dirname(path.abspath(upath(__file__)))
base_dir = path.dirname(path.abspath(__file__))
media_dir = path.join(base_dir, 'media')
locale_dir = path.join(base_dir, 'locale')