Skip to content

Commit 970149b

Browse files
committed
Test readme
1 parent 2238a0f commit 970149b

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎.travis.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ script:
2424
# Smoke test.
2525
- echo 'This is a sentence.' > foo.txt
2626
- language-check foo.txt
27+
28+
- if [ "$TRAVIS_PYTHON_VERSION" == "3.3" ]; then ./run_doctest.py -v README.rst; fi

‎README.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Print a ``Match`` object:
4040
Line 1, column 51, Rule ID: TOT_HE[1]
4141
Message: Did you mean 'to the'?
4242
Suggestion: to the
43-
... with a error in the Hitchhiker’s Guide tot he Galaxy
43+
...
4444

4545
Automatically apply suggestions to the text:
4646

‎run_doctest.py‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
"""Modified version of "python -m doctest"."""
4+
5+
import doctest
6+
import os
7+
import sys
8+
9+
10+
def main():
11+
testfiles = [arg for arg in sys.argv[1:] if arg and arg[0] != '-']
12+
if not testfiles:
13+
name = os.path.basename(sys.argv[0])
14+
if '__loader__' in globals(): # python -m
15+
name, _ = os.path.splitext(name)
16+
print("usage: {0} [-v] file ...".format(name))
17+
return 2
18+
19+
optionflags = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE
20+
21+
for filename in testfiles:
22+
if filename.endswith(".py"):
23+
# It is a module -- insert its dir into sys.path and try to
24+
# import it. If it is part of a package, that possibly
25+
# won't work because of package imports.
26+
dirname, filename = os.path.split(filename)
27+
sys.path.insert(0, dirname)
28+
m = __import__(filename[:-3])
29+
del sys.path[0]
30+
failures, _ = doctest.testmod(m, optionflags=optionflags)
31+
else:
32+
failures, _ = doctest.testfile(filename, module_relative=False,
33+
optionflags=optionflags)
34+
if failures:
35+
return 1
36+
return 0
37+
38+
39+
if __name__ == "__main__":
40+
sys.exit(main())

0 commit comments

Comments
 (0)