From 1ed78df61ebe32f6d1edac490e5d07e8c0558451 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Tue, 18 Aug 2015 20:02:58 -0500 Subject: [PATCH] Add a regression test for EPIPE IOErrors This should prevent bug 69 from regressing in the future and provides a framework for testing the addition of new errnos to the ingore list. --- flake8/tests/test_reporter.py | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 flake8/tests/test_reporter.py diff --git a/flake8/tests/test_reporter.py b/flake8/tests/test_reporter.py new file mode 100644 index 0000000..f91bb52 --- /dev/null +++ b/flake8/tests/test_reporter.py @@ -0,0 +1,36 @@ +from __future__ import with_statement + +import errno +import unittest +try: + from unittest import mock +except ImportError: + import mock # < PY33 + +from flake8 import reporter + + +def ioerror_report_factory(errno_code): + class IOErrorBaseQReport(reporter.BaseQReport): + def _process_main(self): + raise IOError(errno_code, 'Fake bad pipe exception') + + options = mock.MagicMock() + options.jobs = 2 + return IOErrorBaseQReport(options) + + +class TestBaseQReport(unittest.TestCase): + def test_does_not_raise_a_bad_pipe_ioerror(self): + """Test that no EPIPE IOError exception is re-raised or leaked.""" + report = ioerror_report_factory(errno.EPIPE) + try: + report.process_main() + except IOError: + self.fail('BaseQReport.process_main raised an IOError for EPIPE' + ' but it should have caught this exception.') + + def test_raises_a_enoent_ioerror(self): + """Test that an ENOENT IOError exception is re-raised.""" + report = ioerror_report_factory(errno.ENOENT) + self.assertRaises(IOError, report.process_main)