From d4a0b27838c815af87698920cc4db7d2afd6f05b Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sun, 12 Aug 2012 12:32:08 +0200 Subject: [py3] Refactored __unicode__ to __str__. * Renamed the __unicode__ methods * Applied the python_2_unicode_compatible decorator * Removed the StrAndUnicode mix-in that is superseded by python_2_unicode_compatible * Kept the __unicode__ methods in classes that specifically test it under Python 2 --- tests/regressiontests/admin_scripts/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'tests/regressiontests/admin_scripts') diff --git a/tests/regressiontests/admin_scripts/models.py b/tests/regressiontests/admin_scripts/models.py index da803d0174..cd96052098 100644 --- a/tests/regressiontests/admin_scripts/models.py +++ b/tests/regressiontests/admin_scripts/models.py @@ -1,11 +1,13 @@ from django.db import models +from django.utils.encoding import python_2_unicode_compatible +@python_2_unicode_compatible class Article(models.Model): headline = models.CharField(max_length=100, default='Default headline') pub_date = models.DateTimeField() - def __unicode__(self): + def __str__(self): return self.headline class Meta: -- cgit v1.3 From 73f0f18c8fc04a03bbfb20794aabb95944c90f63 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Mon, 13 Aug 2012 10:58:21 +0200 Subject: [py3] Fixed admin_scripts tests --- tests/regressiontests/admin_scripts/tests.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'tests/regressiontests/admin_scripts') diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py index 546fa7d79c..a8fc7ed503 100644 --- a/tests/regressiontests/admin_scripts/tests.py +++ b/tests/regressiontests/admin_scripts/tests.py @@ -71,6 +71,10 @@ class AdminScriptTestCase(unittest.TestCase): os.remove(full_name + 'c') except OSError: pass + # Also remove a __pycache__ directory, if it exists + cache_name = os.path.join(test_dir, '__pycache__') + if os.path.isdir(cache_name): + shutil.rmtree(cache_name) def _ext_backend_paths(self): """ @@ -110,14 +114,11 @@ class AdminScriptTestCase(unittest.TestCase): python_path.extend(ext_backend_base_dirs) os.environ[python_path_var_name] = os.pathsep.join(python_path) - # Silence the DeprecationWarning caused by having a locale directory - # in the project directory. - cmd = [sys.executable, '-Wignore:::django.utils.translation', script] - # Move to the test directory and run os.chdir(test_dir) - out, err = subprocess.Popen(cmd + args, - stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() + out, err = subprocess.Popen([sys.executable, script] + args, + stdout=subprocess.PIPE, stderr=subprocess.PIPE, + universal_newlines=True).communicate() # Restore the old environment if old_django_settings_module: -- cgit v1.3 From 3afb5916b215c79e36408b729c9516bc435f5cb7 Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Tue, 28 Aug 2012 23:22:06 +0200 Subject: Fixed #18091 -- Non-ASCII templates break `django-admin.py startproject --template=TEMPLATE`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to Claude Huchet and Tomáš Ehrlich for the patch. --- django/core/management/templates.py | 6 ++++-- .../project_template/ticket-18091-non-ascii-template.txt | 2 ++ tests/regressiontests/admin_scripts/tests.py | 13 +++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/regressiontests/admin_scripts/custom_templates/project_template/ticket-18091-non-ascii-template.txt (limited to 'tests/regressiontests/admin_scripts') diff --git a/django/core/management/templates.py b/django/core/management/templates.py index 52d0e5c89d..aa65593e9c 100644 --- a/django/core/management/templates.py +++ b/django/core/management/templates.py @@ -8,6 +8,8 @@ import shutil import stat import sys import tempfile +import codecs + try: from urllib.request import urlretrieve except ImportError: # Python 2 @@ -154,12 +156,12 @@ class TemplateCommand(BaseCommand): # Only render the Python files, as we don't want to # accidentally render Django templates files - with open(old_path, 'r') as template_file: + with codecs.open(old_path, 'r', 'utf-8') as template_file: content = template_file.read() if filename.endswith(extensions) or filename in extra_files: template = Template(content) content = template.render(context) - with open(new_path, 'w') as new_file: + with codecs.open(new_path, 'w', 'utf-8') as new_file: new_file.write(content) if self.verbosity >= 2: diff --git a/tests/regressiontests/admin_scripts/custom_templates/project_template/ticket-18091-non-ascii-template.txt b/tests/regressiontests/admin_scripts/custom_templates/project_template/ticket-18091-non-ascii-template.txt new file mode 100644 index 0000000000..873eaded88 --- /dev/null +++ b/tests/regressiontests/admin_scripts/custom_templates/project_template/ticket-18091-non-ascii-template.txt @@ -0,0 +1,2 @@ +Some non-ASCII text for testing ticket #18091: +üäö € diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py index a8fc7ed503..3af291b806 100644 --- a/tests/regressiontests/admin_scripts/tests.py +++ b/tests/regressiontests/admin_scripts/tests.py @@ -1573,3 +1573,16 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase): self.assertOutput(err, "Destination directory '%s' does not exist, please create it first." % testproject_dir) self.assertFalse(os.path.exists(testproject_dir)) + + def test_custom_project_template_with_non_ascii_templates(self): + "Ticket 18091: Make sure the startproject management command is able to render templates with non-ASCII content" + template_path = os.path.join(test_dir, 'admin_scripts', 'custom_templates', 'project_template') + args = ['startproject', '--template', template_path, '--extension=txt', 'customtestproject'] + testproject_dir = os.path.join(test_dir, 'customtestproject') + + out, err = self.run_django_admin(args) + self.addCleanup(shutil.rmtree, testproject_dir) + self.assertNoOutput(err) + self.assertTrue(os.path.isdir(testproject_dir)) + self.assertEqual(open(os.path.join(testproject_dir, 'ticket-18091-non-ascii-template.txt')).read(), + 'Some non-ASCII text for testing ticket #18091:\n\xc3\xbc\xc3\xa4\xc3\xb6 \xe2\x82\xac\n') -- cgit v1.3 From 9eafb6592e9ed27a59cb3cd9920c44cf230a6c65 Mon Sep 17 00:00:00 2001 From: Florian Apolloner Date: Wed, 29 Aug 2012 00:02:53 +0200 Subject: [py3] Fixed test failures introduced in 3afb5916b215c79e36408b729c9516bc435f5cb7. --- tests/regressiontests/admin_scripts/tests.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'tests/regressiontests/admin_scripts') diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py index 3af291b806..2710f80929 100644 --- a/tests/regressiontests/admin_scripts/tests.py +++ b/tests/regressiontests/admin_scripts/tests.py @@ -1,8 +1,10 @@ +# -*- coding: utf-8 -*- """ A series of tests to establish that the command-line managment tools work as advertised - especially with regards to the handling of the DJANGO_SETTINGS_MODULE and default settings.py files. """ +from __future__ import unicode_literals import os import re @@ -10,6 +12,7 @@ import shutil import socket import subprocess import sys +import codecs from django import conf, bin, get_version from django.conf import settings @@ -1584,5 +1587,6 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase): self.addCleanup(shutil.rmtree, testproject_dir) self.assertNoOutput(err) self.assertTrue(os.path.isdir(testproject_dir)) - self.assertEqual(open(os.path.join(testproject_dir, 'ticket-18091-non-ascii-template.txt')).read(), - 'Some non-ASCII text for testing ticket #18091:\n\xc3\xbc\xc3\xa4\xc3\xb6 \xe2\x82\xac\n') + path = os.path.join(testproject_dir, 'ticket-18091-non-ascii-template.txt') + self.assertEqual(codecs.open(path, 'r', 'utf-8').read(), + 'Some non-ASCII text for testing ticket #18091:\nüäö €\n') -- cgit v1.3