Changed doctest to run tests in alphabetic order of name.
authorTim Peters <tim.peters@gmail.com>
Wed, 21 Mar 2001 23:07:59 +0000 (23:07 +0000)
committerTim Peters <tim.peters@gmail.com>
Wed, 21 Mar 2001 23:07:59 +0000 (23:07 +0000)
This makes verbose-mode output easier to dig thru, and removes an accidental
dependence on the order of dict.items() (made visible by recent changes to
dictobject.c).

Lib/doctest.py
Lib/test/output/test_difflib
Lib/test/output/test_doctest

index 4e80f10ee2ff27c0f1cef84b7366c4ddcf50c9cb..270e3087e752a5a613887f5898c021311855bebb 100644 (file)
@@ -813,7 +813,12 @@ see its docs for details.
             raise TypeError("Tester.rundict: d must support .items(); " +
                             `d`)
         f = t = 0
-        for thisname, value in d.items():
+        # Run the tests by alpha order of names, for consistency in
+        # verbose-mode output.
+        names = d.keys()
+        names.sort()
+        for thisname in names:
+            value = d[thisname]
             if type(value) in (_FunctionType, _ClassType):
                 f2, t2 = self.__runone(value, name + "." + thisname)
                 f = f + f2
@@ -832,7 +837,12 @@ see its docs for details.
         savepvt = self.isprivate
         try:
             self.isprivate = lambda *args: 0
-            for k, v in d.items():
+            # Run the tests by alpha order of names, for consistency in
+            # verbose-mode output.
+            keys = d.keys()
+            keys.sort()
+            for k in keys:
+                v = d[k]
                 thisname = prefix + k
                 if type(v) is _StringType:
                     f, t = self.runstring(v, thisname)
index 0ea1048ca24551461c312adc2261494c611b299e..cc765b176e337f65809a057fc2dd53c454ee473b 100644 (file)
@@ -156,6 +156,14 @@ Trying: s.find_longest_match(0, 2, 0, 1)
 Expecting: (0, 0, 0)
 ok
 0 of 6 examples failed in difflib.SequenceMatcher.find_longest_match.__doc__
+Running difflib.SequenceMatcher.get_matching_blocks.__doc__
+Trying: s = SequenceMatcher(None, "abxcd", "abcd")
+Expecting: nothing
+ok
+Trying: s.get_matching_blocks()
+Expecting: [(0, 0, 2), (3, 2, 2), (5, 4, 0)]
+ok
+0 of 2 examples failed in difflib.SequenceMatcher.get_matching_blocks.__doc__
 Running difflib.SequenceMatcher.get_opcodes.__doc__
 Trying: a = "qabxcd"
 Expecting: nothing
@@ -180,69 +188,61 @@ ok
 0 of 4 examples failed in difflib.SequenceMatcher.get_opcodes.__doc__
 Running difflib.SequenceMatcher.quick_ratio.__doc__
 0 of 0 examples failed in difflib.SequenceMatcher.quick_ratio.__doc__
-Running difflib.SequenceMatcher.set_seqs.__doc__
-Trying: s = SequenceMatcher()
-Expecting: nothing
-ok
-Trying: s.set_seqs("abcd", "bcde")
+Running difflib.SequenceMatcher.ratio.__doc__
+Trying: s = SequenceMatcher(None, "abcd", "bcde")
 Expecting: nothing
 ok
 Trying: s.ratio()
 Expecting: 0.75
 ok
-0 of 3 examples failed in difflib.SequenceMatcher.set_seqs.__doc__
-Running difflib.SequenceMatcher.set_seq2.__doc__
+Trying: s.quick_ratio()
+Expecting: 0.75
+ok
+Trying: s.real_quick_ratio()
+Expecting: 1.0
+ok
+0 of 4 examples failed in difflib.SequenceMatcher.ratio.__doc__
+Running difflib.SequenceMatcher.real_quick_ratio.__doc__
+0 of 0 examples failed in difflib.SequenceMatcher.real_quick_ratio.__doc__
+Running difflib.SequenceMatcher.set_seq1.__doc__
 Trying: s = SequenceMatcher(None, "abcd", "bcde")
 Expecting: nothing
 ok
 Trying: s.ratio()
 Expecting: 0.75
 ok
-Trying: s.set_seq2("abcd")
+Trying: s.set_seq1("bcde")
 Expecting: nothing
 ok
 Trying: s.ratio()
 Expecting: 1.0
 ok
-0 of 4 examples failed in difflib.SequenceMatcher.set_seq2.__doc__
-Running difflib.SequenceMatcher.set_seq1.__doc__
+0 of 4 examples failed in difflib.SequenceMatcher.set_seq1.__doc__
+Running difflib.SequenceMatcher.set_seq2.__doc__
 Trying: s = SequenceMatcher(None, "abcd", "bcde")
 Expecting: nothing
 ok
 Trying: s.ratio()
 Expecting: 0.75
 ok
-Trying: s.set_seq1("bcde")
+Trying: s.set_seq2("abcd")
 Expecting: nothing
 ok
 Trying: s.ratio()
 Expecting: 1.0
 ok
-0 of 4 examples failed in difflib.SequenceMatcher.set_seq1.__doc__
-Running difflib.SequenceMatcher.get_matching_blocks.__doc__
-Trying: s = SequenceMatcher(None, "abxcd", "abcd")
+0 of 4 examples failed in difflib.SequenceMatcher.set_seq2.__doc__
+Running difflib.SequenceMatcher.set_seqs.__doc__
+Trying: s = SequenceMatcher()
 Expecting: nothing
 ok
-Trying: s.get_matching_blocks()
-Expecting: [(0, 0, 2), (3, 2, 2), (5, 4, 0)]
-ok
-0 of 2 examples failed in difflib.SequenceMatcher.get_matching_blocks.__doc__
-Running difflib.SequenceMatcher.real_quick_ratio.__doc__
-0 of 0 examples failed in difflib.SequenceMatcher.real_quick_ratio.__doc__
-Running difflib.SequenceMatcher.ratio.__doc__
-Trying: s = SequenceMatcher(None, "abcd", "bcde")
+Trying: s.set_seqs("abcd", "bcde")
 Expecting: nothing
 ok
 Trying: s.ratio()
 Expecting: 0.75
 ok
-Trying: s.quick_ratio()
-Expecting: 0.75
-ok
-Trying: s.real_quick_ratio()
-Expecting: 1.0
-ok
-0 of 4 examples failed in difflib.SequenceMatcher.ratio.__doc__
+0 of 3 examples failed in difflib.SequenceMatcher.set_seqs.__doc__
 Running difflib.get_close_matches.__doc__
 Trying: get_close_matches("appel", ["ape", "apple", "peach", "puppy"])
 Expecting: ['apple', 'ape']
index 2a487fb8da849472667d5c8444536a46504e3139..5e54c4aaabe831f2c0145f2ac61b12c1b519bf54 100644 (file)
@@ -88,65 +88,6 @@ ok
 0 of 6 examples failed in doctest.Tester.__doc__
 Running doctest.Tester.__init__.__doc__
 0 of 0 examples failed in doctest.Tester.__init__.__doc__
-Running doctest.Tester.run__test__.__doc__
-0 of 0 examples failed in doctest.Tester.run__test__.__doc__
-Running doctest.Tester.runstring.__doc__
-Trying: t = Tester(globs={}, verbose=1)
-Expecting: nothing
-ok
-Trying:
-test = r'''
-   # just an example
-   >>> x = 1 + 2
-   >>> x
-   3
-'''
-Expecting: nothing
-ok
-Trying: t.runstring(test, "Example")
-Expecting:
-Running string Example
-Trying: x = 1 + 2
-Expecting: nothing
-ok
-Trying: x
-Expecting: 3
-ok
-0 of 2 examples failed in string Example
-(0, 2)
-ok
-0 of 3 examples failed in doctest.Tester.runstring.__doc__
-Running doctest.Tester.summarize.__doc__
-0 of 0 examples failed in doctest.Tester.summarize.__doc__
-Running doctest.Tester.rundict.__doc__
-Trying:
-def _f():
-   '''>>> assert 1 == 1
-   '''
-Expecting: nothing
-ok
-Trying:
-def g():
-   '''>>> assert 2 != 1
-   '''
-Expecting: nothing
-ok
-Trying: d = {"_f": _f, "g": g}
-Expecting: nothing
-ok
-Trying: t = Tester(globs={}, verbose=0)
-Expecting: nothing
-ok
-Trying: t.rundict(d, "rundict_test")  # _f is skipped
-Expecting: (0, 1)
-ok
-Trying: t = Tester(globs={}, verbose=0, isprivate=lambda x,y: 0)
-Expecting: nothing
-ok
-Trying: t.rundict(d, "rundict_test_pvt")  # both are searched
-Expecting: (0, 2)
-ok
-0 of 7 examples failed in doctest.Tester.rundict.__doc__
 Running doctest.Tester.merge.__doc__
 Trying: from doctest import Tester
 Expecting: nothing
@@ -197,6 +138,37 @@ Test passed.
 (0, 6)
 ok
 0 of 10 examples failed in doctest.Tester.merge.__doc__
+Running doctest.Tester.run__test__.__doc__
+0 of 0 examples failed in doctest.Tester.run__test__.__doc__
+Running doctest.Tester.rundict.__doc__
+Trying:
+def _f():
+   '''>>> assert 1 == 1
+   '''
+Expecting: nothing
+ok
+Trying:
+def g():
+   '''>>> assert 2 != 1
+   '''
+Expecting: nothing
+ok
+Trying: d = {"_f": _f, "g": g}
+Expecting: nothing
+ok
+Trying: t = Tester(globs={}, verbose=0)
+Expecting: nothing
+ok
+Trying: t.rundict(d, "rundict_test")  # _f is skipped
+Expecting: (0, 1)
+ok
+Trying: t = Tester(globs={}, verbose=0, isprivate=lambda x,y: 0)
+Expecting: nothing
+ok
+Trying: t.rundict(d, "rundict_test_pvt")  # both are searched
+Expecting: (0, 2)
+ok
+0 of 7 examples failed in doctest.Tester.rundict.__doc__
 Running doctest.Tester.rundoc.__doc__
 Trying: t = Tester(globs={}, verbose=0)
 Expecting: nothing
@@ -213,6 +185,34 @@ Trying: t.rundoc(_f)  # expect 0 failures in 1 example
 Expecting: (0, 1)
 ok
 0 of 3 examples failed in doctest.Tester.rundoc.__doc__
+Running doctest.Tester.runstring.__doc__
+Trying: t = Tester(globs={}, verbose=1)
+Expecting: nothing
+ok
+Trying:
+test = r'''
+   # just an example
+   >>> x = 1 + 2
+   >>> x
+   3
+'''
+Expecting: nothing
+ok
+Trying: t.runstring(test, "Example")
+Expecting:
+Running string Example
+Trying: x = 1 + 2
+Expecting: nothing
+ok
+Trying: x
+Expecting: 3
+ok
+0 of 2 examples failed in string Example
+(0, 2)
+ok
+0 of 3 examples failed in doctest.Tester.runstring.__doc__
+Running doctest.Tester.summarize.__doc__
+0 of 0 examples failed in doctest.Tester.summarize.__doc__
 Running doctest.is_private.__doc__
 Trying: is_private("a.b", "my_func")
 Expecting: 0
@@ -248,14 +248,6 @@ Trying: hex(_TestClass(13).square().get())
 Expecting: '0xa9'
 ok
 0 of 2 examples failed in doctest.__test__._TestClass.__doc__
-Running doctest.__test__._TestClass.get.__doc__
-Trying: x = _TestClass(-42)
-Expecting: nothing
-ok
-Trying: print x.get()
-Expecting: -42
-ok
-0 of 2 examples failed in doctest.__test__._TestClass.get.__doc__
 Running doctest.__test__._TestClass.__init__.__doc__
 Trying: t = _TestClass(123)
 Expecting: nothing
@@ -264,6 +256,14 @@ Trying: print t.get()
 Expecting: 123
 ok
 0 of 2 examples failed in doctest.__test__._TestClass.__init__.__doc__
+Running doctest.__test__._TestClass.get.__doc__
+Trying: x = _TestClass(-42)
+Expecting: nothing
+ok
+Trying: print x.get()
+Expecting: -42
+ok
+0 of 2 examples failed in doctest.__test__._TestClass.get.__doc__
 Running doctest.__test__._TestClass.square.__doc__
 Trying: _TestClass(13).square().get()
 Expecting: 169