diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2012-12-18 13:57:52 -0800 |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2012-12-18 13:57:52 -0800 |
commit | cb298a0b3ea506a80efed801902f8513328a44c3 (patch) | |
tree | 4cf1bc2140b01ca2f6fb6261320920ce32eb47af /README.rst | |
parent | 7b25895384570e980b2a14825e5b2d77f6782ffe (diff) | |
parent | 663818e6d4260513bfd465f4397f6d2ac6db5f03 (diff) | |
download | pep8-cb298a0b3ea506a80efed801902f8513328a44c3.tar.gz |
Merge pull request #114 from JensRantil/api-to-readme
Describe how to execute from Python in README
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 -------- |