summaryrefslogtreecommitdiff
path: root/README.rst
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2012-12-18 13:57:52 -0800
committerFlorent Xicluna <florent.xicluna@gmail.com>2012-12-18 13:57:52 -0800
commitcb298a0b3ea506a80efed801902f8513328a44c3 (patch)
tree4cf1bc2140b01ca2f6fb6261320920ce32eb47af /README.rst
parent7b25895384570e980b2a14825e5b2d77f6782ffe (diff)
parent663818e6d4260513bfd465f4397f6d2ac6db5f03 (diff)
downloadpep8-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.rst30
1 files changed, 30 insertions, 0 deletions
diff --git a/README.rst b/README.rst
index 7ad7e23..fe877dd 100644
--- a/README.rst
+++ b/README.rst
@@ -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
--------