Skip to content

Commit

Permalink
doctests in unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
andgineer committed Apr 18, 2019
1 parent a2385c5 commit 49b3365
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 24 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
- python3 -m pip install -r requirements.txt
script:
- python3 -m unittest discover --start-directory tests --verbose
- rm -rf bombard/__pycache__
- python3 -m doctest -v bombard/*.py tests/*.py
after_success:
- coveralls
25 changes: 3 additions & 22 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,13 @@ CYAN='\033[1;36m'
NC='\033[0m' # No Color
NL=$'\n'

if [[ -z "$@" ]]; then # if selected specific test we do not run doctests
echo
echo "##### Doc tests #####"
rm -rf bombard/__pycache__
python3 -m doctest -v bombard/attr_dict.py bombard/pretty_ns.py tests/fake_args.py tests/stdout_capture.py
DOCTESTS=$?
else
DOCTESTS=1000
fi
echo
echo "##### Unittest tests #####"
python3.7 -m unittest discover --start-directory tests --verbose $@

if [ $? -eq 0 ]; then
echo
echo -e $GREEN"unit tests are success!"$NC
echo -e $GREEN"success!"$NC
else
echo
echo -e $RED"unit tests failed"$NC
fi

if [ $DOCTESTS -eq 1000 ]; then
echo "No doc tests were run"
exit
elif [ $DOCTESTS -eq 0 ]; then
echo -e $GREEN"doc tests are success!"$NC
else
echo -e $RED"doc tests failed"$NC
echo -e $RED"fail"$NC
fi
echo
4 changes: 4 additions & 0 deletions tests/stdout_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
... print('3', end='')
>>> captured.output
'3'
>>> with CaptureOutput(capture=False) as captured:
... captured.output is None
True
"""
import sys
from io import StringIO
Expand Down
11 changes: 11 additions & 0 deletions tests/test_doctests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import doctest
from bombard import attr_dict, pretty_ns
from tests import stdout_capture, fake_args


def load_tests(loader, tests, ignore):
tests.addTest(doctest.DocTestSuite(attr_dict))
tests.addTest(doctest.DocTestSuite(stdout_capture))
tests.addTest(doctest.DocTestSuite(fake_args))
tests.addTest(doctest.DocTestSuite(pretty_ns))
return tests

0 comments on commit 49b3365

Please sign in to comment.