Merge pull request #6071 from blueyed/tests-doctest-mock
Tests: approx: mock doctest runner's pdb usage
This commit is contained in:
		
						commit
						0485b07ff0
					
				| 
						 | 
					@ -1,4 +1,3 @@
 | 
				
			||||||
import doctest
 | 
					 | 
				
			||||||
import operator
 | 
					import operator
 | 
				
			||||||
from decimal import Decimal
 | 
					from decimal import Decimal
 | 
				
			||||||
from fractions import Fraction
 | 
					from fractions import Fraction
 | 
				
			||||||
| 
						 | 
					@ -11,10 +10,26 @@ from pytest import approx
 | 
				
			||||||
inf, nan = float("inf"), float("nan")
 | 
					inf, nan = float("inf"), float("nan")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MyDocTestRunner(doctest.DocTestRunner):
 | 
					@pytest.fixture
 | 
				
			||||||
    def __init__(self):
 | 
					def mocked_doctest_runner(monkeypatch):
 | 
				
			||||||
        doctest.DocTestRunner.__init__(self)
 | 
					    import doctest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class MockedPdb:
 | 
				
			||||||
 | 
					        def __init__(self, out):
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        def set_trace(self):
 | 
				
			||||||
 | 
					            raise NotImplementedError("not used")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        def reset(self):
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        def set_continue(self):
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    monkeypatch.setattr("doctest._OutputRedirectingPdb", MockedPdb)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class MyDocTestRunner(doctest.DocTestRunner):
 | 
				
			||||||
        def report_failure(self, out, test, example, got):
 | 
					        def report_failure(self, out, test, example, got):
 | 
				
			||||||
            raise AssertionError(
 | 
					            raise AssertionError(
 | 
				
			||||||
                "'{}' evaluates to '{}', not '{}'".format(
 | 
					                "'{}' evaluates to '{}', not '{}'".format(
 | 
				
			||||||
| 
						 | 
					@ -22,6 +37,8 @@ class MyDocTestRunner(doctest.DocTestRunner):
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
            )
 | 
					            )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return MyDocTestRunner()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class TestApprox:
 | 
					class TestApprox:
 | 
				
			||||||
    def test_repr_string(self):
 | 
					    def test_repr_string(self):
 | 
				
			||||||
| 
						 | 
					@ -411,13 +428,14 @@ class TestApprox:
 | 
				
			||||||
        assert a12 != approx(a21)
 | 
					        assert a12 != approx(a21)
 | 
				
			||||||
        assert a21 != approx(a12)
 | 
					        assert a21 != approx(a12)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_doctests(self):
 | 
					    def test_doctests(self, mocked_doctest_runner):
 | 
				
			||||||
 | 
					        import doctest
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        parser = doctest.DocTestParser()
 | 
					        parser = doctest.DocTestParser()
 | 
				
			||||||
        test = parser.get_doctest(
 | 
					        test = parser.get_doctest(
 | 
				
			||||||
            approx.__doc__, {"approx": approx}, approx.__name__, None, None
 | 
					            approx.__doc__, {"approx": approx}, approx.__name__, None, None
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        runner = MyDocTestRunner()
 | 
					        mocked_doctest_runner.run(test)
 | 
				
			||||||
        runner.run(test)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_unicode_plus_minus(self, testdir):
 | 
					    def test_unicode_plus_minus(self, testdir):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue