Merge lp:~gz/bzr/trivial_test_rename_fails_stringification into lp:bzr

Proposed by Martin Packman
Status: Merged
Approved by: John A Meinel
Approved revision: not available
Merged at revision: 5606
Proposed branch: lp:~gz/bzr/trivial_test_rename_fails_stringification
Merge into: lp:bzr
Diff against target: 29 lines (+9/-3)
1 file modified
bzrlib/tests/test_transform.py (+9/-3)
To merge this branch: bzr merge lp:~gz/bzr/trivial_test_rename_fails_stringification
Reviewer Review Type Date Requested Status
bzr-core Pending
Review via email: mp+46055@code.launchpad.net

Commit message

Transform.rename test shouldn't assume the str form of the exception because of locale issues.

Description of the change

Philosophy: It's worth checking that exception instances stringify sanely, but that should be done in bt.test_errors on artificially constructed exception instances. Tests like bt.test_transform.TestTreeTransform.test_rename_fails that want to check the right thing is thrown should do it by examining the attributes on the instances.

The test is a little messy because it does some dancing to induce a permissions failure, but that can get cleaned up and unified with other tests that need a similar mechanism at a later date.

...this incidentally avoids a failure on babune due to bug 262874 not being fixed yet.

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

sent to pqm by email

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/test_transform.py'
2--- bzrlib/tests/test_transform.py 2011-01-12 01:01:53 +0000
3+++ bzrlib/tests/test_transform.py 2011-01-13 01:07:15 +0000
4@@ -14,6 +14,7 @@
5 # along with this program; if not, write to the Free Software
6 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
7
8+import errno
9 import os
10 from StringIO import StringIO
11 import sys
12@@ -897,9 +898,14 @@
13 # On windows looks like:
14 # "Failed to rename .../work/myfile to
15 # .../work/.bzr/checkout/limbo/new-1: [Errno 13] Permission denied"
16- # The strerror will vary per OS and language so it's not checked here
17- self.assertContainsRe(str(e),
18- "Failed to rename .*(first-dir.newname:|myfile)")
19+ # This test isn't concerned with exactly what the error looks like,
20+ # and the strerror will vary across OS and locales, but the assert
21+ # that the exeception attributes are what we expect
22+ self.assertEqual(e.errno, errno.EACCES)
23+ if os.name == "posix":
24+ self.assertEndsWith(e.to_path, "/first-dir/newname")
25+ else:
26+ self.assertEqual(os.path.basename(e.from_path), "myfile")
27
28 def test_set_executability_order(self):
29 """Ensure that executability behaves the same, no matter what order.