diff options
author | Jens Rantil <jens.rantil@gmail.com> | 2012-07-26 23:58:27 +0200 |
---|---|---|
committer | Jens Rantil <jens.rantil@gmail.com> | 2012-07-26 23:58:27 +0200 |
commit | 663818e6d4260513bfd465f4397f6d2ac6db5f03 (patch) | |
tree | 20cffaf253b99ced64d07a912a3013cb9487e90c /README.rst | |
parent | 7f2d5a3f561d48864211642097f05c6a5d2c2a55 (diff) | |
download | pep8-663818e6d4260513bfd465f4397f6d2ac6db5f03.tar.gz |
Readme now describes how to execute from Python
Commit related to issue #35 and #105.
Diffstat (limited to 'README.rst')
-rw-r--r-- | README.rst | 30 |
1 files changed, 30 insertions, 0 deletions
@@ -123,6 +123,36 @@ Quick help is available on the command line:: --config=path config file location (default: /home/user/.config/pep8) +Calling `pep8` from Python +-------------------------- + +You can also execute `pep8` tests from Python code. For example, this +can be highly useful for automated testing of code format in your +projects:: + + import unittest + import pep + + class TestCodeFormat(unittest.TestCase): + def test_pep8_conformance(self): + """Test that we conform to PEP8.""" + pep8style = pep8.StyleGuide(quiet=True) + result = pep8style.check_files(['file1.py', 'file2.py']) + self.assertEqual(result.total_errors, 0, + "Found code syntax errors (and warnings).") + +If you are using `nosetests` for running tests, remove `quiet=True` +since Nose suppresses stdout. + +There's also a shortcut for checking a single file:: + + import pep8 + + fchecker = pep8.Checker('testsuite/E27.py', show_source=True) + file_errors = fchecker.check_all() + + print("Found %s errors (and warnings)" % file_errors) + Feedback -------- |