Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(15)

Side by Side Diff: Lib/doctest.py

Issue 767: [issue2630] repr() should not escape non-ASCII characters (Closed) SVN Base: http://svn.python.org/view/*checkout*/python/branches/py3k/
Patch Set: Created 1 year, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Module doctest. 1 # Module doctest.
2 # Released to the public domain 16-Jan-2001, by Tim Peters (tim@python.org). 2 # Released to the public domain 16-Jan-2001, by Tim Peters (tim@python.org).
3 # Major enhancements and refactoring by: 3 # Major enhancements and refactoring by:
4 # Jim Fulton 4 # Jim Fulton
5 # Edward Loper 5 # Edward Loper
6 6
7 # Provided as-is; use at your own risk; no warranty; no promises; enjoy! 7 # Provided as-is; use at your own risk; no warranty; no promises; enjoy!
8 8
9 r"""Module doctest -- a framework for running examples in docstrings. 9 r"""Module doctest -- a framework for running examples in docstrings.
10 10
(...skipping 1426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1437 d[name] = f, t 1437 d[name] = f, t
1438 1438
1439 class OutputChecker: 1439 class OutputChecker:
1440 """ 1440 """
1441 A class used to check the whether the actual output from a doctest 1441 A class used to check the whether the actual output from a doctest
1442 example matches the expected output. `OutputChecker` defines two 1442 example matches the expected output. `OutputChecker` defines two
1443 methods: `check_output`, which compares a given pair of outputs, 1443 methods: `check_output`, which compares a given pair of outputs,
1444 and returns true if they match; and `output_difference`, which 1444 and returns true if they match; and `output_difference`, which
1445 returns a string describing the differences between two outputs. 1445 returns a string describing the differences between two outputs.
1446 """ 1446 """
1447
1448 def _toAscii(self, s):
1449 """
1450 Convert string to hex-escaped ASCII string.
1451 """
1452 return str(s.encode('ASCII', 'backslashreplace'), "ASCII")
1453
1447 def check_output(self, want, got, optionflags): 1454 def check_output(self, want, got, optionflags):
1448 """ 1455 """
1449 Return True iff the actual output from an example (`got`) 1456 Return True iff the actual output from an example (`got`)
1450 matches the expected output (`want`). These strings are 1457 matches the expected output (`want`). These strings are
1451 always considered to match if they are identical; but 1458 always considered to match if they are identical; but
1452 depending on what option flags the test runner is using, 1459 depending on what option flags the test runner is using,
1453 several non-exact match types are also possible. See the 1460 several non-exact match types are also possible. See the
1454 documentation for `TestRunner` for more information about 1461 documentation for `TestRunner` for more information about
1455 option flags. 1462 option flags.
1456 """ 1463 """
1464
1465 # If `want` contains hex-escaped character such as "\u1234",
1466 # then `want` is a string of six characters(e.g. [\,u,1,2,3,4]).
1467 # On the other hand, `got` could be an another sequence of
1468 # characters such as [\u1234], so `want` and `got` should
1469 # be folded to hex-escaped ASCII string to compare.
1470 got = self._toAscii(got)
1471 want = self._toAscii(want)
1472
1457 # Handle the common case first, for efficiency: 1473 # Handle the common case first, for efficiency:
1458 # if they're string-identical, always return true. 1474 # if they're string-identical, always return true.
1459 if got == want: 1475 if got == want:
1460 return True 1476 return True
1461 1477
1462 # The values True and False replaced 1 and 0 as the return 1478 # The values True and False replaced 1 and 0 as the return
1463 # value for boolean comparisons in Python 2.3. 1479 # value for boolean comparisons in Python 2.3.
1464 if not (optionflags & DONT_ACCEPT_TRUE_FOR_1): 1480 if not (optionflags & DONT_ACCEPT_TRUE_FOR_1):
1465 if (got,want) == ("True\n", "1\n"): 1481 if (got,want) == ("True\n", "1\n"):
1466 return True 1482 return True
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after
2659 failures, _ = testfile(filename, module_relative=False) 2675 failures, _ = testfile(filename, module_relative=False)
2660 if failures: 2676 if failures:
2661 return 1 2677 return 1
2662 else: 2678 else:
2663 r = unittest.TextTestRunner() 2679 r = unittest.TextTestRunner()
2664 r.run(DocTestSuite()) 2680 r.run(DocTestSuite())
2665 return 0 2681 return 0
2666 2682
2667 if __name__ == "__main__": 2683 if __name__ == "__main__":
2668 sys.exit(_test()) 2684 sys.exit(_test())
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497