]> granicus.if.org Git - python/commitdiff
("Forward-port" of r46506)
authorArmin Rigo <arigo@tunes.org>
Sun, 28 May 2006 19:13:17 +0000 (19:13 +0000)
committerArmin Rigo <arigo@tunes.org>
Sun, 28 May 2006 19:13:17 +0000 (19:13 +0000)
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.

Remaining open issues:
 * test_extcall is an output test, messy to make robust
 * tarfile.py has a potential bug here, but I'm not familiar
   enough with this code.  Filed in as SF bug #1496501.
 * urllib2.HTTPPasswordMgr() returns a random result if there is more
   than one matching root path.  I'm asking python-dev for
   clarification...

Lib/base64.py
Lib/doctest.py
Lib/optparse.py
Lib/test/test_csv.py
Lib/test/test_itertools.py
Lib/test/test_optparse.py
Lib/test/test_urllib2.py
Lib/test/test_weakref.py

index 8914acce92324a2df827e5d45288565b091d8f00..c196cd8a841b5c8c71339938e16bd02beccca7ef 100755 (executable)
@@ -126,7 +126,9 @@ _b32alphabet = {
     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()])
 
 
index 971ec6cc4c108bdf4edf1f08079d46ce620a558c..b87df7c4835f9c9375bfbc4efd4fe6d95f3db333 100644 (file)
@@ -1056,12 +1056,13 @@ class DocTestRunner:
 
         >>> 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)`
index 9ac987e819c46de420987d235a374dd10d5671fd..6b8f5d10b8dfa7a6c8c3ff62eb757b555d9488a2 100644 (file)
@@ -611,8 +611,10 @@ class Option:
                 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)
 
 
@@ -1661,6 +1663,7 @@ def _match_abbrev(s, wordmap):
             raise BadOptionError(s)
         else:
             # More than one possible completion: ambiguous prefix.
+            possibilities.sort()
             raise AmbiguousOptionError(s, possibilities)
 
 
index 8511a5ae97dfb28bcd9aeaf7dabf904c009a0739..feb6ddf61398dca62be5360a0a458a232f0da892 100644 (file)
@@ -875,7 +875,10 @@ Stonecutters Seafood and Chop House, Lemont, IL, 12/19/02, Week Back
     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="/,")
index 635d1563760d6697cd12e90f1197cfa14ad28162..4b631dda4809643e56018648a05e65f39b0bc6ab 100644 (file)
@@ -766,7 +766,7 @@ Samuele
 
 >>> 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)
 ...
index 991c06d44773e48719e439d454c012ab66fcbc42..79df9066e2c4d36e2556a468166e7d7e20498740 100644 (file)
@@ -230,7 +230,7 @@ class TestOptionChecks(BaseTest):
 
     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):
@@ -718,9 +718,8 @@ class TestStandard(BaseTest):
     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):
@@ -1537,10 +1536,9 @@ class TestMatchAbbrev(BaseTest):
     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?)")
 
 
 class TestParseNumber(BaseTest):
index c8f19bcab02aea22407791a7bb64ccdf8bab18ae..9203e37fb6a809e43a97234bf85c71fb15e2dd21 100644 (file)
@@ -560,6 +560,7 @@ class HandlerTests(unittest.TestCase):
                 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:
index 392e5fa34b9b7ef957ab8ffaabc03f86bab33c43..18ab4012fb7f57fba0aedc1f0595950e8c8a79f5 100644 (file)
@@ -1053,8 +1053,8 @@ libreftest = """ Doctest for examples in the library reference: libweakref.tex
 ...
 >>> 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: