summaryrefslogtreecommitdiff
path: root/flake8/tests
diff options
context:
space:
mode:
authorJoe Gordon <joe.gordon0@gmail.com>2014-10-13 21:42:32 -0700
committerJoe Gordon <joe.gordon0@gmail.com>2014-10-31 20:45:59 -0700
commit8b4bbd23bf37fb946b664f5932e4903f802c6e0d (patch)
tree4246c7b1b8a624d5f1bbf4b1bb6230df70122e33 /flake8/tests
parent247877b7c57d101d32c9c5560910c7609afb3e7b (diff)
downloadflake8-8b4bbd23bf37fb946b664f5932e4903f802c6e0d.tar.gz
Add first pass at integration style tests
In order to better prevent regressions (such as related to concurrency), Add a integration test framework to simulate running flake8 with arguments.
Diffstat (limited to 'flake8/tests')
-rw-r--r--flake8/tests/test_integration.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/flake8/tests/test_integration.py b/flake8/tests/test_integration.py
new file mode 100644
index 0000000..55ace48
--- /dev/null
+++ b/flake8/tests/test_integration.py
@@ -0,0 +1,71 @@
+from __future__ import with_statement
+
+import os
+import unittest
+try:
+ from unittest import mock
+except ImportError:
+ import mock # < PY33
+
+from flake8 import engine
+
+
+class IntegrationTestCase(unittest.TestCase):
+ """Integration style tests to exercise different command line options."""
+
+ def this_file(self):
+ """Return the real path of this file."""
+ this_file = os.path.realpath(__file__)
+ if this_file.endswith("pyc"):
+ this_file = this_file[:-1]
+ return this_file
+
+ def check_files(self, arglist=[], explicit_stdin=False, count=0):
+ """Call check_files."""
+ if explicit_stdin:
+ target_file = "-"
+ else:
+ target_file = self.this_file()
+ argv = ['flake8'] + arglist + [target_file]
+ with mock.patch("sys.argv", argv):
+ style_guide = engine.get_style_guide(parse_argv=True)
+ report = style_guide.check_files()
+ self.assertEqual(report.total_errors, count)
+ return style_guide, report
+
+ def test_no_args(self):
+ # assert there are no reported errors
+ self.check_files()
+
+ def _job_tester(self, jobs):
+ # mock stdout.flush so we can count the number of jobs created
+ with mock.patch('sys.stdout.flush') as mocked:
+ guide, report = self.check_files(arglist=['--jobs=%s' % jobs])
+ self.assertEqual(guide.options.jobs, jobs)
+ self.assertEqual(mocked.call_count, jobs)
+
+ def test_jobs(self):
+ self._job_tester(2)
+ self._job_tester(10)
+
+ def test_stdin(self):
+ self.count = 0
+
+ def fake_stdin():
+ self.count += 1
+ with open(self.this_file(), "r") as f:
+ return f.read()
+
+ with mock.patch("pep8.stdin_get_value", fake_stdin):
+ guide, report = self.check_files(arglist=['--jobs=4'],
+ explicit_stdin=True)
+ self.assertEqual(self.count, 1)
+
+ def test_stdin_fail(self):
+ def fake_stdin():
+ return "notathing\n"
+ with mock.patch("pep8.stdin_get_value", fake_stdin):
+ # only assert needed is in check_files
+ guide, report = self.check_files(arglist=['--jobs=4'],
+ explicit_stdin=True,
+ count=1)