Merge lp:~james-w/django-factory/fix-python2.6-compatibility into lp:django-factory

Proposed by James Westby
Status: Merged
Merged at revision: 60
Proposed branch: lp:~james-w/django-factory/fix-python2.6-compatibility
Merge into: lp:django-factory
Diff against target: 92 lines (+30/-6)
3 files modified
README (+3/-1)
django_factory/testcase.py (+7/-2)
django_project/factory_tests/tests.py (+20/-3)
To merge this branch: bzr merge lp:~james-w/django-factory/fix-python2.6-compatibility
Reviewer Review Type Date Requested Status
James Westby Pending
Review via email: mp+92336@code.launchpad.net

Description of the change

Hi,

I hate this fix, so other ideas are welcome.

Thanks,

James

To post a comment you must log in.
61. By James Westby

Improvements from review. Thanks to jml and achuni.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README'
2--- README 2012-02-07 23:08:29 +0000
3+++ README 2012-02-09 18:35:20 +0000
4@@ -352,7 +352,9 @@
5 0.9
6 ```
7
8-
9+ * Fix `TestCase` compatibility with 2.6. Previously when running under 2.6
10+ `testtools.TestCase.__init__` wouldn't be called, leading to lots
11+ of problems.
12
13 0.8
14 ```
15
16=== modified file 'django_factory/testcase.py'
17--- django_factory/testcase.py 2011-12-16 21:30:48 +0000
18+++ django_factory/testcase.py 2012-02-09 18:35:20 +0000
19@@ -26,14 +26,19 @@
20 ]
21
22
23-class TestCase(DjangoTestCase, TesttoolsTestCase):
24+# N.B. The order of the superclasses matters here.
25+# if Django is first then when running under 2.6
26+# TesttoolsTestCase.__init__() won't be called,
27+# causing all sorts of havoc.
28+
29+class TestCase(TesttoolsTestCase, DjangoTestCase):
30
31 def setUp(self):
32 super(TestCase, self).setUp()
33 self.factory = Factory(test_case=self)
34
35
36-class TransactionTestCase(DjangoTransactionTestCase, TesttoolsTestCase):
37+class TransactionTestCase(TesttoolsTestCase, DjangoTransactionTestCase):
38
39 def setUp(self):
40 super(TransactionTestCase, self).setUp()
41
42=== modified file 'django_project/factory_tests/tests.py'
43--- django_project/factory_tests/tests.py 2012-02-07 22:58:29 +0000
44+++ django_project/factory_tests/tests.py 2012-02-09 18:35:20 +0000
45@@ -21,7 +21,10 @@
46 from django.db.models import fields as django_fields
47 from django.test import TestCase as DjangoTestCase
48
49-from testtools import TestCase
50+from testtools import (
51+ ExtendedToOriginalDecorator,
52+ TestCase,
53+ )
54 from testtools.matchers import StartsWith
55
56 from django_factory import generators, testcase
57@@ -569,7 +572,7 @@
58 self.assertRaises(TypeError, factory.generate_value, field)
59
60
61-class TestFactory(DjangoTestCase, TestCase):
62+class TestFactory(TestCase, DjangoTestCase):
63
64 def test_get_fields_with_no_fields(self):
65 fields = Factory.get_fields(test_models.ModelWithNoFields)
66@@ -1052,7 +1055,7 @@
67
68 def run_test(self, cls, method_name):
69 test = cls(method_name)
70- result = TestResult()
71+ result = ExtendedToOriginalDecorator(TestResult())
72 result.startTestRun()
73 test.run(result)
74 result.stopTestRun()
75@@ -1071,3 +1074,17 @@
76 self.assertIsInstance(self.factory, Factory)
77 result = self.run_test(Test, 'test_foo')
78 self.assert_(result.wasSuccessful(), result.errors or result.failures)
79+
80+ def test_test_case_get_unique_integer(self):
81+ class Test(testcase.TestCase):
82+ def test_foo(self):
83+ self.getUniqueInteger()
84+ result = self.run_test(Test, 'test_foo')
85+ self.assert_(result.wasSuccessful(), result.errors or result.failures)
86+
87+ def test_transaction_test_case_get_unique_integer(self):
88+ class Test(testcase.TransactionTestCase):
89+ def test_foo(self):
90+ self.getUniqueInteger()
91+ result = self.run_test(Test, 'test_foo')
92+ self.assert_(result.wasSuccessful(), result.errors or result.failures)

Subscribers

People subscribed via source and target branches

to all changes: