Skip to content

Commit

Permalink
Unit test for help (fix #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
rec committed May 11, 2020
1 parent 90ffff2 commit 4785320
Show file tree
Hide file tree
Showing 6 changed files with 395 additions and 22 deletions.
4 changes: 3 additions & 1 deletion doc_safer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import print_function
import inspect
import safer
from test import get_help

README_FILE = 'README.rst'

Expand Down Expand Up @@ -28,6 +28,8 @@ def main():
with safer.printer(README_FILE) as print:
print(make_doc())

get_help.write_help()


BODY = """
{doc}
Expand Down
11 changes: 0 additions & 11 deletions safer.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,17 +496,6 @@ def close(self):
temporary file is deleted.
"""

_DOC_FUNC = {
'open': """
A drop-in replacement for ``open()`` which returns a stream which only
overwrites the original file when close() is called, and only if there was no
failure""",
'printer': """
A context manager that yields a function that prints to the opened file,
only overwriting the original file at the exit of the context,
and only if there was no exception thrown""",
}

_DOC_WRITER_ARGS = """
ARGUMENTS
stream:
Expand Down
16 changes: 16 additions & 0 deletions test/get_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
import pydoc
import safer

HELP_FILE = os.path.join(os.path.dirname(__file__), 'help.txt')


def get_help():
items = [getattr(safer, k) for k in safer.__all__] + [safer]
return [pydoc.render_doc(i, title='Help on %s:') for i in items]


def write_help():
with safer.open(HELP_FILE, 'w') as fp:
for h in get_help():
fp.write(h)
Loading

0 comments on commit 4785320

Please sign in to comment.