Rev 6601: (vila) Split some tests to be able to get finer grained failures (Vincent in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Mon Oct 6 16:32:43 UTC 2014


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6601 [merge]
revision-id: pqm at pqm.ubuntu.com-20141006163242-c2cll01cwc24grkk
parent: pqm at pqm.ubuntu.com-20140922194230-y32j0sq621bxhp7c
parent: v.ladeuil+lp at free.fr-20141006123159-7q567ts4y38nwn89
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2014-10-06 16:32:42 +0000
message:
  (vila) Split some tests to be able to get finer grained failures (Vincent
   Ladeuil)
modified:
  bzrlib/diff.py                 diff.py-20050309040759-26944fbbf2ebbf36
  bzrlib/tests/test_diff.py      testdiff.py-20050727164403-d1a3496ebb12e339
=== modified file 'bzrlib/diff.py'
--- a/bzrlib/diff.py	2014-09-16 13:42:23 +0000
+++ b/bzrlib/diff.py	2014-10-06 12:31:59 +0000
@@ -286,21 +286,19 @@
     finally:
         oldtmpf.close()                 # and delete
         newtmpf.close()
-        # Clean up. Warn in case the files couldn't be deleted
-        # (in case windows still holds the file open, but not
-        # if the files have already been deleted)
-        try:
-            os.remove(old_abspath)
-        except OSError, e:
-            if e.errno not in (errno.ENOENT,):
-                warning('Failed to delete temporary file: %s %s',
-                        old_abspath, e)
-        try:
-            os.remove(new_abspath)
-        except OSError, e:
-            if e.errno not in (errno.ENOENT,):
-                warning('Failed to delete temporary file: %s %s',
-                        new_abspath, e)
+
+        def cleanup(path):
+            # Warn in case the file couldn't be deleted (in case windows still
+            # holds the file open, but not if the files have already been
+            # deleted)
+            try:
+                os.remove(path)
+            except OSError, e:
+                if e.errno not in (errno.ENOENT,):
+                    warning('Failed to delete temporary file: %s %s', path, e)
+
+        cleanup(old_abspath)
+        cleanup(new_abspath)
 
 
 def get_trees_and_branches_to_diff_locked(

=== modified file 'bzrlib/tests/test_diff.py'
--- a/bzrlib/tests/test_diff.py	2014-09-16 13:42:23 +0000
+++ b/bzrlib/tests/test_diff.py	2014-10-02 05:50:48 +0000
@@ -17,7 +17,6 @@
 import os
 from cStringIO import StringIO
 import subprocess
-import sys
 import tempfile
 
 from bzrlib import (
@@ -32,12 +31,15 @@
     tests,
     transform,
     )
-from bzrlib.symbol_versioning import deprecated_in
-from bzrlib.tests import features, EncodingAdapter
-from bzrlib.tests.blackbox.test_diff import subst_dates
 from bzrlib.tests import (
     features,
-    )
+    EncodingAdapter,
+)
+from bzrlib.tests.blackbox.test_diff import subst_dates
+from bzrlib.tests.scenarios import load_tests_apply_scenarios
+
+
+load_tests = load_tests_apply_scenarios
 
 
 def udiff_lines(old, new, allow_binary=False):
@@ -63,6 +65,29 @@
     return lines
 
 
+class TestDiffOptions(tests.TestCase):
+
+    def test_unified_added(self):
+        """Check for default style '-u' only if no other style specified
+        in 'diff-options'.
+        """
+        # Verify that style defaults to unified, id est '-u' appended
+        # to option list, in the absence of an alternative style.
+        self.assertEqual(['-a', '-u'], diff.default_style_unified(['-a']))
+
+
+class TestDiffOptionsScenarios(tests.TestCase):
+
+    scenarios = [(s, dict(style=s)) for s in diff.style_option_list]
+    style = None # Set by load_tests_apply_scenarios from scenarios
+
+    def test_unified_not_added(self):
+        # Verify that for all valid style options, '-u' is not
+        # appended to option list.
+        ret_opts = diff.default_style_unified(diff_opts=["%s" % (self.style,)])
+        self.assertEqual(["%s" % (self.style,)], ret_opts)
+
+
 class TestDiff(tests.TestCase):
 
     def test_add_nl(self):
@@ -143,19 +168,6 @@
                           'old', ['boo\n'], 'new', ['goo\n'],
                           StringIO(), diff_opts=['-u'])
 
-    def test_default_style_unified(self):
-        """Check for default style '-u' only if no other style specified
-        in 'diff-options'.
-        """
-        # Verify that style defaults to unified, id est '-u' appended
-        # to option list, in the absence of an alternative style.
-        self.assertEqual(['-a', '-u'], diff.default_style_unified(["-a"]))
-        # Verify that for all valid style options, '-u' is not
-        # appended to option list.
-        for s in diff.style_option_list:
-            ret_opts = diff.default_style_unified(diff_opts=["%s" % (s,)])
-            self.assertEqual(["%s" % (s,)], ret_opts)
-
     def test_internal_diff_default(self):
         # Default internal diff encoding is utf8
         output = StringIO()
@@ -1484,7 +1496,6 @@
     def test_encodable_filename(self):
         # Just checks file path for external diff tool.
         # We cannot change CPython's internal encoding used by os.exec*.
-        import sys
         diffobj = diff.DiffFromTool(['dummy', '@old_path', '@new_path'],
                                     None, None, None)
         for _, scenario in EncodingAdapter.encoding_scenarios:
@@ -1502,7 +1513,6 @@
             self.assert_(fullpath.startswith(diffobj._root + '/safe'))
 
     def test_unencodable_filename(self):
-        import sys
         diffobj = diff.DiffFromTool(['dummy', '@old_path', '@new_path'],
                                     None, None, None)
         for _, scenario in EncodingAdapter.encoding_scenarios:




More information about the bazaar-commits mailing list