PY-7856: Provide "actual" and "expected" for DocTest runner

This commit is contained in:
Ilya.Kazakevich
2017-02-08 23:02:07 +03:00
parent c0e94ad6bb
commit b9d24eedeb
3 changed files with 40 additions and 4 deletions

View File

@@ -61,8 +61,8 @@ class TeamcityDocTestResult(TeamcityTestResult):
def stopSuite(self, suite):
self.messages.testSuiteFinished(suite.name)
def addFailure(self, test, err = ''):
self.messages.testFailed(self.getTestName(test),
def addFailure(self, test, err = '', expected=None, actual=None):
self.messages.testFailed(self.getTestName(test), expected=expected, actual=actual,
message='Failure', details=err, duration=int(self.__getDuration(test)))
def addError(self, test, err = ''):
@@ -180,7 +180,12 @@ class DocTestRunner(doctest.DocTestRunner):
self.result.startTest(example)
err = self._failure_header(test, example) +\
self._checker.output_difference(example, got, self.optionflags)
self.result.addFailure(example, err)
expected = None
try:
expected = example.want
except KeyError:
pass
self.result.addFailure(example, err, expected=expected, actual=got)
elif outcome is BOOM:
self.result.startTest(example)

View File

@@ -0,0 +1,8 @@
def test_dff():
"""
>>> 1 + 1
> 3
"""
pass

View File

@@ -5,7 +5,9 @@ import com.jetbrains.env.PyProcessWithConsoleTestTask;
import com.jetbrains.env.ut.PyDocTestProcessRunner;
import com.jetbrains.python.sdkTools.SdkCreationType;
import com.jetbrains.python.testing.doctest.PythonDocTestRunConfiguration;
import org.hamcrest.Matchers;
import org.jetbrains.annotations.NotNull;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -13,7 +15,7 @@ import static org.junit.Assert.assertEquals;
/**
* User : catherine
*/
public class PythonDocTestingTest extends PyEnvTestCase {
public final class PythonDocTestingTest extends PyEnvTestCase {
@Test
@@ -63,6 +65,27 @@ public class PythonDocTestingTest extends PyEnvTestCase {
});
}
@Test
public void testDiff() throws Exception {
runPythonTest(new PyProcessWithConsoleTestTask<PyDocTestProcessRunner>("/testRunner/env/doc", SdkCreationType.EMPTY_SDK) {
@NotNull
@Override
protected PyDocTestProcessRunner createProcessRunner() throws Exception {
return new PyDocTestProcessRunner("test_Diff.py::test_dff", 0);
}
@Override
protected void checkTestResults(@NotNull final PyDocTestProcessRunner runner,
@NotNull final String stdout,
@NotNull final String stderr,
@NotNull final String all) {
Assert.assertThat("No diff link", runner.getConsole().getText(), Matchers.containsString(" <Click to see difference>"));
Assert.assertThat("Wrong actual", runner.getConsole().getText(), Matchers.containsString("Actual :2"));
Assert.assertThat("Wrong expected", runner.getConsole().getText(), Matchers.containsString("Expected :> 3"));
}
});
}
@Test
public void testMethod() {
runPythonTest(new PyProcessWithConsoleTestTask<PyDocTestProcessRunner>("/testRunner/env/doc", SdkCreationType.EMPTY_SDK) {