Merge lp:~jameinel/bzr/2.5-merges-2.4 into lp:bzr/2.5

Proposed by John A Meinel
Status: Merged
Approved by: John A Meinel
Approved revision: no longer in the source branch.
Merged at revision: 6512
Proposed branch: lp:~jameinel/bzr/2.5-merges-2.4
Merge into: lp:bzr/2.5
Diff against target: 92 lines (+48/-6)
2 files modified
bzrlib/tests/__init__.py (+8/-2)
bzrlib/tests/test_selftest.py (+40/-4)
To merge this branch: bzr merge lp:~jameinel/bzr/2.5-merges-2.4
Reviewer Review Type Date Requested Status
Richard Wilbur Approve
Review via email: mp+164620@code.launchpad.net

Commit message

Merge 2.4 into 2.5, and resolve a few conflicts wrt extract_format_string().

Description of the change

This is a merge of 2.4 into 2.5.

I had been working with an out-of-date 2.5 branch. This new diff is just the overrideAttr fixes.

To post a comment you must log in.
Revision history for this message
Richard Wilbur (richard-wilbur) wrote :

Looks like these changes only touch the test suite. Thanks for taking the time to update the fixes so they can go into 2.5!
+1

review: Approve
Revision history for this message
John A Meinel (jameinel) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/tests/__init__.py'
2--- bzrlib/tests/__init__.py 2012-04-30 09:50:33 +0000
3+++ bzrlib/tests/__init__.py 2013-05-19 14:34:34 +0000
4@@ -1782,9 +1782,15 @@
5
6 :returns: The actual attr value.
7 """
8- value = getattr(obj, attr_name)
9 # The actual value is captured by the call below
10- self.addCleanup(setattr, obj, attr_name, value)
11+ value = getattr(obj, attr_name, _unitialized_attr)
12+ if value is _unitialized_attr:
13+ # When the test completes, the attribute should not exist, but if
14+ # we aren't setting a value, we don't need to do anything.
15+ if new is not _unitialized_attr:
16+ self.addCleanup(delattr, obj, attr_name)
17+ else:
18+ self.addCleanup(setattr, obj, attr_name, value)
19 if new is not _unitialized_attr:
20 setattr(obj, attr_name, new)
21 return value
22
23=== modified file 'bzrlib/tests/test_selftest.py'
24--- bzrlib/tests/test_selftest.py 2012-09-07 10:33:40 +0000
25+++ bzrlib/tests/test_selftest.py 2013-05-19 14:34:34 +0000
26@@ -1653,6 +1653,12 @@
27 self.assertRaises(AssertionError,
28 self.assertListRaises, _TestException, success_generator)
29
30+ def _run_successful_test(self, test):
31+ result = testtools.TestResult()
32+ test.run(result)
33+ self.assertTrue(result.wasSuccessful())
34+ return result
35+
36 def test_overrideAttr_without_value(self):
37 self.test_attr = 'original' # Define a test attribute
38 obj = self # Make 'obj' visible to the embedded test
39@@ -1668,8 +1674,7 @@
40 obj.test_attr = 'modified'
41 self.assertEqual('modified', obj.test_attr)
42
43- test = Test('test_value')
44- test.run(unittest.TestResult())
45+ self._run_successful_test(Test('test_value'))
46 self.assertEqual('original', obj.test_attr)
47
48 def test_overrideAttr_with_value(self):
49@@ -1685,10 +1690,41 @@
50 self.assertEqual('original', self.orig)
51 self.assertEqual('modified', obj.test_attr)
52
53- test = Test('test_value')
54- test.run(unittest.TestResult())
55+ self._run_successful_test(Test('test_value'))
56 self.assertEqual('original', obj.test_attr)
57
58+ def test_overrideAttr_with_no_existing_value_and_value(self):
59+ # Do not define the test_attribute
60+ obj = self # Make 'obj' visible to the embedded test
61+ class Test(tests.TestCase):
62+
63+ def setUp(self):
64+ tests.TestCase.setUp(self)
65+ self.orig = self.overrideAttr(obj, 'test_attr', new='modified')
66+
67+ def test_value(self):
68+ self.assertEqual(tests._unitialized_attr, self.orig)
69+ self.assertEqual('modified', obj.test_attr)
70+
71+ self._run_successful_test(Test('test_value'))
72+ self.assertRaises(AttributeError, getattr, obj, 'test_attr')
73+
74+ def test_overrideAttr_with_no_existing_value_and_no_value(self):
75+ # Do not define the test_attribute
76+ obj = self # Make 'obj' visible to the embedded test
77+ class Test(tests.TestCase):
78+
79+ def setUp(self):
80+ tests.TestCase.setUp(self)
81+ self.orig = self.overrideAttr(obj, 'test_attr')
82+
83+ def test_value(self):
84+ self.assertEqual(tests._unitialized_attr, self.orig)
85+ self.assertRaises(AttributeError, getattr, obj, 'test_attr')
86+
87+ self._run_successful_test(Test('test_value'))
88+ self.assertRaises(AttributeError, getattr, obj, 'test_attr')
89+
90 def test_recordCalls(self):
91 from bzrlib.tests import test_selftest
92 calls = self.recordCalls(

Subscribers

People subscribed via source and target branches