("Forward-port" of r46506)
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...
diff --git a/Lib/test/test_csv.py b/Lib/test/test_csv.py
index 8511a5a..feb6ddf 100644
--- a/Lib/test/test_csv.py
+++ b/Lib/test/test_csv.py
@@ -875,7 +875,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="/,")
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
index 635d156..4b631dd 100644
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -766,7 +766,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)
...
diff --git a/Lib/test/test_optparse.py b/Lib/test/test_optparse.py
index 991c06d..79df906 100644
--- a/Lib/test/test_optparse.py
+++ b/Lib/test/test_optparse.py
@@ -230,7 +230,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):
@@ -718,9 +718,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):
@@ -1537,10 +1536,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?)")
class TestParseNumber(BaseTest):
diff --git a/Lib/test/test_urllib2.py b/Lib/test/test_urllib2.py
index c8f19bc..9203e37 100644
--- a/Lib/test/test_urllib2.py
+++ b/Lib/test/test_urllib2.py
@@ -560,6 +560,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:
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index 392e5fa..18ab401 100644
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -1053,8 +1053,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: