-
diff --git a/django/contrib/auth/tests/context_processors.py b/django/contrib/auth/tests/context_processors.py
index 32fea8a..42bed4d 100644
a
|
b
|
class PermWrapperTests(TestCase):
|
63 | 63 | @skipIfCustomUser |
64 | 64 | @override_settings( |
65 | 65 | TEMPLATE_DIRS=( |
66 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 66 | os.path.join(os.path.dirname(__file__), str('templates')), |
67 | 67 | ), |
68 | 68 | USE_TZ=False, # required for loading the fixture |
69 | 69 | PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',), |
… |
… |
class AuthContextProcessorTests(TestCase):
|
110 | 110 | self.assertContains(response, "Has auth permissions") |
111 | 111 | self.assertContains(response, "Has auth.add_permission permissions") |
112 | 112 | self.assertNotContains(response, "nonexisting") |
113 | | |
| 113 | |
114 | 114 | def test_perm_in_perms_attrs(self): |
115 | 115 | u = User.objects.create_user(username='normal', password='secret') |
116 | 116 | u.user_permissions.add( |
-
diff --git a/django/contrib/auth/tests/forms.py b/django/contrib/auth/tests/forms.py
index f3eb242..674d78e 100644
a
|
b
|
class PasswordResetFormTest(TestCase):
|
322 | 322 | self.assertEqual(form.cleaned_data['email'], email) |
323 | 323 | |
324 | 324 | def test_custom_email_subject(self): |
325 | | template_path = os.path.join(os.path.dirname(__file__), 'templates') |
| 325 | template_path = os.path.join(os.path.dirname(__file__), str('templates')) |
326 | 326 | with self.settings(TEMPLATE_DIRS=(template_path,)): |
327 | 327 | data = {'email': 'testclient@example.com'} |
328 | 328 | form = PasswordResetForm(data) |
-
diff --git a/django/contrib/auth/tests/views.py b/django/contrib/auth/tests/views.py
index b97d4a7..5c1e995 100644
a
|
b
|
from django.contrib.auth.tests.utils import skipIfCustomUser
|
27 | 27 | LANGUAGE_CODE='en', |
28 | 28 | TEMPLATE_LOADERS=global_settings.TEMPLATE_LOADERS, |
29 | 29 | TEMPLATE_DIRS=( |
30 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 30 | os.path.join(os.path.dirname(__file__), str('templates')), |
31 | 31 | ), |
32 | 32 | USE_TZ=False, |
33 | 33 | PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',), |
-
diff --git a/django/contrib/flatpages/tests/csrf.py b/django/contrib/flatpages/tests/csrf.py
index e64c4bb..b1a74d9 100644
a
|
b
|
from django.test.utils import override_settings
|
16 | 16 | 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', |
17 | 17 | ), |
18 | 18 | TEMPLATE_DIRS=( |
19 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 19 | os.path.join(os.path.dirname(__file__), str('templates')), |
20 | 20 | ), |
21 | 21 | SITE_ID=1, |
22 | 22 | ) |
-
diff --git a/django/contrib/flatpages/tests/middleware.py b/django/contrib/flatpages/tests/middleware.py
index 4afa4ff..588b94b 100644
a
|
b
|
from django.test.utils import override_settings
|
17 | 17 | 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', |
18 | 18 | ), |
19 | 19 | TEMPLATE_DIRS=( |
20 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 20 | os.path.join(os.path.dirname(__file__), str('templates')), |
21 | 21 | ), |
22 | 22 | SITE_ID=1, |
23 | 23 | ) |
… |
… |
class FlatpageMiddlewareTests(TestCase):
|
95 | 95 | 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', |
96 | 96 | ), |
97 | 97 | TEMPLATE_DIRS=( |
98 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 98 | os.path.join(os.path.dirname(__file__), str('templates')), |
99 | 99 | ), |
100 | 100 | SITE_ID=1, |
101 | 101 | ) |
-
diff --git a/django/contrib/flatpages/tests/templatetags.py b/django/contrib/flatpages/tests/templatetags.py
index aebc622..2fe2263 100644
a
|
b
|
from django.test.utils import override_settings
|
16 | 16 | 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', |
17 | 17 | ), |
18 | 18 | TEMPLATE_DIRS=( |
19 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 19 | os.path.join(os.path.dirname(__file__), str('templates')), |
20 | 20 | ), |
21 | 21 | SITE_ID=1, |
22 | 22 | ) |
-
diff --git a/django/contrib/flatpages/tests/views.py b/django/contrib/flatpages/tests/views.py
index b69bd6a..88204ae 100644
a
|
b
|
from django.test.utils import override_settings
|
17 | 17 | # no 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware' |
18 | 18 | ), |
19 | 19 | TEMPLATE_DIRS=( |
20 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 20 | os.path.join(os.path.dirname(__file__), str('templates')), |
21 | 21 | ), |
22 | 22 | SITE_ID=1, |
23 | 23 | ) |
… |
… |
class FlatpageViewTests(TestCase):
|
84 | 84 | # no 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware' |
85 | 85 | ), |
86 | 86 | TEMPLATE_DIRS=( |
87 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 87 | os.path.join(os.path.dirname(__file__), str('templates')), |
88 | 88 | ), |
89 | 89 | SITE_ID=1, |
90 | 90 | ) |
-
diff --git a/django/contrib/formtools/tests/__init__.py b/django/contrib/formtools/tests/__init__.py
index a21ffde..9a989fc 100644
a
|
b
|
class TestFormPreview(preview.FormPreview):
|
36 | 36 | |
37 | 37 | @override_settings( |
38 | 38 | TEMPLATE_DIRS=( |
39 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 39 | os.path.join(os.path.dirname(__file__), str('templates')), |
40 | 40 | ), |
41 | 41 | ) |
42 | 42 | class PreviewTests(TestCase): |
… |
… |
class DummyRequest(http.HttpRequest):
|
214 | 214 | @override_settings( |
215 | 215 | SECRET_KEY="123", |
216 | 216 | TEMPLATE_DIRS=( |
217 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 217 | os.path.join(os.path.dirname(__file__), str('templates')), |
218 | 218 | ), |
219 | 219 | ) |
220 | 220 | class WizardTests(TestCase): |
-
diff --git a/django/contrib/formtools/tests/wizard/wizardtests/tests.py b/django/contrib/formtools/tests/wizard/wizardtests/tests.py
index 6403a55..a0ba123 100644
a
|
b
|
class WizardTests(object):
|
74 | 74 | |
75 | 75 | # ticket #19025: `form` should be included in context |
76 | 76 | form = response.context_data['wizard']['form'] |
77 | | self.assertEqual(response.context_data['form'], form) |
| 77 | self.assertEqual(response.context_data['form'], form) |
78 | 78 | |
79 | 79 | def test_form_finish(self): |
80 | 80 | response = self.client.get(self.wizard_url) |
… |
… |
class WizardTestKwargs(TestCase):
|
291 | 291 | self.wizard_step_data[0]['form1-user'] = self.testuser.pk |
292 | 292 | |
293 | 293 | def test_template(self): |
294 | | templates = os.path.join(os.path.dirname(__file__), 'templates') |
| 294 | templates = os.path.join(os.path.dirname(__file__), str('templates')) |
295 | 295 | with self.settings( |
296 | 296 | TEMPLATE_DIRS=list(settings.TEMPLATE_DIRS) + [templates]): |
297 | 297 | response = self.client.get(self.wizard_url) |
-
diff --git a/django/contrib/gis/tests/geo3d/tests.py b/django/contrib/gis/tests/geo3d/tests.py
index f7590fe..e8193a3 100644
a
|
b
|
from .models import (City3D, Interstate2D, Interstate3D, InterstateProj2D,
|
12 | 12 | InterstateProj3D, Point2D, Point3D, MultiPoint3D, Polygon2D, Polygon3D) |
13 | 13 | |
14 | 14 | |
15 | | data_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'data')) |
16 | | city_file = os.path.join(data_path, 'cities', 'cities.shp') |
17 | | vrt_file = os.path.join(data_path, 'test_vrt', 'test_vrt.vrt') |
| 15 | data_path = os.path.realpath(os.path.join(os.path.dirname(__file__), str('..'), str('data'))) |
| 16 | city_file = os.path.join(data_path, str('cities'), str('cities.shp')) |
| 17 | vrt_file = os.path.join(data_path, str('test_vrt'), str('test_vrt.vrt')) |
18 | 18 | |
19 | 19 | # The coordinates of each city, with Z values corresponding to their |
20 | 20 | # altitude in meters. |
-
diff --git a/django/contrib/gis/tests/geogapp/tests.py b/django/contrib/gis/tests/geogapp/tests.py
index 2fd3560..efcd51a 100644
a
|
b
|
class GeographyTest(TestCase):
|
61 | 61 | from django.contrib.gis.utils import LayerMapping |
62 | 62 | |
63 | 63 | # Getting the shapefile and mapping dictionary. |
64 | | shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), '..', 'data')) |
65 | | co_shp = os.path.join(shp_path, 'counties', 'counties.shp') |
| 64 | shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), str('..'), str('data'))) |
| 65 | co_shp = os.path.join(shp_path, str('counties'), str('counties.shp')) |
66 | 66 | co_mapping = {'name' : 'Name', |
67 | 67 | 'state' : 'State', |
68 | 68 | 'mpoly' : 'MULTIPOLYGON', |
-
diff --git a/django/contrib/gis/tests/layermap/tests.py b/django/contrib/gis/tests/layermap/tests.py
index a976954..6fd0e46 100644
a
|
b
|
from .models import (
|
19 | 19 | city_mapping, co_mapping, cofeat_mapping, inter_mapping) |
20 | 20 | |
21 | 21 | |
22 | | shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir, 'data')) |
23 | | city_shp = os.path.join(shp_path, 'cities', 'cities.shp') |
24 | | co_shp = os.path.join(shp_path, 'counties', 'counties.shp') |
25 | | inter_shp = os.path.join(shp_path, 'interstates', 'interstates.shp') |
26 | | invalid_shp = os.path.join(shp_path, 'invalid', 'emptypoints.shp') |
| 22 | shp_path = os.path.realpath(os.path.join(os.path.dirname(__file__), os.pardir, str('data'))) |
| 23 | city_shp = os.path.join(shp_path, str('cities'), str('cities.shp')) |
| 24 | co_shp = os.path.join(shp_path, str('counties'), str('counties.shp')) |
| 25 | inter_shp = os.path.join(shp_path, str('interstates'), str('interstates.shp')) |
| 26 | invalid_shp = os.path.join(shp_path, str('invalid'), str('emptypoints.shp')) |
27 | 27 | |
28 | 28 | # Dictionaries to hold what's expected in the county shapefile. |
29 | 29 | NAMES = ['Bexar', 'Galveston', 'Harris', 'Honolulu', 'Pueblo'] |
-
diff --git a/django/contrib/sitemaps/tests/http.py b/django/contrib/sitemaps/tests/http.py
index 99042fe..75c869f 100644
a
|
b
|
class HTTPSitemapTests(SitemapTestsBase):
|
29 | 29 | self.assertXMLEqual(response.content.decode('utf-8'), expected_content) |
30 | 30 | |
31 | 31 | @override_settings( |
32 | | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),) |
| 32 | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), str('templates')),) |
33 | 33 | ) |
34 | 34 | def test_simple_sitemap_custom_index(self): |
35 | 35 | "A simple sitemap index can be rendered with a custom template" |
… |
… |
class HTTPSitemapTests(SitemapTestsBase):
|
64 | 64 | self.assertXMLEqual(response.content.decode('utf-8'), expected_content) |
65 | 65 | |
66 | 66 | @override_settings( |
67 | | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),) |
| 67 | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), str('templates')),) |
68 | 68 | ) |
69 | 69 | def test_simple_custom_sitemap(self): |
70 | 70 | "A simple sitemap can be rendered with a custom template" |
-
diff --git a/django/contrib/staticfiles/storage.py b/django/contrib/staticfiles/storage.py
index 9691b78..507ad1f 100644
a
|
b
|
class CachedFilesMixin(object):
|
106 | 106 | path, filename = os.path.split(clean_name) |
107 | 107 | root, ext = os.path.splitext(filename) |
108 | 108 | if file_hash is not None: |
109 | | file_hash = ".%s" % file_hash |
110 | | hashed_name = os.path.join(path, "%s%s%s" % |
| 109 | file_hash = str(".%s") % file_hash |
| 110 | hashed_name = os.path.join(path, str("%s%s%s") % |
111 | 111 | (root, file_hash, ext)) |
112 | 112 | unparsed_name = list(parsed_name) |
113 | 113 | unparsed_name[2] = hashed_name |
… |
… |
class AppStaticStorage(FileSystemStorage):
|
288 | 288 | for the ``static`` directory of it. |
289 | 289 | """ |
290 | 290 | prefix = None |
291 | | source_dir = 'static' |
| 291 | source_dir = str('static') |
292 | 292 | |
293 | 293 | def __init__(self, app, *args, **kwargs): |
294 | 294 | """ |
-
diff --git a/django/core/management/commands/compilemessages.py b/django/core/management/commands/compilemessages.py
index b7392b9..32de139 100644
a
|
b
|
def has_bom(fn):
|
14 | 14 | sample.startswith(codecs.BOM_UTF16_BE) |
15 | 15 | |
16 | 16 | def compile_messages(stderr, locale=None): |
17 | | basedirs = [os.path.join('conf', 'locale'), 'locale'] |
| 17 | basedirs = [os.path.join(str('conf'), str('locale')), str('locale')] |
18 | 18 | if os.environ.get('DJANGO_SETTINGS_MODULE'): |
19 | 19 | from django.conf import settings |
20 | 20 | basedirs.extend(settings.LOCALE_PATHS) |
… |
… |
def compile_messages(stderr, locale=None):
|
27 | 27 | |
28 | 28 | for basedir in basedirs: |
29 | 29 | if locale: |
30 | | basedir = os.path.join(basedir, locale, 'LC_MESSAGES') |
| 30 | basedir = os.path.join(basedir, locale, str('LC_MESSAGES')) |
31 | 31 | for dirpath, dirnames, filenames in os.walk(basedir): |
32 | 32 | for f in filenames: |
33 | 33 | if f.endswith('.po'): |
34 | | stderr.write('processing file %s in %s\n' % (f, dirpath)) |
| 34 | stderr.write(str('processing file %s in %s\n') % (f, dirpath)) |
35 | 35 | fn = os.path.join(dirpath, f) |
36 | 36 | if has_bom(fn): |
37 | | raise CommandError("The %s file has a BOM (Byte Order Mark). Django only supports .po files encoded in UTF-8 and without any BOM." % fn) |
| 37 | raise CommandError(str("The %s file has a BOM (Byte Order Mark). " |
| 38 | "Django only supports .po files encoded in UTF-8 and without any BOM.") % fn) |
38 | 39 | pf = os.path.splitext(fn)[0] |
39 | 40 | # Store the names of the .mo and .po files in an environment |
40 | 41 | # variable, rather than doing a string replacement into the |
41 | 42 | # command, so that we can take advantage of shell quoting, to |
42 | 43 | # quote any malicious characters/escaping. |
43 | 44 | # See http://cyberelk.net/tim/articles/cmdline/ar01s02.html |
44 | | os.environ['djangocompilemo'] = pf + '.mo' |
45 | | os.environ['djangocompilepo'] = pf + '.po' |
| 45 | os.environ['djangocompilemo'] = pf + str('.mo') |
| 46 | os.environ['djangocompilepo'] = pf + str('.po') |
46 | 47 | if sys.platform == 'win32': # Different shell-variable syntax |
47 | 48 | cmd = 'msgfmt --check-format -o "%djangocompilemo%" "%djangocompilepo%"' |
48 | 49 | else: |
-
diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py
index f6f1b10..402485f 100644
a
|
b
|
from django.core.management.color import no_style
|
12 | 12 | from django.db import (connections, router, transaction, DEFAULT_DB_ALIAS, |
13 | 13 | IntegrityError, DatabaseError) |
14 | 14 | from django.db.models import get_apps |
15 | | from django.utils.encoding import force_text |
| 15 | from django.utils._os import path_as_str |
| 16 | from django.utils.encoding import force_str, force_text |
16 | 17 | from itertools import product |
17 | 18 | |
18 | 19 | try: |
… |
… |
class Command(BaseCommand):
|
43 | 44 | connection = connections[self.using] |
44 | 45 | |
45 | 46 | if not len(fixture_labels): |
46 | | raise CommandError( |
| 47 | raise CommandError(str( |
47 | 48 | "No database fixture specified. Please provide the path of at " |
48 | 49 | "least one fixture in the command line." |
49 | | ) |
| 50 | )) |
50 | 51 | |
51 | 52 | self.verbosity = int(options.get('verbosity')) |
52 | 53 | |
… |
… |
class Command(BaseCommand):
|
86 | 87 | |
87 | 88 | self.compression_types = { |
88 | 89 | None: open, |
89 | | 'gz': gzip.GzipFile, |
90 | | 'zip': SingleZipReader |
| 90 | str('gz'): gzip.GzipFile, |
| 91 | str('zip'): SingleZipReader |
91 | 92 | } |
92 | 93 | if has_bz2: |
93 | | self.compression_types['bz2'] = bz2.BZ2File |
| 94 | self.compression_types[str('bz2')] = bz2.BZ2File |
94 | 95 | |
95 | 96 | app_module_paths = [] |
96 | 97 | for app in get_apps(): |
… |
… |
class Command(BaseCommand):
|
102 | 103 | # It's a models.py module |
103 | 104 | app_module_paths.append(app.__file__) |
104 | 105 | |
105 | | app_fixtures = [os.path.join(os.path.dirname(path), 'fixtures') for path in app_module_paths] |
| 106 | app_fixtures = [os.path.join(os.path.dirname(path), str('fixtures')) for path in app_module_paths] |
106 | 107 | |
107 | 108 | try: |
108 | 109 | with connection.constraint_checks_disabled(): |
… |
… |
class Command(BaseCommand):
|
132 | 133 | sequence_sql = connection.ops.sequence_reset_sql(no_style(), self.models) |
133 | 134 | if sequence_sql: |
134 | 135 | if self.verbosity >= 2: |
135 | | self.stdout.write("Resetting sequences\n") |
| 136 | self.stdout.write(str("Resetting sequences\n")) |
136 | 137 | for line in sequence_sql: |
137 | 138 | cursor.execute(line) |
138 | 139 | |
… |
… |
class Command(BaseCommand):
|
142 | 143 | |
143 | 144 | if self.verbosity >= 1: |
144 | 145 | if self.fixture_object_count == self.loaded_object_count: |
145 | | self.stdout.write("Installed %d object(s) from %d fixture(s)" % ( |
| 146 | self.stdout.write(str("Installed %d object(s) from %d fixture(s)") % ( |
146 | 147 | self.loaded_object_count, self.fixture_count)) |
147 | 148 | else: |
148 | | self.stdout.write("Installed %d object(s) (of %d) from %d fixture(s)" % ( |
| 149 | self.stdout.write(str("Installed %d object(s) (of %d) from %d fixture(s)") % ( |
149 | 150 | self.loaded_object_count, self.fixture_object_count, self.fixture_count)) |
150 | 151 | |
151 | 152 | # Close the DB connection. This is required as a workaround for an |
… |
… |
class Command(BaseCommand):
|
157 | 158 | |
158 | 159 | def load_label(self, fixture_label, app_fixtures): |
159 | 160 | |
160 | | parts = fixture_label.split('.') |
| 161 | parts = force_str(fixture_label).split(str('.')) |
161 | 162 | |
162 | 163 | if len(parts) > 1 and parts[-1] in self.compression_types: |
163 | 164 | compression_formats = [parts[-1]] |
… |
… |
class Command(BaseCommand):
|
169 | 170 | fixture_name = parts[0] |
170 | 171 | formats = serializers.get_public_serializer_formats() |
171 | 172 | else: |
172 | | fixture_name, format = '.'.join(parts[:-1]), parts[-1] |
| 173 | fixture_name, format = str('.').join(parts[:-1]), parts[-1] |
173 | 174 | if format in serializers.get_public_serializer_formats(): |
174 | 175 | formats = [format] |
175 | 176 | else: |
… |
… |
class Command(BaseCommand):
|
177 | 178 | |
178 | 179 | if formats: |
179 | 180 | if self.verbosity >= 2: |
180 | | self.stdout.write("Loading '%s' fixtures..." % fixture_name) |
| 181 | self.stdout.write(str("Loading '%s' fixtures...") % fixture_name) |
181 | 182 | else: |
182 | | raise CommandError( |
183 | | "Problem installing fixture '%s': %s is not a known serialization format." % |
| 183 | raise CommandError(str( |
| 184 | "Problem installing fixture '%s': %s is not a known serialization format.") % |
184 | 185 | (fixture_name, format)) |
185 | 186 | |
186 | 187 | if os.path.isabs(fixture_name): |
… |
… |
class Command(BaseCommand):
|
195 | 196 | def process_dir(self, fixture_dir, fixture_name, compression_formats, |
196 | 197 | serialization_formats): |
197 | 198 | |
198 | | humanize = lambda dirname: "'%s'" % dirname if dirname else 'absolute path' |
| 199 | humanize = lambda dirname: str("'%s'") % path_as_str(dirname) if dirname else str('absolute path') |
199 | 200 | |
200 | 201 | if self.verbosity >= 2: |
201 | | self.stdout.write("Checking %s for fixtures..." % humanize(fixture_dir)) |
| 202 | self.stdout.write(str("Checking %s for fixtures...") % humanize(fixture_dir)) |
202 | 203 | |
203 | 204 | label_found = False |
204 | 205 | for combo in product([self.using, None], serialization_formats, compression_formats): |
205 | 206 | database, format, compression_format = combo |
206 | | file_name = '.'.join( |
| 207 | file_name = str('.').join( |
207 | 208 | p for p in [ |
208 | 209 | fixture_name, database, format, compression_format |
209 | 210 | ] |
… |
… |
class Command(BaseCommand):
|
211 | 212 | ) |
212 | 213 | |
213 | 214 | if self.verbosity >= 3: |
214 | | self.stdout.write("Trying %s for %s fixture '%s'..." % \ |
| 215 | self.stdout.write(str("Trying %s for %s fixture '%s'...") % \ |
215 | 216 | (humanize(fixture_dir), file_name, fixture_name)) |
216 | 217 | full_path = os.path.join(fixture_dir, file_name) |
217 | 218 | open_method = self.compression_types[compression_format] |
… |
… |
class Command(BaseCommand):
|
219 | 220 | fixture = open_method(full_path, 'r') |
220 | 221 | except IOError: |
221 | 222 | if self.verbosity >= 2: |
222 | | self.stdout.write("No %s fixture '%s' in %s." % \ |
| 223 | self.stdout.write(str("No %s fixture '%s' in %s.") % \ |
223 | 224 | (format, fixture_name, humanize(fixture_dir))) |
224 | 225 | else: |
225 | 226 | try: |
226 | 227 | if label_found: |
227 | | raise CommandError("Multiple fixtures named '%s' in %s. Aborting." % |
| 228 | raise CommandError(str("Multiple fixtures named '%s' in %s. Aborting.") % |
228 | 229 | (fixture_name, humanize(fixture_dir))) |
229 | 230 | |
230 | 231 | self.fixture_count += 1 |
231 | 232 | objects_in_fixture = 0 |
232 | 233 | loaded_objects_in_fixture = 0 |
233 | 234 | if self.verbosity >= 2: |
234 | | self.stdout.write("Installing %s fixture '%s' from %s." % \ |
| 235 | self.stdout.write(str("Installing %s fixture '%s' from %s.") % \ |
235 | 236 | (format, fixture_name, humanize(fixture_dir))) |
236 | 237 | |
237 | 238 | objects = serializers.deserialize(format, fixture, using=self.using, ignorenonexistent=self.ignore) |
… |
… |
class Command(BaseCommand):
|
257 | 258 | label_found = True |
258 | 259 | except Exception as e: |
259 | 260 | if not isinstance(e, CommandError): |
260 | | e.args = ("Problem installing fixture '%s': %s" % (full_path, e),) |
| 261 | e.args = (str("Problem installing fixture '%s': %s") % (path_as_str(full_path), e),) |
261 | 262 | raise |
262 | 263 | finally: |
263 | 264 | fixture.close() |
… |
… |
class Command(BaseCommand):
|
265 | 266 | # If the fixture we loaded contains 0 objects, assume that an |
266 | 267 | # error was encountered during fixture loading. |
267 | 268 | if objects_in_fixture == 0: |
268 | | raise CommandError( |
269 | | "No fixture data found for '%s'. (File format may be invalid.)" % |
| 269 | raise CommandError(str( |
| 270 | "No fixture data found for '%s'. (File format may be invalid.)") % |
270 | 271 | (fixture_name)) |
-
diff --git a/django/core/management/sql.py b/django/core/management/sql.py
index 78cd17a..e887194 100644
a
|
b
|
def _split_statements(content):
|
159 | 159 | |
160 | 160 | def custom_sql_for_model(model, style, connection): |
161 | 161 | opts = model._meta |
162 | | app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), 'sql')) |
| 162 | app_dir = os.path.normpath(os.path.join(os.path.dirname(models.get_app(model._meta.app_label).__file__), str('sql'))) |
163 | 163 | output = [] |
164 | 164 | |
165 | 165 | # Post-creation SQL should come before any initial SQL data is loaded. |
… |
… |
def custom_sql_for_model(model, style, connection):
|
171 | 171 | output.extend(f.post_create_sql(style, model._meta.db_table)) |
172 | 172 | |
173 | 173 | # Find custom SQL, if it's available. |
174 | | backend_name = connection.settings_dict['ENGINE'].split('.')[-1] |
175 | | sql_files = [os.path.join(app_dir, "%s.%s.sql" % (opts.object_name.lower(), backend_name)), |
176 | | os.path.join(app_dir, "%s.sql" % opts.object_name.lower())] |
| 174 | backend_name = str(connection.settings_dict['ENGINE'].split('.')[-1]) |
| 175 | sql_files = [os.path.join(app_dir, str('%s.%s.sql') % (opts.object_name.lower(), backend_name)), |
| 176 | os.path.join(app_dir, str('%s.sql') % opts.object_name.lower())] |
177 | 177 | for sql_file in sql_files: |
178 | 178 | if os.path.exists(sql_file): |
179 | 179 | with codecs.open(sql_file, 'U', encoding=settings.FILE_CHARSET) as fp: |
-
diff --git a/django/db/utils.py b/django/db/utils.py
index a912986..7d6b60d 100644
a
|
b
|
def load_backend(backend_name):
|
27 | 27 | except ImportError as e_user: |
28 | 28 | # The database backend wasn't found. Display a helpful error message |
29 | 29 | # listing all possible (built-in) database backends. |
30 | | backend_dir = os.path.join(os.path.dirname(__file__), 'backends') |
| 30 | backend_dir = os.path.join(os.path.dirname(__file__), str('backends')) |
31 | 31 | try: |
32 | 32 | builtin_backends = [ |
33 | 33 | name for _, name, ispkg in pkgutil.iter_modules([backend_dir]) |
-
diff --git a/django/utils/translation/trans_real.py b/django/utils/translation/trans_real.py
index 1bcef2d..aa7815f 100644
a
|
b
|
def translation(language):
|
103 | 103 | """ |
104 | 104 | global _translations |
105 | 105 | |
| 106 | language = str(language) |
| 107 | |
106 | 108 | t = _translations.get(language, None) |
107 | 109 | if t is not None: |
108 | 110 | return t |
109 | 111 | |
110 | 112 | from django.conf import settings |
111 | 113 | |
112 | | globalpath = os.path.join(os.path.dirname(sys.modules[settings.__module__].__file__), 'locale') |
| 114 | globalpath = os.path.join(os.path.dirname(sys.modules[settings.__module__].__file__), str('locale')) |
113 | 115 | |
114 | 116 | def _fetch(lang, fallback=None): |
115 | 117 | |
… |
… |
def translation(language):
|
123 | 125 | |
124 | 126 | def _translation(path): |
125 | 127 | try: |
126 | | t = gettext_module.translation('django', path, [loc], DjangoTranslation) |
| 128 | t = gettext_module.translation(str('django'), path, [loc], DjangoTranslation) |
127 | 129 | t.set_language(lang) |
128 | 130 | return t |
129 | 131 | except IOError: |
… |
… |
def translation(language):
|
151 | 153 | |
152 | 154 | for appname in reversed(settings.INSTALLED_APPS): |
153 | 155 | app = import_module(appname) |
154 | | apppath = os.path.join(os.path.dirname(app.__file__), 'locale') |
| 156 | apppath = os.path.join(os.path.dirname(app.__file__), str('locale')) |
155 | 157 | |
156 | 158 | if os.path.isdir(apppath): |
157 | 159 | res = _merge(apppath) |
… |
… |
def all_locale_paths():
|
337 | 339 | """ |
338 | 340 | from django.conf import settings |
339 | 341 | globalpath = os.path.join( |
340 | | os.path.dirname(sys.modules[settings.__module__].__file__), 'locale') |
| 342 | os.path.dirname(sys.modules[settings.__module__].__file__), str('locale')) |
341 | 343 | return [globalpath] + list(settings.LOCALE_PATHS) |
342 | 344 | |
343 | 345 | def check_for_language(lang_code): |
… |
… |
def check_for_language(lang_code):
|
348 | 350 | or session and during format localization. |
349 | 351 | """ |
350 | 352 | for path in all_locale_paths(): |
351 | | if gettext_module.find('django', path, [to_locale(lang_code)]) is not None: |
| 353 | if gettext_module.find(str('django'), path, [str(to_locale(lang_code))]) is not None: |
352 | 354 | return True |
353 | 355 | return False |
354 | 356 | |
… |
… |
def get_language_from_request(request, check_path=False):
|
426 | 428 | if lang.lower() not in supported: |
427 | 429 | continue |
428 | 430 | for path in all_locale_paths(): |
429 | | if os.path.exists(os.path.join(path, dirname, 'LC_MESSAGES', 'django.mo')): |
| 431 | if os.path.exists(os.path.join(path, str(dirname), str('LC_MESSAGES'), str('django.mo'))): |
430 | 432 | _accepted[normalized] = lang |
431 | 433 | return lang |
432 | 434 | |
-
diff --git a/django/views/static.py b/django/views/static.py
index f61ba28..324250f 100644
a
|
b
|
|
| 1 | |
1 | 2 | """ |
2 | 3 | Views and functions for serving static files. These are only to be used |
3 | 4 | during development, and SHOULD NOT be used in a production setting. |
… |
… |
except ImportError: # Python 2
|
17 | 18 | from django.http import (CompatibleStreamingHttpResponse, Http404, |
18 | 19 | HttpResponse, HttpResponseRedirect, HttpResponseNotModified) |
19 | 20 | from django.template import loader, Template, Context, TemplateDoesNotExist |
| 21 | from django.utils._os import path_as_str |
20 | 22 | from django.utils.http import http_date, parse_http_date |
21 | 23 | from django.utils.translation import ugettext as _, ugettext_noop |
22 | 24 | |
… |
… |
def serve(request, path, document_root=None, show_indexes=False):
|
49 | 51 | newpath = os.path.join(newpath, part).replace('\\', '/') |
50 | 52 | if newpath and path != newpath: |
51 | 53 | return HttpResponseRedirect(newpath) |
52 | | fullpath = os.path.join(document_root, newpath) |
| 54 | fullpath = os.path.join(path_as_str(document_root), path_as_str(newpath)) |
53 | 55 | if os.path.isdir(fullpath): |
54 | 56 | if show_indexes: |
55 | 57 | return directory_index(newpath, fullpath) |
-
diff --git a/tests/modeltests/model_forms/tests.py b/tests/modeltests/model_forms/tests.py
index c47de45..3a7a24d 100644
a
|
b
|
class OldFormForXTests(TestCase):
|
1282 | 1282 | # it comes to validation. This specifically tests that #6302 is fixed for |
1283 | 1283 | # both file fields and image fields. |
1284 | 1284 | |
1285 | | with open(os.path.join(os.path.dirname(__file__), "test.png"), 'rb') as fp: |
| 1285 | with open(os.path.join(os.path.dirname(__file__), str('test.png')), 'rb') as fp: |
1286 | 1286 | image_data = fp.read() |
1287 | | with open(os.path.join(os.path.dirname(__file__), "test2.png"), 'rb') as fp: |
| 1287 | with open(os.path.join(os.path.dirname(__file__), str('test2.png')), 'rb') as fp: |
1288 | 1288 | image_data2 = fp.read() |
1289 | 1289 | |
1290 | 1290 | f = ImageFileForm( |
-
diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
index a26d7a6..27cd998 100644
a
|
b
|
class AdminScriptTestCase(unittest.TestCase):
|
27 | 27 | def write_settings(self, filename, apps=None, is_dir=False, sdict=None): |
28 | 28 | test_dir = os.path.dirname(os.path.dirname(__file__)) |
29 | 29 | if is_dir: |
30 | | settings_dir = os.path.join(test_dir, filename) |
| 30 | settings_dir = os.path.join(test_dir, str(filename)) |
31 | 31 | os.mkdir(settings_dir) |
32 | | settings_file_path = os.path.join(settings_dir, '__init__.py') |
| 32 | settings_file_path = os.path.join(settings_dir, str('__init__.py')) |
33 | 33 | else: |
34 | | settings_file_path = os.path.join(test_dir, filename) |
| 34 | settings_file_path = os.path.join(test_dir, str(filename)) |
35 | 35 | |
36 | 36 | with open(settings_file_path, 'w') as settings_file: |
37 | 37 | settings_file.write('# Settings file automatically generated by regressiontests.admin_scripts test case\n') |
… |
… |
class AdminScriptTestCase(unittest.TestCase):
|
57 | 57 | settings_file.write("%s = %s\n" % (k, v)) |
58 | 58 | |
59 | 59 | def remove_settings(self, filename, is_dir=False): |
60 | | full_name = os.path.join(test_dir, filename) |
| 60 | full_name = os.path.join(test_dir, str(filename)) |
61 | 61 | if is_dir: |
62 | 62 | shutil.rmtree(full_name) |
63 | 63 | else: |
… |
… |
class AdminScriptTestCase(unittest.TestCase):
|
68 | 68 | try: |
69 | 69 | if sys.platform.startswith('java'): |
70 | 70 | # Jython produces module$py.class files |
71 | | os.remove(re.sub(r'\.py$', '$py.class', full_name)) |
| 71 | os.remove(re.sub(str(r'\.py$'), str('$py.class'), full_name)) |
72 | 72 | else: |
73 | 73 | # CPython produces module.pyc files |
74 | | os.remove(full_name + 'c') |
| 74 | os.remove(full_name + str('c')) |
75 | 75 | except OSError: |
76 | 76 | pass |
77 | 77 | # Also remove a __pycache__ directory, if it exists |
78 | | cache_name = os.path.join(test_dir, '__pycache__') |
| 78 | cache_name = os.path.join(test_dir, str('__pycache__')) |
79 | 79 | if os.path.isdir(cache_name): |
80 | 80 | shutil.rmtree(cache_name) |
81 | 81 | |
… |
… |
class AdminScriptTestCase(unittest.TestCase):
|
135 | 135 | |
136 | 136 | def run_django_admin(self, args, settings_file=None): |
137 | 137 | bin_dir = os.path.abspath(os.path.dirname(bin.__file__)) |
138 | | return self.run_test(os.path.join(bin_dir, 'django-admin.py'), args, settings_file) |
| 138 | return self.run_test(os.path.join(bin_dir, str('django-admin.py')), args, settings_file) |
139 | 139 | |
140 | 140 | def run_manage(self, args, settings_file=None): |
141 | 141 | def safe_remove(path): |
… |
… |
class AdminScriptTestCase(unittest.TestCase):
|
145 | 145 | pass |
146 | 146 | |
147 | 147 | conf_dir = os.path.dirname(conf.__file__) |
148 | | template_manage_py = os.path.join(conf_dir, 'project_template', 'manage.py') |
| 148 | template_manage_py = os.path.join(conf_dir, str('project_template'), str('manage.py')) |
149 | 149 | |
150 | | test_manage_py = os.path.join(test_dir, 'manage.py') |
| 150 | test_manage_py = os.path.join(test_dir, str('manage.py')) |
151 | 151 | shutil.copyfile(template_manage_py, test_manage_py) |
152 | 152 | |
153 | 153 | with open(test_manage_py, 'r') as fp: |
… |
… |
class AdminScriptTestCase(unittest.TestCase):
|
162 | 162 | |
163 | 163 | def assertNoOutput(self, stream): |
164 | 164 | "Utility assertion: assert that the given stream is empty" |
165 | | self.assertEqual(len(stream), 0, "Stream should be empty: actually contains '%s'" % stream) |
| 165 | self.assertEqual(len(stream), 0, str("Stream should be empty: actually contains '%s'") % stream) |
166 | 166 | |
167 | 167 | def assertOutput(self, stream, msg): |
168 | 168 | "Utility assertion: assert that the given message exists in the output" |
169 | | self.assertTrue(msg in stream, "'%s' does not match actual output text '%s'" % (msg, stream)) |
| 169 | msg = str(msg) |
| 170 | self.assertTrue(msg in stream, str("'%s' does not match actual output text '%s'") % (msg, stream)) |
170 | 171 | |
171 | 172 | def assertNotInOutput(self, stream, msg): |
172 | 173 | "Utility assertion: assert that the given message doesn't exist in the output" |
173 | | self.assertFalse(msg in stream, "'%s' matches actual output text '%s'" % (msg, stream)) |
| 174 | msg = str(msg) |
| 175 | self.assertFalse(msg in stream, str("'%s' matches actual output text '%s'") % (msg, stream)) |
174 | 176 | |
175 | 177 | ########################################################################## |
176 | 178 | # DJANGO ADMIN TESTS |
… |
… |
class DjangoAdminSettingsDirectory(AdminScriptTestCase):
|
554 | 556 | def test_setup_environ(self): |
555 | 557 | "directory: startapp creates the correct directory" |
556 | 558 | args = ['startapp', 'settings_test'] |
557 | | app_path = os.path.join(test_dir, 'settings_test') |
| 559 | app_path = os.path.join(test_dir, str('settings_test')) |
558 | 560 | out, err = self.run_django_admin(args, 'regressiontests.settings') |
559 | 561 | self.addCleanup(shutil.rmtree, app_path) |
560 | 562 | self.assertNoOutput(err) |
… |
… |
class DjangoAdminSettingsDirectory(AdminScriptTestCase):
|
562 | 564 | |
563 | 565 | def test_setup_environ_custom_template(self): |
564 | 566 | "directory: startapp creates the correct directory with a custom template" |
565 | | template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'app_template') |
| 567 | template_path = os.path.join(test_dir, str('admin_scripts'), str('custom_templates'), str('app_template')) |
566 | 568 | args = ['startapp', '--template', template_path, 'custom_settings_test'] |
567 | | app_path = os.path.join(test_dir, 'custom_settings_test') |
| 569 | app_path = os.path.join(test_dir, str('custom_settings_test')) |
568 | 570 | out, err = self.run_django_admin(args, 'regressiontests.settings') |
569 | 571 | self.addCleanup(shutil.rmtree, app_path) |
570 | 572 | self.assertNoOutput(err) |
571 | 573 | self.assertTrue(os.path.exists(app_path)) |
572 | | self.assertTrue(os.path.exists(os.path.join(app_path, 'api.py'))) |
| 574 | self.assertTrue(os.path.exists(os.path.join(app_path, str('api.py')))) |
573 | 575 | |
574 | 576 | def test_builtin_command(self): |
575 | 577 | "directory: django-admin builtin commands fail with an error when no settings provided" |
… |
… |
class ManageSettingsWithImportError(AdminScriptTestCase):
|
994 | 996 | |
995 | 997 | def write_settings_with_import_error(self, filename, apps=None, is_dir=False, sdict=None): |
996 | 998 | if is_dir: |
997 | | settings_dir = os.path.join(test_dir, filename) |
| 999 | settings_dir = os.path.join(test_dir, str(filename)) |
998 | 1000 | os.mkdir(settings_dir) |
999 | | settings_file_path = os.path.join(settings_dir, '__init__.py') |
| 1001 | settings_file_path = os.path.join(settings_dir, str('__init__.py')) |
1000 | 1002 | else: |
1001 | | settings_file_path = os.path.join(test_dir, filename) |
| 1003 | settings_file_path = os.path.join(test_dir, str(filename)) |
1002 | 1004 | with open(settings_file_path, 'w') as settings_file: |
1003 | 1005 | settings_file.write('# Settings file automatically generated by regressiontests.admin_scripts test case\n') |
1004 | 1006 | settings_file.write('# The next line will cause an import error:\nimport foo42bar\n') |
… |
… |
class StartProject(LiveServerTestCase, AdminScriptTestCase):
|
1411 | 1413 | def test_simple_project(self): |
1412 | 1414 | "Make sure the startproject management command creates a project" |
1413 | 1415 | args = ['startproject', 'testproject'] |
1414 | | testproject_dir = os.path.join(test_dir, 'testproject') |
| 1416 | testproject_dir = os.path.join(test_dir, str('testproject')) |
1415 | 1417 | self.addCleanup(shutil.rmtree, testproject_dir, True) |
1416 | 1418 | |
1417 | 1419 | out, err = self.run_django_admin(args) |
… |
… |
class StartProject(LiveServerTestCase, AdminScriptTestCase):
|
1426 | 1428 | def test_invalid_project_name(self): |
1427 | 1429 | "Make sure the startproject management command validates a project name" |
1428 | 1430 | args = ['startproject', '7testproject'] |
1429 | | testproject_dir = os.path.join(test_dir, '7testproject') |
| 1431 | testproject_dir = os.path.join(test_dir, str('7testproject')) |
1430 | 1432 | self.addCleanup(shutil.rmtree, testproject_dir, True) |
1431 | 1433 | |
1432 | 1434 | out, err = self.run_django_admin(args) |
… |
… |
class StartProject(LiveServerTestCase, AdminScriptTestCase):
|
1436 | 1438 | def test_simple_project_different_directory(self): |
1437 | 1439 | "Make sure the startproject management command creates a project in a specific directory" |
1438 | 1440 | args = ['startproject', 'testproject', 'othertestproject'] |
1439 | | testproject_dir = os.path.join(test_dir, 'othertestproject') |
| 1441 | testproject_dir = os.path.join(test_dir, str('othertestproject')) |
1440 | 1442 | os.mkdir(testproject_dir) |
1441 | 1443 | self.addCleanup(shutil.rmtree, testproject_dir) |
1442 | 1444 | |
1443 | 1445 | out, err = self.run_django_admin(args) |
1444 | 1446 | self.assertNoOutput(err) |
1445 | | self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'manage.py'))) |
| 1447 | self.assertTrue(os.path.exists(os.path.join(testproject_dir, str('manage.py')))) |
1446 | 1448 | |
1447 | 1449 | # running again.. |
1448 | 1450 | out, err = self.run_django_admin(args) |
… |
… |
class StartProject(LiveServerTestCase, AdminScriptTestCase):
|
1451 | 1453 | |
1452 | 1454 | def test_custom_project_template(self): |
1453 | 1455 | "Make sure the startproject management command is able to use a different project template" |
1454 | | template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template') |
| 1456 | template_path = os.path.join(test_dir, str('admin_scripts'), str('custom_templates'), str('project_template')) |
1455 | 1457 | args = ['startproject', '--template', template_path, 'customtestproject'] |
1456 | | testproject_dir = os.path.join(test_dir, 'customtestproject') |
| 1458 | testproject_dir = os.path.join(test_dir, str('customtestproject')) |
1457 | 1459 | self.addCleanup(shutil.rmtree, testproject_dir, True) |
1458 | 1460 | |
1459 | 1461 | out, err = self.run_django_admin(args) |
1460 | 1462 | self.assertNoOutput(err) |
1461 | 1463 | self.assertTrue(os.path.isdir(testproject_dir)) |
1462 | | self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'additional_dir'))) |
| 1464 | self.assertTrue(os.path.exists(os.path.join(testproject_dir, str('additional_dir')))) |
1463 | 1465 | |
1464 | 1466 | def test_template_dir_with_trailing_slash(self): |
1465 | 1467 | "Ticket 17475: Template dir passed has a trailing path separator" |
1466 | | template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template' + os.sep) |
| 1468 | template_path = os.path.join(test_dir, str('admin_scripts'), str('custom_templates'), str('project_template') + os.sep) |
1467 | 1469 | args = ['startproject', '--template', template_path, 'customtestproject'] |
1468 | | testproject_dir = os.path.join(test_dir, 'customtestproject') |
| 1470 | testproject_dir = os.path.join(test_dir, str('customtestproject')) |
1469 | 1471 | self.addCleanup(shutil.rmtree, testproject_dir, True) |
1470 | 1472 | |
1471 | 1473 | out, err = self.run_django_admin(args) |
1472 | 1474 | self.assertNoOutput(err) |
1473 | 1475 | self.assertTrue(os.path.isdir(testproject_dir)) |
1474 | | self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'additional_dir'))) |
| 1476 | self.assertTrue(os.path.exists(os.path.join(testproject_dir, str('additional_dir')))) |
1475 | 1477 | |
1476 | 1478 | def test_custom_project_template_from_tarball_by_path(self): |
1477 | 1479 | "Make sure the startproject management command is able to use a different project template from a tarball" |
1478 | | template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template.tgz') |
| 1480 | template_path = os.path.join(test_dir, str('admin_scripts'), str('custom_templates'), str('project_template.tgz')) |
1479 | 1481 | args = ['startproject', '--template', template_path, 'tarballtestproject'] |
1480 | | testproject_dir = os.path.join(test_dir, 'tarballtestproject') |
| 1482 | testproject_dir = os.path.join(test_dir, str('tarballtestproject')) |
1481 | 1483 | self.addCleanup(shutil.rmtree, testproject_dir, True) |
1482 | 1484 | |
1483 | 1485 | out, err = self.run_django_admin(args) |
1484 | 1486 | self.assertNoOutput(err) |
1485 | 1487 | self.assertTrue(os.path.isdir(testproject_dir)) |
1486 | | self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'run.py'))) |
| 1488 | self.assertTrue(os.path.exists(os.path.join(testproject_dir, str('run.py')))) |
1487 | 1489 | |
1488 | 1490 | def test_custom_project_template_from_tarball_to_alternative_location(self): |
1489 | 1491 | "Startproject can use a project template from a tarball and create it in a specified location" |
1490 | | template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template.tgz') |
| 1492 | template_path = os.path.join(test_dir, str('admin_scripts'), str('custom_templates'), str('project_template.tgz')) |
1491 | 1493 | args = ['startproject', '--template', template_path, 'tarballtestproject', 'altlocation'] |
1492 | | testproject_dir = os.path.join(test_dir, 'altlocation') |
| 1494 | testproject_dir = os.path.join(test_dir, str('altlocation')) |
1493 | 1495 | os.mkdir(testproject_dir) |
1494 | 1496 | self.addCleanup(shutil.rmtree, testproject_dir) |
1495 | 1497 | |
1496 | 1498 | out, err = self.run_django_admin(args) |
1497 | 1499 | self.assertNoOutput(err) |
1498 | 1500 | self.assertTrue(os.path.isdir(testproject_dir)) |
1499 | | self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'run.py'))) |
| 1501 | self.assertTrue(os.path.exists(os.path.join(testproject_dir, str('run.py')))) |
1500 | 1502 | |
1501 | 1503 | def test_custom_project_template_from_tarball_by_url(self): |
1502 | 1504 | "Make sure the startproject management command is able to use a different project template from a tarball via a url" |
1503 | 1505 | template_url = '%s/admin_scripts/custom_templates/project_template.tgz' % self.live_server_url |
1504 | 1506 | |
1505 | 1507 | args = ['startproject', '--template', template_url, 'urltestproject'] |
1506 | | testproject_dir = os.path.join(test_dir, 'urltestproject') |
| 1508 | testproject_dir = os.path.join(test_dir, str('urltestproject')) |
1507 | 1509 | self.addCleanup(shutil.rmtree, testproject_dir, True) |
1508 | 1510 | |
1509 | 1511 | out, err = self.run_django_admin(args) |
1510 | 1512 | self.assertNoOutput(err) |
1511 | 1513 | self.assertTrue(os.path.isdir(testproject_dir)) |
1512 | | self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'run.py'))) |
| 1514 | self.assertTrue(os.path.exists(os.path.join(testproject_dir, str('run.py')))) |
1513 | 1515 | |
1514 | 1516 | def test_project_template_tarball_url(self): |
1515 | 1517 | "Startproject management command handles project template tar/zip balls from non-canonical urls" |
1516 | 1518 | template_url = '%s/admin_scripts/custom_templates/project_template.tgz/' % self.live_server_url |
1517 | 1519 | |
1518 | 1520 | args = ['startproject', '--template', template_url, 'urltestproject'] |
1519 | | testproject_dir = os.path.join(test_dir, 'urltestproject') |
| 1521 | testproject_dir = os.path.join(test_dir, str('urltestproject')) |
1520 | 1522 | self.addCleanup(shutil.rmtree, testproject_dir, True) |
1521 | 1523 | |
1522 | 1524 | out, err = self.run_django_admin(args) |
1523 | 1525 | self.assertNoOutput(err) |
1524 | 1526 | self.assertTrue(os.path.isdir(testproject_dir)) |
1525 | | self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'run.py'))) |
| 1527 | self.assertTrue(os.path.exists(os.path.join(testproject_dir, str('run.py')))) |
1526 | 1528 | |
1527 | 1529 | def test_file_without_extension(self): |
1528 | 1530 | "Make sure the startproject management command is able to render custom files" |
1529 | | template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template') |
| 1531 | template_path = os.path.join(test_dir, str('admin_scripts'), str('custom_templates'), str('project_template')) |
1530 | 1532 | args = ['startproject', '--template', template_path, 'customtestproject', '-e', 'txt', '-n', 'Procfile'] |
1531 | | testproject_dir = os.path.join(test_dir, 'customtestproject') |
| 1533 | testproject_dir = os.path.join(test_dir, str('customtestproject')) |
1532 | 1534 | self.addCleanup(shutil.rmtree, testproject_dir, True) |
1533 | 1535 | |
1534 | 1536 | out, err = self.run_django_admin(args) |
1535 | 1537 | self.assertNoOutput(err) |
1536 | 1538 | self.assertTrue(os.path.isdir(testproject_dir)) |
1537 | | self.assertTrue(os.path.exists(os.path.join(testproject_dir, 'additional_dir'))) |
1538 | | base_path = os.path.join(testproject_dir, 'additional_dir') |
1539 | | for f in ('Procfile', 'additional_file.py', 'requirements.txt'): |
| 1539 | self.assertTrue(os.path.exists(os.path.join(testproject_dir, str('additional_dir')))) |
| 1540 | base_path = os.path.join(testproject_dir, str('additional_dir')) |
| 1541 | for f in (str('Procfile'), str('additional_file.py'), str('requirements.txt')): |
1540 | 1542 | self.assertTrue(os.path.exists(os.path.join(base_path, f))) |
1541 | 1543 | with open(os.path.join(base_path, f)) as fh: |
1542 | 1544 | self.assertEqual(fh.read(), |
… |
… |
class StartProject(LiveServerTestCase, AdminScriptTestCase):
|
1544 | 1546 | |
1545 | 1547 | def test_custom_project_template_context_variables(self): |
1546 | 1548 | "Make sure template context variables are rendered with proper values" |
1547 | | template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template') |
| 1549 | template_path = os.path.join(test_dir, str('admin_scripts'), str('custom_templates'), str('project_template')) |
1548 | 1550 | args = ['startproject', '--template', template_path, 'another_project', 'project_dir'] |
1549 | | testproject_dir = os.path.join(test_dir, 'project_dir') |
| 1551 | testproject_dir = os.path.join(test_dir, str('project_dir')) |
1550 | 1552 | os.mkdir(testproject_dir) |
1551 | 1553 | self.addCleanup(shutil.rmtree, testproject_dir) |
1552 | 1554 | out, err = self.run_django_admin(args) |
1553 | 1555 | self.assertNoOutput(err) |
1554 | | test_manage_py = os.path.join(testproject_dir, 'manage.py') |
| 1556 | test_manage_py = os.path.join(testproject_dir, str('manage.py')) |
1555 | 1557 | with open(test_manage_py, 'r') as fp: |
1556 | 1558 | content = fp.read() |
1557 | | self.assertIn("project_name = 'another_project'", content) |
1558 | | self.assertIn("project_directory = '%s'" % testproject_dir, content) |
| 1559 | self.assertIn(str("project_name = 'another_project'"), content) |
| 1560 | self.assertIn(str("project_directory = '%s'") % testproject_dir, content) |
1559 | 1561 | |
1560 | 1562 | def test_no_escaping_of_project_variables(self): |
1561 | 1563 | "Make sure template context variables are not html escaped" |
1562 | 1564 | # We're using a custom command so we need the alternate settings |
1563 | 1565 | self.write_settings('alternate_settings.py') |
1564 | 1566 | self.addCleanup(self.remove_settings, 'alternate_settings.py') |
1565 | | template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template') |
| 1567 | template_path = os.path.join(test_dir, str('admin_scripts'), str('custom_templates'), str('project_template')) |
1566 | 1568 | args = ['custom_startproject', '--template', template_path, 'another_project', 'project_dir', '--extra', '<&>', '--settings=alternate_settings'] |
1567 | | testproject_dir = os.path.join(test_dir, 'project_dir') |
| 1569 | testproject_dir = os.path.join(test_dir, str('project_dir')) |
1568 | 1570 | os.mkdir(testproject_dir) |
1569 | 1571 | self.addCleanup(shutil.rmtree, testproject_dir) |
1570 | 1572 | out, err = self.run_manage(args) |
1571 | 1573 | self.assertNoOutput(err) |
1572 | | test_manage_py = os.path.join(testproject_dir, 'additional_dir', 'extra.py') |
| 1574 | test_manage_py = os.path.join(testproject_dir, str('additional_dir'), str('extra.py')) |
1573 | 1575 | with open(test_manage_py, 'r') as fp: |
1574 | 1576 | content = fp.read() |
1575 | 1577 | self.assertIn("<&>", content) |
… |
… |
class StartProject(LiveServerTestCase, AdminScriptTestCase):
|
1579 | 1581 | Make sure an exception is raised when the provided |
1580 | 1582 | destination directory doesn't exist |
1581 | 1583 | """ |
1582 | | template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template') |
| 1584 | template_path = os.path.join(test_dir, str('admin_scripts'), str('custom_templates'), str('project_template')) |
1583 | 1585 | args = ['startproject', '--template', template_path, 'yet_another_project', 'project_dir2'] |
1584 | | testproject_dir = os.path.join(test_dir, 'project_dir2') |
| 1586 | testproject_dir = os.path.join(test_dir, str('project_dir2')) |
1585 | 1587 | out, err = self.run_django_admin(args) |
1586 | 1588 | self.assertNoOutput(out) |
1587 | | self.assertOutput(err, "Destination directory '%s' does not exist, please create it first." % testproject_dir) |
| 1589 | self.assertOutput(err, str("Destination directory '%s' does not exist, please create it first.") % testproject_dir) |
1588 | 1590 | self.assertFalse(os.path.exists(testproject_dir)) |
1589 | 1591 | |
1590 | 1592 | def test_custom_project_template_with_non_ascii_templates(self): |
1591 | 1593 | "Ticket 18091: Make sure the startproject management command is able to render templates with non-ASCII content" |
1592 | | template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template') |
| 1594 | template_path = os.path.join(test_dir, str('admin_scripts'), str('custom_templates'), str('project_template')) |
1593 | 1595 | args = ['startproject', '--template', template_path, '--extension=txt', 'customtestproject'] |
1594 | | testproject_dir = os.path.join(test_dir, 'customtestproject') |
| 1596 | testproject_dir = os.path.join(test_dir, str('customtestproject')) |
1595 | 1597 | self.addCleanup(shutil.rmtree, testproject_dir, True) |
1596 | 1598 | |
1597 | 1599 | out, err = self.run_django_admin(args) |
1598 | 1600 | self.assertNoOutput(err) |
1599 | 1601 | self.assertTrue(os.path.isdir(testproject_dir)) |
1600 | | path = os.path.join(testproject_dir, 'ticket-18091-non-ascii-template.txt') |
| 1602 | path = os.path.join(testproject_dir, str('ticket-18091-non-ascii-template.txt')) |
1601 | 1603 | with codecs.open(path, 'r', 'utf-8') as f: |
1602 | 1604 | self.assertEqual(f.read(), |
1603 | 1605 | 'Some non-ASCII text for testing ticket #18091:\nüäö €\n') |
-
diff --git a/tests/regressiontests/admin_views/tests.py b/tests/regressiontests/admin_views/tests.py
index 62f69f6..96962b2 100644
a
|
b
|
class AdminViewFormUrlTest(TestCase):
|
633 | 633 | Refs #17515. |
634 | 634 | """ |
635 | 635 | template_dirs = settings.TEMPLATE_DIRS + ( |
636 | | os.path.join(os.path.dirname(__file__), 'templates'),) |
| 636 | os.path.join(os.path.dirname(__file__), str('templates')),) |
637 | 637 | with self.settings(TEMPLATE_DIRS=template_dirs): |
638 | 638 | response = self.client.get("/test_admin/admin/admin_views/color2/") |
639 | 639 | self.assertTrue('custom_filter_template.html' in [t.name for t in response.templates]) |
-
diff --git a/tests/regressiontests/app_loading/tests.py b/tests/regressiontests/app_loading/tests.py
index 0e66a5a..10c6aef 100644
a
|
b
|
class EggLoadingTest(TestCase):
|
13 | 13 | |
14 | 14 | def setUp(self): |
15 | 15 | self.old_path = sys.path[:] |
16 | | self.egg_dir = '%s/eggs' % os.path.dirname(__file__) |
| 16 | self.egg_dir = str('%s/eggs') % os.path.dirname(__file__) |
17 | 17 | |
18 | 18 | # This test adds dummy applications to the app cache. These |
19 | 19 | # need to be removed in order to prevent bad interactions |
-
diff --git a/tests/regressiontests/file_storage/tests.py b/tests/regressiontests/file_storage/tests.py
index 595b65d..c569e54 100644
a
|
b
|
class DimensionClosingBug(unittest.TestCase):
|
534 | 534 | from django.core.files import images |
535 | 535 | images.open = catching_open |
536 | 536 | try: |
537 | | get_image_dimensions(os.path.join(os.path.dirname(__file__), "test1.png")) |
| 537 | get_image_dimensions(os.path.join(os.path.dirname(__file__), str('test1.png'))) |
538 | 538 | finally: |
539 | 539 | del images.open |
540 | 540 | self.assertTrue(FileWrapper._closed) |
… |
… |
class InconsistentGetImageDimensionsBug(unittest.TestCase):
|
551 | 551 | """ |
552 | 552 | from django.core.files.images import ImageFile |
553 | 553 | |
554 | | img_path = os.path.join(os.path.dirname(__file__), "test.png") |
| 554 | img_path = os.path.join(os.path.dirname(__file__), str('test.png')) |
555 | 555 | image = ImageFile(open(img_path, 'rb')) |
556 | 556 | image_pil = Image.open(img_path) |
557 | 557 | size_1, size_2 = get_image_dimensions(image), get_image_dimensions(image) |
-
diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py
index 55363bc..2647e7f 100644
a
|
b
|
class TestFixtures(TestCase):
|
127 | 127 | """ |
128 | 128 | load_absolute_path = os.path.join( |
129 | 129 | os.path.dirname(__file__), |
130 | | 'fixtures', |
131 | | 'absolute.json' |
| 130 | str('fixtures'), |
| 131 | str('absolute.json') |
132 | 132 | ) |
133 | 133 | management.call_command( |
134 | 134 | 'loaddata', |
… |
… |
class TestFixtures(TestCase):
|
390 | 390 | |
391 | 391 | _cur_dir = os.path.dirname(os.path.abspath(__file__)) |
392 | 392 | |
393 | | @override_settings(FIXTURE_DIRS=[os.path.join(_cur_dir, 'fixtures_1'), |
394 | | os.path.join(_cur_dir, 'fixtures_2')]) |
| 393 | @override_settings(FIXTURE_DIRS=[os.path.join(_cur_dir, str('fixtures_1')), |
| 394 | os.path.join(_cur_dir, str('fixtures_2'))]) |
395 | 395 | def test_loaddata_forward_refs_split_fixtures(self): |
396 | 396 | """ |
397 | 397 | Regression for #17530 - should be able to cope with forward references |
… |
… |
class TestFixtures(TestCase):
|
429 | 429 | commit=False, |
430 | 430 | stdout=stdout_output, |
431 | 431 | ) |
432 | | self.assertTrue("No xml fixture 'this_fixture_doesnt_exist' in" in |
| 432 | self.assertIn(str("No xml fixture 'this_fixture_doesnt_exist' in"), |
433 | 433 | stdout_output.getvalue()) |
434 | 434 | |
435 | 435 | |
-
diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
index 1027afc..2e18db3 100644
a
|
b
|
class FieldsTests(SimpleTestCase):
|
992 | 992 | self.assertTrue(got[0].endswith(exp[0])) |
993 | 993 | |
994 | 994 | def test_filepathfield_folders(self): |
995 | | path = os.path.dirname(__file__) + '/filepath_test_files/' |
| 995 | path = os.path.dirname(__file__) + str('/filepath_test_files/') |
996 | 996 | f = FilePathField(path=path, allow_folders=True, allow_files=False) |
997 | 997 | f.choices.sort() |
998 | 998 | expected = [ |
-
diff --git a/tests/regressiontests/httpwrappers/tests.py b/tests/regressiontests/httpwrappers/tests.py
index 2d172ad..9b3d48d 100644
a
|
b
|
class StreamingHttpResponseTests(TestCase):
|
483 | 483 | |
484 | 484 | class FileCloseTests(TestCase): |
485 | 485 | def test_response(self): |
486 | | filename = os.path.join(os.path.dirname(__file__), 'abc.txt') |
| 486 | filename = os.path.join(os.path.dirname(__file__), str('abc.txt')) |
487 | 487 | |
488 | 488 | # file isn't closed until we close the response. |
489 | 489 | file1 = open(filename) |
… |
… |
class FileCloseTests(TestCase):
|
516 | 516 | self.assertTrue(file2.closed) |
517 | 517 | |
518 | 518 | def test_streaming_response(self): |
519 | | filename = os.path.join(os.path.dirname(__file__), 'abc.txt') |
| 519 | filename = os.path.join(os.path.dirname(__file__), str('abc.txt')) |
520 | 520 | |
521 | 521 | # file isn't closed until we close the response. |
522 | 522 | file1 = open(filename) |
-
diff --git a/tests/regressiontests/i18n/contenttypes/tests.py b/tests/regressiontests/i18n/contenttypes/tests.py
index 178232f..c6cfe0b 100644
a
|
b
|
from django.utils import translation
|
13 | 13 | @override_settings( |
14 | 14 | USE_I18N=True, |
15 | 15 | LOCALE_PATHS=( |
16 | | os.path.join(os.path.dirname(__file__), 'locale'), |
| 16 | os.path.join(os.path.dirname(__file__), str('locale')), |
17 | 17 | ), |
18 | 18 | LANGUAGE_CODE='en', |
19 | 19 | LANGUAGES=( |
-
diff --git a/tests/regressiontests/i18n/patterns/tests.py b/tests/regressiontests/i18n/patterns/tests.py
index 73c9f56..213ba8f 100644
a
|
b
|
from django.utils import translation
|
13 | 13 | @override_settings( |
14 | 14 | USE_I18N=True, |
15 | 15 | LOCALE_PATHS=( |
16 | | os.path.join(os.path.dirname(__file__), 'locale'), |
| 16 | os.path.join(os.path.dirname(__file__), str('locale')), |
17 | 17 | ), |
18 | 18 | TEMPLATE_DIRS=( |
19 | | os.path.join(os.path.dirname(__file__), 'templates'), |
| 19 | os.path.join(os.path.dirname(__file__), str('templates')), |
20 | 20 | ), |
21 | 21 | LANGUAGE_CODE='en', |
22 | 22 | LANGUAGES=( |
-
diff --git a/tests/regressiontests/i18n/tests.py b/tests/regressiontests/i18n/tests.py
index 2e0c097..60ee8d9 100644
a
|
b
|
from .patterns.tests import (URLRedirectWithoutTrailingSlashTests,
|
46 | 46 | |
47 | 47 | here = os.path.dirname(os.path.abspath(__file__)) |
48 | 48 | extended_locale_paths = settings.LOCALE_PATHS + ( |
49 | | os.path.join(here, 'other', 'locale'), |
| 49 | os.path.join(here, str('other'), str('locale')), |
50 | 50 | ) |
51 | 51 | |
52 | 52 | class TranslationTests(TestCase): |
… |
… |
class TranslationTests(TestCase):
|
266 | 266 | self.assertEqual(trans_real.to_language('en_US'), 'en-us') |
267 | 267 | self.assertEqual(trans_real.to_language('sr_Lat'), 'sr-lat') |
268 | 268 | |
269 | | @override_settings(LOCALE_PATHS=(os.path.join(here, 'other', 'locale'),)) |
| 269 | @override_settings(LOCALE_PATHS=(os.path.join(here, str('other'), str('locale')),)) |
270 | 270 | def test_bad_placeholder_1(self): |
271 | 271 | """ |
272 | 272 | Error in translation file should not crash template rendering |
… |
… |
class TranslationTests(TestCase):
|
278 | 278 | rendered = t.render(Context({'person': 'James'})) |
279 | 279 | self.assertEqual(rendered, 'My name is James.') |
280 | 280 | |
281 | | @override_settings(LOCALE_PATHS=(os.path.join(here, 'other', 'locale'),)) |
| 281 | @override_settings(LOCALE_PATHS=(os.path.join(here, str('other'), str('locale')),)) |
282 | 282 | def test_bad_placeholder_2(self): |
283 | 283 | """ |
284 | 284 | Error in translation file should not crash template rendering |
… |
… |
class FormattingTests(TestCase):
|
666 | 666 | with self.settings(USE_L10N=True, |
667 | 667 | FORMAT_MODULE_PATH='regressiontests.i18n.other.locale'): |
668 | 668 | with translation.override('de', deactivate=True): |
669 | | old = "%r" % get_format_modules(reverse=True) |
670 | | new = "%r" % get_format_modules(reverse=True) # second try |
| 669 | old = str("%r") % get_format_modules(reverse=True) |
| 670 | new = str("%r") % get_format_modules(reverse=True) # second try |
671 | 671 | self.assertEqual(new, old, 'Value returned by get_formats_modules() must be preserved between calls.') |
672 | 672 | |
673 | 673 | def test_localize_templatetag_and_filter(self): |
-
diff --git a/tests/regressiontests/servers/tests.py b/tests/regressiontests/servers/tests.py
index f54e34c..87b7c81 100644
a
|
b
|
from .models import Person
|
22 | 22 | TEST_ROOT = os.path.dirname(__file__) |
23 | 23 | TEST_SETTINGS = { |
24 | 24 | 'MEDIA_URL': '/media/', |
25 | | 'MEDIA_ROOT': os.path.join(TEST_ROOT, 'media'), |
| 25 | 'MEDIA_ROOT': os.path.join(TEST_ROOT, str('media')), |
26 | 26 | 'STATIC_URL': '/static/', |
27 | | 'STATIC_ROOT': os.path.join(TEST_ROOT, 'static'), |
| 27 | 'STATIC_ROOT': os.path.join(TEST_ROOT, str('static')), |
28 | 28 | } |
29 | 29 | |
30 | 30 | |
-
diff --git a/tests/regressiontests/staticfiles_tests/tests.py b/tests/regressiontests/staticfiles_tests/tests.py
index 0c8e7db..c7f25ea 100644
a
|
b
|
from django.core.exceptions import ImproperlyConfigured
|
15 | 15 | from django.core.management import call_command |
16 | 16 | from django.test import TestCase |
17 | 17 | from django.test.utils import override_settings |
18 | | from django.utils.encoding import smart_text |
| 18 | from django.utils.encoding import smart_text, force_str |
19 | 19 | from django.utils.functional import empty |
20 | | from django.utils._os import rmtree_errorhandler |
| 20 | from django.utils._os import path_as_text, rmtree_errorhandler |
21 | 21 | from django.utils import six |
22 | 22 | |
23 | 23 | from django.contrib.staticfiles import finders, storage |
… |
… |
TEST_SETTINGS = {
|
27 | 27 | 'DEBUG': True, |
28 | 28 | 'MEDIA_URL': '/media/', |
29 | 29 | 'STATIC_URL': '/static/', |
30 | | 'MEDIA_ROOT': os.path.join(TEST_ROOT, 'project', 'site_media', 'media'), |
31 | | 'STATIC_ROOT': os.path.join(TEST_ROOT, 'project', 'site_media', 'static'), |
| 30 | 'MEDIA_ROOT': os.path.join(TEST_ROOT, str('project'), str('site_media'), str('media')), |
| 31 | 'STATIC_ROOT': os.path.join(TEST_ROOT, str('project'), str('site_media'), str('static')), |
32 | 32 | 'STATICFILES_DIRS': ( |
33 | | os.path.join(TEST_ROOT, 'project', 'documents'), |
34 | | ('prefix', os.path.join(TEST_ROOT, 'project', 'prefixed')), |
| 33 | os.path.join(TEST_ROOT, str('project'), str('documents')), |
| 34 | (str('prefix'), os.path.join(TEST_ROOT, str('project'), str('prefixed'))), |
35 | 35 | ), |
36 | 36 | 'STATICFILES_FINDERS': ( |
37 | 37 | 'django.contrib.staticfiles.finders.FileSystemFinder', |
… |
… |
class BaseStaticFilesTestCase(object):
|
55 | 55 | # run and pick up changes in settings.STATICFILES_DIRS. |
56 | 56 | finders._finders.clear() |
57 | 57 | |
58 | | testfiles_path = os.path.join(TEST_ROOT, 'apps', 'test', 'static', 'test') |
| 58 | testfiles_path = os.path.join(TEST_ROOT, str('apps'), str('test'), str('static'), str('test')) |
59 | 59 | # To make sure SVN doesn't hangs itself with the non-ASCII characters |
60 | 60 | # during checkout, we actually create one file dynamically. |
61 | | self._nonascii_filepath = os.path.join(testfiles_path, '\u2297.txt') |
| 61 | self._nonascii_filepath = os.path.join(testfiles_path, force_str('\u2297.txt')) |
62 | 62 | with codecs.open(self._nonascii_filepath, 'w', 'utf-8') as f: |
63 | 63 | f.write("\u2297 in the app dir") |
64 | 64 | # And also create the stupid hidden file to dwarf the setup.py's |
65 | 65 | # package data handling. |
66 | | self._hidden_filepath = os.path.join(testfiles_path, '.hidden') |
| 66 | self._hidden_filepath = os.path.join(testfiles_path, str('.hidden')) |
67 | 67 | with codecs.open(self._hidden_filepath, 'w', 'utf-8') as f: |
68 | 68 | f.write("should be ignored") |
69 | 69 | self._backup_filepath = os.path.join( |
70 | | TEST_ROOT, 'project', 'documents', 'test', 'backup~') |
| 70 | TEST_ROOT, str('project'), str('documents'), str('test'), str('backup~')) |
71 | 71 | with codecs.open(self._backup_filepath, 'w', 'utf-8') as f: |
72 | 72 | f.write("should be ignored") |
73 | 73 | |
… |
… |
class BaseCollectionTestCase(BaseStaticFilesTestCase):
|
134 | 134 | |
135 | 135 | def _get_file(self, filepath): |
136 | 136 | assert filepath, 'filepath is empty.' |
137 | | filepath = os.path.join(settings.STATIC_ROOT, filepath) |
| 137 | filepath = os.path.join(settings.STATIC_ROOT, force_str(filepath)) |
138 | 138 | with codecs.open(filepath, "r", "utf-8") as f: |
139 | 139 | return f.read() |
140 | 140 | |
… |
… |
class TestFindStatic(CollectionTestCase, TestDefaults):
|
207 | 207 | out.seek(0) |
208 | 208 | lines = [l.strip() for l in out.readlines()] |
209 | 209 | self.assertEqual(len(lines), 3) # three because there is also the "Found <file> here" line |
210 | | self.assertIn('project', lines[1]) |
211 | | self.assertIn('apps', lines[2]) |
| 210 | self.assertIn(str('project'), lines[1]) |
| 211 | self.assertIn(str('apps'), lines[2]) |
212 | 212 | |
213 | 213 | |
214 | 214 | class TestCollection(CollectionTestCase, TestDefaults): |
… |
… |
class TestCollectionFilesOverride(CollectionTestCase):
|
292 | 292 | |
293 | 293 | """ |
294 | 294 | def setUp(self): |
295 | | self.orig_path = os.path.join(TEST_ROOT, 'apps', 'no_label', 'static', 'file2.txt') |
| 295 | self.orig_path = os.path.join(TEST_ROOT, str('apps'), str('no_label'), str('static'), str('file2.txt')) |
296 | 296 | # get modification and access times for no_label/static/file2.txt |
297 | 297 | self.orig_mtime = os.path.getmtime(self.orig_path) |
298 | 298 | self.orig_atime = os.path.getatime(self.orig_path) |
… |
… |
class TestCollectionFilesOverride(CollectionTestCase):
|
301 | 301 | # this file will have modification time older than no_label/static/file2.txt |
302 | 302 | # anyway it should be taken to STATIC_ROOT because 'test' app is before |
303 | 303 | # 'no_label' app in INSTALLED_APPS |
304 | | self.testfile_path = os.path.join(TEST_ROOT, 'apps', 'test', 'static', 'file2.txt') |
| 304 | self.testfile_path = os.path.join(TEST_ROOT, str('apps'), str('test'), str('static'), str('file2.txt')) |
305 | 305 | with open(self.testfile_path, 'w+') as f: |
306 | 306 | f.write('duplicate of file2.txt') |
307 | 307 | os.utime(self.testfile_path, (self.orig_atime - 1, self.orig_mtime - 1)) |
… |
… |
if sys.platform != 'win32':
|
586 | 586 | """ |
587 | 587 | With ``--link``, symbolic links are created. |
588 | 588 | """ |
589 | | self.assertTrue(os.path.islink(os.path.join(settings.STATIC_ROOT, 'test.txt'))) |
| 589 | self.assertTrue(os.path.islink(os.path.join(settings.STATIC_ROOT, str('test.txt')))) |
590 | 590 | |
591 | 591 | |
592 | 592 | class TestServeStatic(StaticFilesTestCase): |
… |
… |
class FinderTestCase(object):
|
656 | 656 | def test_find_first(self): |
657 | 657 | src, dst = self.find_first |
658 | 658 | found = self.finder.find(src) |
| 659 | # finders currently return paths as unicode strings |
| 660 | dst = path_as_text(dst) |
659 | 661 | self.assertEqual(os.path.normcase(found), os.path.normcase(dst)) |
660 | 662 | |
661 | 663 | def test_find_all(self): |
662 | 664 | src, dst = self.find_all |
663 | 665 | found = self.finder.find(src, all=True) |
| 666 | # finders currently return paths as unicode strings |
664 | 667 | found = [os.path.normcase(f) for f in found] |
665 | | dst = [os.path.normcase(d) for d in dst] |
| 668 | dst = [os.path.normcase(path_as_text(d)) for d in dst] |
666 | 669 | self.assertEqual(found, dst) |
667 | 670 | |
668 | 671 | |
… |
… |
class TestFileSystemFinder(StaticFilesTestCase, FinderTestCase):
|
673 | 676 | def setUp(self): |
674 | 677 | super(TestFileSystemFinder, self).setUp() |
675 | 678 | self.finder = finders.FileSystemFinder() |
676 | | test_file_path = os.path.join(TEST_ROOT, 'project', 'documents', 'test', 'file.txt') |
677 | | self.find_first = (os.path.join('test', 'file.txt'), test_file_path) |
678 | | self.find_all = (os.path.join('test', 'file.txt'), [test_file_path]) |
| 679 | test_file_path = os.path.join(TEST_ROOT, str('project'), str('documents'), str('test'), str('file.txt')) |
| 680 | self.find_first = (os.path.join(str('test'), str('file.txt')), test_file_path) |
| 681 | self.find_all = (os.path.join(str('test'), str('file.txt')), [test_file_path]) |
679 | 682 | |
680 | 683 | |
681 | 684 | class TestAppDirectoriesFinder(StaticFilesTestCase, FinderTestCase): |
… |
… |
class TestAppDirectoriesFinder(StaticFilesTestCase, FinderTestCase):
|
685 | 688 | def setUp(self): |
686 | 689 | super(TestAppDirectoriesFinder, self).setUp() |
687 | 690 | self.finder = finders.AppDirectoriesFinder() |
688 | | test_file_path = os.path.join(TEST_ROOT, 'apps', 'test', 'static', 'test', 'file1.txt') |
689 | | self.find_first = (os.path.join('test', 'file1.txt'), test_file_path) |
690 | | self.find_all = (os.path.join('test', 'file1.txt'), [test_file_path]) |
| 691 | test_file_path = os.path.join(TEST_ROOT, str('apps'), str('test'), str('static'), str('test'), str('file1.txt')) |
| 692 | self.find_first = (os.path.join(str('test'), str('file1.txt')), test_file_path) |
| 693 | self.find_all = (os.path.join(str('test'), str('file1.txt')), [test_file_path]) |
691 | 694 | |
692 | 695 | |
693 | 696 | class TestDefaultStorageFinder(StaticFilesTestCase, FinderTestCase): |
… |
… |
class TestDefaultStorageFinder(StaticFilesTestCase, FinderTestCase):
|
698 | 701 | super(TestDefaultStorageFinder, self).setUp() |
699 | 702 | self.finder = finders.DefaultStorageFinder( |
700 | 703 | storage=storage.StaticFilesStorage(location=settings.MEDIA_ROOT)) |
701 | | test_file_path = os.path.join(settings.MEDIA_ROOT, 'media-file.txt') |
702 | | self.find_first = ('media-file.txt', test_file_path) |
703 | | self.find_all = ('media-file.txt', [test_file_path]) |
| 704 | test_file_path = os.path.join(settings.MEDIA_ROOT, str('media-file.txt')) |
| 705 | self.find_first = (str('media-file.txt'), test_file_path) |
| 706 | self.find_all = (str('media-file.txt'), [test_file_path]) |
704 | 707 | |
705 | 708 | |
706 | 709 | class TestMiscFinder(TestCase): |
-
diff --git a/tests/regressiontests/templates/response.py b/tests/regressiontests/templates/response.py
index a2a76a3..9606333 100644
a
|
b
|
class SimpleTemplateResponseTest(TestCase):
|
206 | 206 | |
207 | 207 | @override_settings( |
208 | 208 | TEMPLATE_CONTEXT_PROCESSORS=[test_processor_name], |
209 | | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__),'templates')), |
| 209 | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), str('templates'))), |
210 | 210 | ) |
211 | 211 | class TemplateResponseTest(TestCase): |
212 | 212 | |
-
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 65d6e72..d39a5d3 100644
a
|
b
|
class Templates(TestCase):
|
1412 | 1412 | ### SSI TAG ######################################################## |
1413 | 1413 | |
1414 | 1414 | # Test normal behavior |
1415 | | 'ssi01': ('{%% ssi "%s" %%}' % os.path.join(basedir, 'templates', 'ssi_include.html'), {}, 'This is for testing an ssi include. {{ test }}\n'), |
1416 | | 'ssi02': ('{%% ssi "%s" %%}' % os.path.join(basedir, 'not_here'), {}, ''), |
1417 | | 'ssi03': ("{%% ssi '%s' %%}" % os.path.join(basedir, 'not_here'), {}, ''), |
| 1415 | 'ssi01': ('{%% ssi "%s" %%}' % os.path.join(basedir, str('templates'), str('ssi_include.html')), {}, 'This is for testing an ssi include. {{ test }}\n'), |
| 1416 | 'ssi02': ('{%% ssi "%s" %%}' % os.path.join(basedir, str('not_here')), {}, ''), |
| 1417 | 'ssi03': ("{%% ssi '%s' %%}" % os.path.join(basedir, str('not_here')), {}, ''), |
1418 | 1418 | |
1419 | 1419 | # Test passing as a variable |
1420 | | 'ssi04': ('{% load ssi from future %}{% ssi ssi_file %}', {'ssi_file': os.path.join(basedir, 'templates', 'ssi_include.html')}, 'This is for testing an ssi include. {{ test }}\n'), |
1421 | | 'ssi05': ('{% load ssi from future %}{% ssi ssi_file %}', {'ssi_file': 'no_file'}, ''), |
| 1420 | 'ssi04': ('{% load ssi from future %}{% ssi ssi_file %}', {'ssi_file': os.path.join(basedir, str('templates'), 'ssi_include.html')}, 'This is for testing an ssi include. {{ test }}\n'), |
| 1421 | 'ssi05': ('{% load ssi from future %}{% ssi ssi_file %}', {'ssi_file': str('no_file')}, ''), |
1422 | 1422 | |
1423 | 1423 | # Test parsed output |
1424 | | 'ssi06': ('{%% ssi "%s" parsed %%}' % os.path.join(basedir, 'templates', 'ssi_include.html'), {'test': 'Look ma! It parsed!'}, 'This is for testing an ssi include. Look ma! It parsed!\n'), |
1425 | | 'ssi07': ('{%% ssi "%s" parsed %%}' % os.path.join(basedir, 'not_here'), {'test': 'Look ma! It parsed!'}, ''), |
| 1424 | 'ssi06': ('{%% ssi "%s" parsed %%}' % os.path.join(basedir, str('templates'), str('ssi_include.html')), {'test': 'Look ma! It parsed!'}, 'This is for testing an ssi include. Look ma! It parsed!\n'), |
| 1425 | 'ssi07': ('{%% ssi "%s" parsed %%}' % os.path.join(basedir, str('not_here')), {'test': 'Look ma! It parsed!'}, ''), |
1426 | 1426 | |
1427 | 1427 | # Test space in file name |
1428 | | 'ssi08': ('{%% ssi "%s" %%}' % os.path.join(basedir, 'templates', 'ssi include with spaces.html'), {}, 'This is for testing an ssi include with spaces in its name. {{ test }}\n'), |
1429 | | 'ssi09': ('{%% ssi "%s" parsed %%}' % os.path.join(basedir, 'templates', 'ssi include with spaces.html'), {'test': 'Look ma! It parsed!'}, 'This is for testing an ssi include with spaces in its name. Look ma! It parsed!\n'), |
| 1428 | 'ssi08': ('{%% ssi "%s" %%}' % os.path.join(basedir, str('templates'), str('ssi include with spaces.html')), {}, 'This is for testing an ssi include with spaces in its name. {{ test }}\n'), |
| 1429 | 'ssi09': ('{%% ssi "%s" parsed %%}' % os.path.join(basedir, str('templates'), str('ssi include with spaces.html')), {'test': 'Look ma! It parsed!'}, 'This is for testing an ssi include with spaces in its name. Look ma! It parsed!\n'), |
1430 | 1430 | |
1431 | 1431 | ### TEMPLATETAG TAG ####################################################### |
1432 | 1432 | 'templatetag01': ('{% templatetag openblock %}', {}, '{%'), |
… |
… |
class TemplateTagLoading(unittest.TestCase):
|
1649 | 1649 | def setUp(self): |
1650 | 1650 | self.old_path = sys.path[:] |
1651 | 1651 | self.old_apps = settings.INSTALLED_APPS |
1652 | | self.egg_dir = '%s/eggs' % os.path.dirname(__file__) |
| 1652 | self.egg_dir = str('%s/eggs') % os.path.dirname(__file__) |
1653 | 1653 | self.old_tag_modules = template_base.templatetags_modules |
1654 | 1654 | template_base.templatetags_modules = [] |
1655 | 1655 | |
… |
… |
class TemplateTagLoading(unittest.TestCase):
|
1669 | 1669 | |
1670 | 1670 | def test_load_error_egg(self): |
1671 | 1671 | ttext = "{% load broken_egg %}" |
1672 | | egg_name = '%s/tagsegg.egg' % self.egg_dir |
| 1672 | egg_name = str('%s/tagsegg.egg') % self.egg_dir |
1673 | 1673 | sys.path.append(egg_name) |
1674 | 1674 | settings.INSTALLED_APPS = ('tagsegg',) |
1675 | 1675 | self.assertRaises(template.TemplateSyntaxError, template.Template, ttext) |
… |
… |
class TemplateTagLoading(unittest.TestCase):
|
1681 | 1681 | |
1682 | 1682 | def test_load_working_egg(self): |
1683 | 1683 | ttext = "{% load working_egg %}" |
1684 | | egg_name = '%s/tagsegg.egg' % self.egg_dir |
| 1684 | egg_name = str('%s/tagsegg.egg') % self.egg_dir |
1685 | 1685 | sys.path.append(egg_name) |
1686 | 1686 | settings.INSTALLED_APPS = ('tagsegg',) |
1687 | 1687 | t = template.Template(ttext) |
-
diff --git a/tests/regressiontests/test_client_regress/tests.py b/tests/regressiontests/test_client_regress/tests.py
index f424321..9c47cc5 100644
a
|
b
|
from django.http import HttpResponse
|
21 | 21 | |
22 | 22 | |
23 | 23 | @override_settings( |
24 | | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'templates'),) |
| 24 | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), str('templates')),) |
25 | 25 | ) |
26 | 26 | class AssertContainsTests(TestCase): |
27 | 27 | def test_contains(self): |
… |
… |
class TemplateExceptionTests(TestCase):
|
629 | 629 | template_loader.reset() |
630 | 630 | |
631 | 631 | @override_settings( |
632 | | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), 'bad_templates'),) |
| 632 | TEMPLATE_DIRS=(os.path.join(os.path.dirname(__file__), str('bad_templates')),) |
633 | 633 | ) |
634 | 634 | def test_bad_404_template(self): |
635 | 635 | "Errors found when rendering 404 error templates are re-raised" |
-
diff --git a/tests/regressiontests/utils/archive.py b/tests/regressiontests/utils/archive.py
index 5575f34..6275be7 100644
a
|
b
|
from django.utils import unittest
|
6 | 6 | from django.utils.archive import Archive, extract |
7 | 7 | |
8 | 8 | |
9 | | TEST_DIR = os.path.join(os.path.dirname(__file__), 'archives') |
| 9 | TEST_DIR = os.path.join(os.path.dirname(__file__), str('archives')) |
10 | 10 | |
11 | 11 | |
12 | 12 | class ArchiveTester(object): |
-
diff --git a/tests/regressiontests/utils/module_loading.py b/tests/regressiontests/utils/module_loading.py
index dffb519..80ee706 100644
a
|
b
|
class DefaultLoader(unittest.TestCase):
|
50 | 50 | class EggLoader(unittest.TestCase): |
51 | 51 | def setUp(self): |
52 | 52 | self.old_path = sys.path[:] |
53 | | self.egg_dir = '%s/eggs' % os.path.dirname(__file__) |
| 53 | self.egg_dir = str('%s/eggs') % os.path.dirname(__file__) |
54 | 54 | |
55 | 55 | def tearDown(self): |
56 | 56 | sys.path = self.old_path |
-
diff --git a/tests/regressiontests/views/tests/debug.py b/tests/regressiontests/views/tests/debug.py
index e616d18..9a691f7 100644
a
|
b
|
class ExceptionReportTestMixin(object):
|
306 | 306 | self.assertEqual(len(mail.outbox), 1) |
307 | 307 | email = mail.outbox[0] |
308 | 308 | # 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) |
| 309 | self.assertNotIn(str('cooked_eggs'), email.body) |
| 310 | self.assertNotIn(str('scrambled'), email.body) |
| 311 | self.assertNotIn(str('sauce'), email.body) |
| 312 | self.assertNotIn(str('worcestershire'), email.body) |
313 | 313 | if check_for_POST_params: |
314 | 314 | for k, v in self.breakfast_data.items(): |
315 | 315 | # All POST parameters are shown. |
316 | | self.assertIn(k, email.body) |
317 | | self.assertIn(v, email.body) |
| 316 | self.assertIn(str(k), email.body) |
| 317 | self.assertIn(str(v), email.body) |
318 | 318 | |
319 | 319 | def verify_safe_email(self, view, check_for_POST_params=True): |
320 | 320 | """ |
… |
… |
class ExceptionReportTestMixin(object):
|
327 | 327 | self.assertEqual(len(mail.outbox), 1) |
328 | 328 | email = mail.outbox[0] |
329 | 329 | # 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) |
| 330 | self.assertNotIn(str('cooked_eggs'), email.body) |
| 331 | self.assertNotIn(str('scrambled'), email.body) |
| 332 | self.assertNotIn(str('sauce'), email.body) |
| 333 | self.assertNotIn(str('worcestershire'), email.body) |
334 | 334 | if check_for_POST_params: |
335 | 335 | for k, v in self.breakfast_data.items(): |
336 | 336 | # All POST parameters' names are shown. |
337 | | self.assertIn(k, email.body) |
| 337 | self.assertIn(str(k), email.body) |
338 | 338 | # Non-sensitive POST parameters' values are shown. |
339 | | self.assertIn('baked-beans-value', email.body) |
340 | | self.assertIn('hash-brown-value', email.body) |
| 339 | self.assertIn(str('baked-beans-value'), email.body) |
| 340 | self.assertIn(str('hash-brown-value'), email.body) |
341 | 341 | # Sensitive POST parameters' values are not shown. |
342 | | self.assertNotIn('sausage-value', email.body) |
343 | | self.assertNotIn('bacon-value', email.body) |
| 342 | self.assertNotIn(str('sausage-value'), email.body) |
| 343 | self.assertNotIn(str('bacon-value'), email.body) |
344 | 344 | |
345 | 345 | def verify_paranoid_email(self, view): |
346 | 346 | """ |
… |
… |
class ExceptionReportTestMixin(object):
|
353 | 353 | self.assertEqual(len(mail.outbox), 1) |
354 | 354 | email = mail.outbox[0] |
355 | 355 | # 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) |
| 356 | self.assertNotIn(str('cooked_eggs'), email.body) |
| 357 | self.assertNotIn(str('scrambled'), email.body) |
| 358 | self.assertNotIn(str('sauce'), email.body) |
| 359 | self.assertNotIn(str('worcestershire'), email.body) |
360 | 360 | for k, v in self.breakfast_data.items(): |
361 | 361 | # All POST parameters' names are shown. |
362 | | self.assertIn(k, email.body) |
| 362 | self.assertIn(str(k), email.body) |
363 | 363 | # No POST parameters' values are shown. |
364 | | self.assertNotIn(v, email.body) |
| 364 | self.assertNotIn(str(v), email.body) |
365 | 365 | |
366 | 366 | |
367 | 367 | class ExceptionReporterFilterTests(TestCase, ExceptionReportTestMixin): |