Skip to content

Loading…

Ticket 19038 - Add support for Python 3.3 #435

Closed
wants to merge 5 commits into from

2 participants

@clelland

I've updated the 19038 patch to the latest trunk, and removed the dependency on ticket 17758.

This passes the entire test suite, except for those tests which are broken by hash randomization, and the issue tracked in ticket 19039.

You can run the tests (or django itself) with hash randomization turned off in Python 3.3 with this:

PYTHONHASHSEED=0 ./runtests.py --settings=test_sqlite
@spookylukey
Django member

These are pulled now, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 10, 2012
  1. @clelland
  2. @clelland
  3. @clelland

    Don't use : as an invalid cookie character

    clelland committed
    Since http://bugs.python.org/issue2193 has been resolved in favour of
    the colon in cookie names, we need to test invalid cookie removal using
    a different character. "@" is still considered invalid by all sources.
  4. @clelland
  5. @clelland
View
4 django/test/testcases.py
@@ -867,7 +867,9 @@ def log_message(*args):
pass
-if sys.version_info >= (2, 7, 0):
+if sys.version_info >= (3, 3, 0):
+ _ImprovedEvent = threading.Event
+elif sys.version_info >= (2, 7, 0):
_ImprovedEvent = threading._Event
else:
class _ImprovedEvent(threading._Event):
View
10 django/utils/functional.py
@@ -293,6 +293,16 @@ def __getstate__(self):
self._setup()
return self._wrapped.__dict__
+ # Python 3.3 will call __reduce__ when pickling; these methods are needed
+ # to serialize and deserialize correctly. They are not called in earlier
+ # versions of Python.
+ @classmethod
+ def __newobj__(cls, *args):
+ return cls.__new__(cls, *args)
+
+ def __reduce__(self):
+ return (self.__newobj__, (self.__class__,), self.__getstate__())
+
# Need to pretend to be the wrapped class, for the sake of objects that care
# about this (especially in equality tests)
__class__ = property(new_method_proxy(operator.attrgetter("__class__")))
View
22 django/views/debug.py
@@ -354,15 +354,19 @@ def _get_lines_from_file(self, filename, lineno, context_lines, loader=None, mod
if source is None:
return None, [], None, []
- encoding = 'ascii'
- for line in source[:2]:
- # File coding may be specified. Match pattern from PEP-263
- # (http://www.python.org/dev/peps/pep-0263/)
- match = re.search(br'coding[:=]\s*([-\w.]+)', line)
- if match:
- encoding = match.group(1).decode('ascii')
- break
- source = [six.text_type(sline, encoding, 'replace') for sline in source]
+ # If we just read the source from a file, or if the loader did not
+ # apply tokenize.detect_encoding to decode the source into a Unicode
+ # string, then we should do that ourselves.
+ if isinstance(source[0], six.binary_type):
+ encoding = 'ascii'
+ for line in source[:2]:
+ # File coding may be specified. Match pattern from PEP-263
+ # (http://www.python.org/dev/peps/pep-0263/)
+ match = re.search(br'coding[:=]\s*([-\w.]+)', line)
+ if match:
+ encoding = match.group(1).decode('ascii')
+ break
+ source = [six.text_type(sline, encoding, 'replace') for sline in source]
lower_bound = max(0, lineno - context_lines)
upper_bound = lineno + context_lines
View
3 tests/modeltests/basic/tests.py
@@ -259,9 +259,8 @@ def test_object_creation(self):
"datetime.datetime(2005, 7, 28, 0, 0)"])
# dates() requires valid arguments.
- six.assertRaisesRegex(self,
+ self.assertRaises(
TypeError,
- "dates\(\) takes at least 3 arguments \(1 given\)",
Article.objects.dates,
)
View
6 tests/regressiontests/admin_scripts/tests.py
@@ -1010,7 +1010,8 @@ def test_builtin_command(self):
args = ['sqlall', 'admin_scripts']
out, err = self.run_manage(args)
self.assertNoOutput(out)
- self.assertOutput(err, "No module named foo42bar")
+ self.assertOutput(err, "No module named")
+ self.assertOutput(err, "foo42bar")
def test_builtin_command_with_attribute_error(self):
"""
@@ -1033,7 +1034,8 @@ def test_nonexistent_app(self):
args = ['validate']
out, err = self.run_manage(args)
self.assertNoOutput(out)
- self.assertOutput(err, 'No module named admin_scriptz')
+ self.assertOutput(err, 'No module named')
+ self.assertOutput(err, 'admin_scriptz')
def test_broken_app(self):
"manage.py validate reports an ImportError if an app's models.py raises one on import"
View
2 tests/regressiontests/file_storage/tests.py
@@ -78,7 +78,7 @@ def test_get_nonexisting_storage_module(self):
six.assertRaisesRegex(self,
ImproperlyConfigured,
('Error importing storage module django.core.files.non_existing_'
- 'storage: "No module named .*non_existing_storage"'),
+ 'storage: "No module named .*non_existing_storage'),
get_storage_class,
'django.core.files.non_existing_storage.NonExistingStorage'
)
View
2 tests/regressiontests/fixtures_regress/tests.py
@@ -159,7 +159,7 @@ def test_unimportable_serializer(self):
Test that failing serializer import raises the proper error
"""
with six.assertRaisesRegex(self, ImportError,
- "No module named unexistent.path"):
+ r"No module named.*unexistent"):
management.call_command(
'loaddata',
'bad_fixture1.unkn',
View
2 tests/regressiontests/requests/tests.py
@@ -56,7 +56,7 @@ def test_wsgirequest_repr(self):
str_prefix("<WSGIRequest\npath:/otherpath/,\nGET:{%(_)s'a': %(_)s'b'},\nPOST:{%(_)s'c': %(_)s'd'},\nCOOKIES:{%(_)s'e': %(_)s'f'},\nMETA:{%(_)s'g': %(_)s'h'}>"))
def test_parse_cookie(self):
- self.assertEqual(parse_cookie('invalid:key=true'), {})
+ self.assertEqual(parse_cookie('invalid@key=true'), {})
def test_httprequest_location(self):
request = HttpRequest()
Something went wrong with that request. Please try again.