Skip to content
Permalink
Browse files

MNT: add .coveragerc and increase reported coverage of CLI module

  • Loading branch information...
kernc committed Nov 25, 2018
1 parent ffc22cf commit 24daf45cac3e71121ecf1eb34d30c38e9ef3359b
Showing with 32 additions and 8 deletions.
  1. +13 −0 .coveragerc
  2. +5 −0 pdoc/cli.py
  3. +14 −8 pdoc/test/__init__.py
@@ -0,0 +1,13 @@
[run]
source =
pdoc
omit =
pdoc/test/example_pkg/*

[report]
exclude_lines =
continue
return
raise
except
warn\(
@@ -301,6 +301,11 @@ def main(_args=None):
print('Starting pdoc server on {}:{}'.format(host, port), file=sys.stderr)
httpd = HTTPServer((host, port), WebDoc)
print("pdoc server ready at http://%s:%d" % (host, port), file=sys.stderr)

# Allow tests to perform `pdoc.cli._httpd.shutdown()`
global _httpd
_httpd = httpd

try:
httpd.serve_forever()
finally:
@@ -1,7 +1,7 @@
import os
import signal
import subprocess
import sys
import threading
import unittest
from contextlib import contextmanager, redirect_stderr, redirect_stdout
from glob import glob
@@ -506,15 +506,17 @@ def _raise(*_):

def test_http(self):
host, port = 'localhost', randint(9000, 12000)
cmd = 'pdoc --http :{} pdoc {}'.format(
args = '--http :{} pdoc {}'.format(
port, os.path.join(TESTS_BASEDIR, EXAMPLE_MODULE)).split()

with self._timeout(10):
with subprocess.Popen(cmd, stderr=subprocess.PIPE) as proc:
sleep(1)
with redirect_streams() as (stdout, stderr):
t = threading.Thread(target=main, args=(parser.parse_args(args),))
t.start()
sleep(.1)

if proc.poll() is not None:
sys.stderr.write(proc.stderr.read().decode(sys.getdefaultencoding()))
if not t.is_alive():
sys.stderr.write(stderr.getvalue())
raise AssertionError

try:
@@ -528,9 +530,13 @@ def test_http(self):
with urlopen(url + 'pdoc', timeout=3) as resp:
html = resp.read()
self.assertIn(b'__pdoc__', html)
with self.subTest(url='/csv.ext'):
with urlopen(url + 'csv.ext', timeout=3) as resp:
html = resp.read()
self.assertIn(b'DictReader', html)
finally:
proc.terminate()
proc.kill()
pdoc.cli._httpd.shutdown()
t.join()


if __name__ == '__main__':

0 comments on commit 24daf45

Please sign in to comment.
You can’t perform that action at this time.