[Python-checkins] r46506 - in python/branches/release24-maint/Lib: base64.py doctest.py optparse.py test/test_csv.py test/test_itertools.py test/test_optparse.py test/test_urllib2.py test/test_weakref.py

armin.rigo python-checkins at python.org
Sun May 28 20:15:45 CEST 2006


Author: armin.rigo
Date: Sun May 28 20:15:43 2006
New Revision: 46506

Modified:
   python/branches/release24-maint/Lib/base64.py
   python/branches/release24-maint/Lib/doctest.py
   python/branches/release24-maint/Lib/optparse.py
   python/branches/release24-maint/Lib/test/test_csv.py
   python/branches/release24-maint/Lib/test/test_itertools.py
   python/branches/release24-maint/Lib/test/test_optparse.py
   python/branches/release24-maint/Lib/test/test_urllib2.py
   python/branches/release24-maint/Lib/test/test_weakref.py
Log:
Remove various dependencies on dictionary order in the standard library
tests, and one (clearly an oversight, potentially critical) in the
standard library itself - base64.py.

test_extcall is an output test which still needs to be fixed somehow.

Forwardporting candidate...


Modified: python/branches/release24-maint/Lib/base64.py
==============================================================================
--- python/branches/release24-maint/Lib/base64.py	(original)
+++ python/branches/release24-maint/Lib/base64.py	Sun May 28 20:15:43 2006
@@ -126,7 +126,9 @@
     8: 'I', 17: 'R', 26: '2',
     }
 
-_b32tab = [v for v in _b32alphabet.values()]
+_b32tab = _b32alphabet.items()
+_b32tab.sort()
+_b32tab = [v for k, v in _b32tab]
 _b32rev = dict([(v, long(k)) for k, v in _b32alphabet.items()])
 
 

Modified: python/branches/release24-maint/Lib/doctest.py
==============================================================================
--- python/branches/release24-maint/Lib/doctest.py	(original)
+++ python/branches/release24-maint/Lib/doctest.py	Sun May 28 20:15:43 2006
@@ -1044,12 +1044,13 @@
 
         >>> tests = DocTestFinder().find(_TestClass)
         >>> runner = DocTestRunner(verbose=False)
+        >>> tests.sort(key = lambda test: test.name)
         >>> for test in tests:
-        ...     print runner.run(test)
-        (0, 2)
-        (0, 1)
-        (0, 2)
-        (0, 2)
+        ...     print test.name, '->', runner.run(test)
+        _TestClass -> (0, 2)
+        _TestClass.__init__ -> (0, 2)
+        _TestClass.get -> (0, 2)
+        _TestClass.square -> (0, 1)
 
     The `summarize` method prints a summary of all the test cases that
     have been run by the runner, and returns an aggregated `(f, t)`

Modified: python/branches/release24-maint/Lib/optparse.py
==============================================================================
--- python/branches/release24-maint/Lib/optparse.py	(original)
+++ python/branches/release24-maint/Lib/optparse.py	Sun May 28 20:15:43 2006
@@ -547,8 +547,10 @@
                 else:
                     setattr(self, attr, None)
         if attrs:
+            attrs = attrs.keys()
+            attrs.sort()
             raise OptionError(
-                "invalid keyword arguments: %s" % ", ".join(attrs.keys()),
+                "invalid keyword arguments: %s" % ", ".join(attrs),
                 self)
 
 
@@ -1556,6 +1558,7 @@
             raise BadOptionError(_("no such option: %s") % s)
         else:
             # More than one possible completion: ambiguous prefix.
+            possibilities.sort()
             raise BadOptionError(_("ambiguous option: %s (%s?)")
                                  % (s, ", ".join(possibilities)))
 

Modified: python/branches/release24-maint/Lib/test/test_csv.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_csv.py	(original)
+++ python/branches/release24-maint/Lib/test/test_csv.py	Sun May 28 20:15:43 2006
@@ -760,7 +760,10 @@
     def test_delimiters(self):
         sniffer = csv.Sniffer()
         dialect = sniffer.sniff(self.sample3)
-        self.assertEqual(dialect.delimiter, "0")
+        # given that all three lines in sample3 are equal,
+        # I think that any character could have been 'guessed' as the
+        # delimiter, depending on dictionary order
+        self.assert_(dialect.delimiter in self.sample3)
         dialect = sniffer.sniff(self.sample3, delimiters="?,")
         self.assertEqual(dialect.delimiter, "?")
         dialect = sniffer.sniff(self.sample3, delimiters="/,")

Modified: python/branches/release24-maint/Lib/test/test_itertools.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_itertools.py	(original)
+++ python/branches/release24-maint/Lib/test/test_itertools.py	Sun May 28 20:15:43 2006
@@ -758,7 +758,7 @@
 
 >>> from operator import itemgetter
 >>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3)
->>> di = sorted(d.iteritems(), key=itemgetter(1))
+>>> di = sorted(sorted(d.iteritems()), key=itemgetter(1))
 >>> for k, g in groupby(di, itemgetter(1)):
 ...     print k, map(itemgetter(0), g)
 ...

Modified: python/branches/release24-maint/Lib/test/test_optparse.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_optparse.py	(original)
+++ python/branches/release24-maint/Lib/test/test_optparse.py	Sun May 28 20:15:43 2006
@@ -212,7 +212,7 @@
 
     def test_attr_invalid(self):
         self.assertOptionError(
-            "option -b: invalid keyword arguments: foo, bar",
+            "option -b: invalid keyword arguments: bar, foo",
             ["-b"], {'foo': None, 'bar': None})
 
     def test_action_invalid(self):
@@ -675,9 +675,8 @@
     def test_ambiguous_option(self):
         self.parser.add_option("--foz", action="store",
                                type="string", dest="foo")
-        possibilities = ", ".join({"--foz": None, "--foo": None}.keys())
         self.assertParseFail(["--f=bar"],
-                             "ambiguous option: --f (%s?)" % possibilities)
+                             "ambiguous option: --f (--foo, --foz?)")
 
 
     def test_short_and_long_option_split(self):
@@ -1477,10 +1476,9 @@
     def test_match_abbrev_error(self):
         s = "--f"
         wordmap = {"--foz": None, "--foo": None, "--fie": None}
-        possibilities = ", ".join(wordmap.keys())
         self.assertRaises(
             _match_abbrev, (s, wordmap), None,
-            BadOptionError, "ambiguous option: --f (%s?)" % possibilities)
+            BadOptionError, "ambiguous option: --f (--fie, --foo, --foz?)")
 
 
 def _testclasses():

Modified: python/branches/release24-maint/Lib/test/test_urllib2.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_urllib2.py	(original)
+++ python/branches/release24-maint/Lib/test/test_urllib2.py	Sun May 28 20:15:43 2006
@@ -447,6 +447,7 @@
                 self.method = method
                 self.selector = url
                 self.req_headers += headers.items()
+                self.req_headers.sort()
                 if body:
                     self.data = body
                 if self.raise_on_endheaders:

Modified: python/branches/release24-maint/Lib/test/test_weakref.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_weakref.py	(original)
+++ python/branches/release24-maint/Lib/test/test_weakref.py	Sun May 28 20:15:43 2006
@@ -1009,8 +1009,8 @@
 ...
 >>> obj = Dict(red=1, green=2, blue=3)   # this object is weak referencable
 >>> r = weakref.ref(obj)
->>> print r()
-{'blue': 3, 'green': 2, 'red': 1}
+>>> print r() is obj
+True
 
 >>> import weakref
 >>> class Object:


More information about the Python-checkins mailing list