Skip to content

Commit 1a33025

Browse files
committed
Refactors test to be in its own class, as discussed with @nicoddemus.
1 parent 922a295 commit 1a33025

File tree

1 file changed

+81
-79
lines changed

1 file changed

+81
-79
lines changed

testing/test_doctest.py

Lines changed: 81 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -475,85 +475,6 @@ def foo():
475475
"--junit-xml=junit.xml")
476476
reprec.assertoutcome(failed=1)
477477

478-
def _run_doctest_report(self, testdir, format):
479-
testdir.makepyfile("""
480-
def foo():
481-
'''
482-
>>> foo()
483-
a b
484-
0 1 4
485-
1 2 4
486-
2 3 6
487-
'''
488-
print(' a b\\n'
489-
'0 1 4\\n'
490-
'1 2 5\\n'
491-
'2 3 6')
492-
""")
493-
return testdir.runpytest("--doctest-modules", "--doctest-report", format)
494-
495-
def test_doctest_report_udiff(self, testdir, format='udiff'):
496-
result = self._run_doctest_report(testdir, format)
497-
result.stdout.fnmatch_lines([
498-
' 0 1 4',
499-
' -1 2 4',
500-
' +1 2 5',
501-
' 2 3 6',
502-
])
503-
504-
def test_doctest_report_cdiff(self, testdir):
505-
result = self._run_doctest_report(testdir, 'cdiff')
506-
result.stdout.fnmatch_lines([
507-
' a b',
508-
' 0 1 4',
509-
' ! 1 2 4',
510-
' 2 3 6',
511-
' --- 1,4 ----',
512-
' a b',
513-
' 0 1 4',
514-
' ! 1 2 5',
515-
' 2 3 6',
516-
])
517-
518-
def test_doctest_report_ndiff(self, testdir):
519-
result = self._run_doctest_report(testdir, 'ndiff')
520-
result.stdout.fnmatch_lines([
521-
' a b',
522-
' 0 1 4',
523-
' - 1 2 4',
524-
' ? ^',
525-
' + 1 2 5',
526-
' ? ^',
527-
' 2 3 6',
528-
])
529-
530-
def test_doctest_report_none_or_only_first_failure(self, testdir):
531-
for format in 'none', 'only_first_failure':
532-
result = self._run_doctest_report(testdir, format)
533-
result.stdout.fnmatch_lines([
534-
'Expected:',
535-
' a b',
536-
' 0 1 4',
537-
' 1 2 4',
538-
' 2 3 6',
539-
'Got:',
540-
' a b',
541-
' 0 1 4',
542-
' 1 2 5',
543-
' 2 3 6',
544-
])
545-
546-
def test_doctest_report_case_insensitive(self, testdir):
547-
for format in 'udiff', 'UDIFF', 'uDiFf':
548-
self.test_doctest_report_udiff(testdir, format)
549-
550-
def test_doctest_report_invalid(self, testdir):
551-
result = self._run_doctest_report(testdir, 'obviously_invalid_format')
552-
result.stderr.fnmatch_lines([
553-
"*error: argument --doctest-report: invalid choice: 'obviously_invalid_format' (choose from*"
554-
])
555-
556-
557478

558479
class TestLiterals:
559480

@@ -863,3 +784,84 @@ def foo():
863784
""")
864785
reprec = testdir.inline_run(p, "--doctest-modules")
865786
reprec.assertoutcome(passed=1)
787+
788+
789+
class TestDoctestReportingOption:
790+
def _run_doctest_report(self, testdir, format):
791+
testdir.makepyfile("""
792+
def foo():
793+
'''
794+
>>> foo()
795+
a b
796+
0 1 4
797+
1 2 4
798+
2 3 6
799+
'''
800+
print(' a b\\n'
801+
'0 1 4\\n'
802+
'1 2 5\\n'
803+
'2 3 6')
804+
""")
805+
return testdir.runpytest("--doctest-modules", "--doctest-report", format)
806+
807+
def test_doctest_report_udiff(self, testdir, format='udiff'):
808+
result = self._run_doctest_report(testdir, format)
809+
result.stdout.fnmatch_lines([
810+
' 0 1 4',
811+
' -1 2 4',
812+
' +1 2 5',
813+
' 2 3 6',
814+
])
815+
816+
def test_doctest_report_cdiff(self, testdir):
817+
result = self._run_doctest_report(testdir, 'cdiff')
818+
result.stdout.fnmatch_lines([
819+
' a b',
820+
' 0 1 4',
821+
' ! 1 2 4',
822+
' 2 3 6',
823+
' --- 1,4 ----',
824+
' a b',
825+
' 0 1 4',
826+
' ! 1 2 5',
827+
' 2 3 6',
828+
])
829+
830+
def test_doctest_report_ndiff(self, testdir):
831+
result = self._run_doctest_report(testdir, 'ndiff')
832+
result.stdout.fnmatch_lines([
833+
' a b',
834+
' 0 1 4',
835+
' - 1 2 4',
836+
' ? ^',
837+
' + 1 2 5',
838+
' ? ^',
839+
' 2 3 6',
840+
])
841+
842+
def test_doctest_report_none_or_only_first_failure(self, testdir):
843+
for format in 'none', 'only_first_failure':
844+
result = self._run_doctest_report(testdir, format)
845+
result.stdout.fnmatch_lines([
846+
'Expected:',
847+
' a b',
848+
' 0 1 4',
849+
' 1 2 4',
850+
' 2 3 6',
851+
'Got:',
852+
' a b',
853+
' 0 1 4',
854+
' 1 2 5',
855+
' 2 3 6',
856+
])
857+
858+
def test_doctest_report_case_insensitive(self, testdir):
859+
for format in 'udiff', 'UDIFF', 'uDiFf':
860+
self.test_doctest_report_udiff(testdir, format)
861+
862+
def test_doctest_report_invalid(self, testdir):
863+
result = self._run_doctest_report(testdir, 'obviously_invalid_format')
864+
result.stderr.fnmatch_lines([
865+
"*error: argument --doctest-report: invalid choice: 'obviously_invalid_format' (choose from*"
866+
])
867+

0 commit comments

Comments
 (0)