← Back to team overview

testtools-dev team mailing list archive

[Merge] lp:~jml/testtools/address-0.9.18-release-issues into lp:testtools

 

Jonathan Lange has proposed merging lp:~jml/testtools/address-0.9.18-release-issues into lp:testtools.

Commit message:
Fix Python 3 cosmetic errors and include matcher tests in the release

Requested reviews:
  testtools committers (testtools-committers)

For more details, see:
https://code.launchpad.net/~jml/testtools/address-0.9.18-release-issues/+merge/130557

Attacks the cosmetic Python 3.3 errors by sorting dict output.

Includes the matcher tests, allowing the tests to be run from the tarball.
-- 
https://code.launchpad.net/~jml/testtools/address-0.9.18-release-issues/+merge/130557
Your team testtools developers is subscribed to branch lp:testtools.
=== modified file 'MANIFEST.in'
--- MANIFEST.in	2011-04-11 11:40:44 +0000
+++ MANIFEST.in	2012-10-19 14:15:26 +0000
@@ -1,8 +1,6 @@
 include LICENSE
-include HACKING
 include Makefile
 include MANIFEST.in
-include MANUAL
 include NEWS
 include README
 include .bzrignore

=== modified file 'NEWS'
--- NEWS	2012-10-19 09:10:59 +0000
+++ NEWS	2012-10-19 14:15:26 +0000
@@ -6,6 +6,15 @@
 NEXT
 ~~~~
 
+Improvements
+------------
+
+* Include the matcher tests in the release, allowing the tests to run and
+  pass from the release tarball.  (Jonathan Lange)
+
+* Fix cosmetic test failures in Python 3.3, introduced during release 0.9.17.
+  (Jonathan Lange)
+
 
 0.9.18
 ~~~~~~

=== modified file 'setup.py'
--- setup.py	2012-10-19 09:06:47 +0000
+++ setup.py	2012-10-19 14:15:26 +0000
@@ -77,5 +77,6 @@
         'testtools.matchers',
         'testtools.testresult',
         'testtools.tests',
+        'testtools.tests.matchers',
         ],
       cmdclass={'test': testtools.TestCommand})

=== modified file 'testtools/content_type.py'
--- testtools/content_type.py	2012-07-21 22:08:56 +0000
+++ testtools/content_type.py	2012-10-19 14:15:26 +0000
@@ -30,7 +30,7 @@
         if self.parameters:
             params = '; '
             params += ', '.join(
-                '%s="%s"' % (k, v) for k, v in self.parameters.items())
+                sorted('%s="%s"' % (k, v) for k, v in self.parameters.items()))
         else:
             params = ''
         return "%s/%s%s" % (self.type, self.subtype, params)

=== modified file 'testtools/matchers/_dict.py'
--- testtools/matchers/_dict.py	2012-09-10 11:37:46 +0000
+++ testtools/matchers/_dict.py	2012-10-19 14:15:26 +0000
@@ -36,8 +36,7 @@
         self.matchers = matchers
 
     def __str__(self):
-        return 'MatchesAllDict({%s})' % (
-            ', '.join('%r: %s' % (k, v) for k, v in self.matchers.items()))
+        return 'MatchesAllDict(%s)' % (_format_matcher_dict(self.matchers),)
 
     def match(self, observed):
         mismatches = {}
@@ -134,7 +133,7 @@
 
 def _format_matcher_dict(matchers):
     return '{%s}' % (
-        ', '.join('%r: %s' % (k, v) for k, v in matchers.items()))
+        ', '.join(sorted('%r: %s' % (k, v) for k, v in matchers.items())))
 
 
 class _CombinedMatcher(Matcher):

=== modified file 'testtools/tests/matchers/test_dict.py'
--- testtools/tests/matchers/test_dict.py	2012-09-08 17:21:06 +0000
+++ testtools/tests/matchers/test_dict.py	2012-10-19 14:15:26 +0000
@@ -48,11 +48,16 @@
         ("KeysEqual('foo', 'bar')", KeysEqual('foo', 'bar')),
         ]
 
-    describe_examples = [
-        ("['bar', 'foo'] does not match {'baz': 2, 'foo': 0, 'bar': 1}: "
-         "Keys not equal",
-         {'foo': 0, 'bar': 1, 'baz': 2}, KeysEqual('foo', 'bar')),
-        ]
+    describe_examples = []
+
+    def test_description(self):
+        matchee = {'foo': 0, 'bar': 1, 'baz': 2}
+        mismatch = KeysEqual('foo', 'bar').match(matchee)
+        description = mismatch.describe()
+        self.assertThat(
+            description, Equals(
+                "['bar', 'foo'] does not match %r: Keys not equal"
+                % (matchee,)))
 
 
 class TestSubDictOf(TestCase, TestMatchersInterface):
@@ -91,8 +96,8 @@
         ]
 
     str_examples = [
-        ("MatchesDict({'foo': %s, 'baz': %s})" % (
-                Equals('bar'), Not(Equals('qux'))),
+        ("MatchesDict({'baz': %s, 'foo': %s})" % (
+                Not(Equals('qux')), Equals('bar')),
          matches_matcher),
         ]
 
@@ -144,8 +149,8 @@
         ]
 
     str_examples = [
-        ("ContainsDict({'foo': %s, 'baz': %s})" % (
-                Equals('bar'), Not(Equals('qux'))),
+        ("ContainsDict({'baz': %s, 'foo': %s})" % (
+                Not(Equals('qux')), Equals('bar')),
          matches_matcher),
         ]
 
@@ -190,8 +195,8 @@
         ]
 
     str_examples = [
-        ("ContainedByDict({'foo': %s, 'baz': %s})" % (
-                Equals('bar'), Not(Equals('qux'))),
+        ("ContainedByDict({'baz': %s, 'foo': %s})" % (
+                Not(Equals('qux')), Equals('bar')),
          matches_matcher),
         ]
 

=== modified file 'testtools/tests/test_content_type.py'
--- testtools/tests/test_content_type.py	2012-10-18 15:29:07 +0000
+++ testtools/tests/test_content_type.py	2012-10-19 14:15:26 +0000
@@ -43,7 +43,7 @@
         content_type = ContentType(
             'text', 'plain', {'foo': 'bar', 'baz': 'qux'})
         self.assertThat(
-            repr(content_type), Equals('text/plain; foo="bar", baz="qux"'))
+            repr(content_type), Equals('text/plain; baz="qux", foo="bar"'))
 
 
 class TestBuiltinContentTypes(TestCase):

=== modified file 'testtools/tests/test_testresult.py'
--- testtools/tests/test_testresult.py	2012-07-27 18:53:44 +0000
+++ testtools/tests/test_testresult.py	2012-10-19 14:15:26 +0000
@@ -1471,7 +1471,7 @@
         _u("\u5357\u7121"), # In ISO 2022 encodings
         _u("\xa7\xa7\xa7"), # In ISO 8859 encodings
         )
-    
+
     _is_pypy = "__pypy__" in sys.builtin_module_names
     # Everything but Jython shows syntax errors on the current character
     _error_on_character = os.name != "java" and not _is_pypy
@@ -1574,17 +1574,21 @@
             self.assertNotIn, self._as_output("\a\a\a"), textoutput)
         self.assertIn(self._as_output(_u("\uFFFD\uFFFD\uFFFD")), textoutput)
 
+    def _get_local_os_error(self):
+        if sys.version_info > (3, 3):
+            return "FileExistsError"
+        elif os.name != "nt" or sys.version_info < (2, 5):
+            return "OSError"
+        else:
+            return "WindowsError"
+
     def test_os_error(self):
         """Locale error messages from the OS shouldn't break anything"""
         textoutput = self._test_external_case(
             modulelevel="import os",
             testline="os.mkdir('/')")
-        if sys.version_info > (3, 3):
-            self.assertIn(self._as_output("PermissionError: "), textoutput)
-        elif os.name != "nt" or sys.version_info < (2, 5):
-            self.assertIn(self._as_output("OSError: "), textoutput)
-        else:
-            self.assertIn(self._as_output("WindowsError: "), textoutput)
+        error = self._get_local_os_error()
+        self.assertIn(self._as_output("%s: " % (error,)), textoutput)
 
     def test_assertion_text_shift_jis(self):
         """A terminal raw backslash in an encoded string is weird but fine"""
@@ -1686,7 +1690,11 @@
         finally:
             f.close()
         textoutput = self._run_external_case()
-        self.assertIn(self._as_output("\nSyntaxError: "), textoutput)
+        if sys.version_info > (3, 3):
+            error = 'TypeError'
+        else:
+            error = 'SyntaxError'
+        self.assertIn(self._as_output("\n%s: " % (error,)), textoutput)
 
     def test_syntax_error_line_iso_8859_1(self):
         """Syntax error on a latin-1 line shows the line decoded"""


Follow ups