diff options
| author | Scott Gasch <[email protected]> | 2021-09-10 13:23:31 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2021-09-10 13:23:31 -0700 |
| commit | 83c1e0d04fe2e78963c8b508e8b7d0ae03bfcb16 (patch) | |
| tree | dadcd5f5a9fbd50f468a0f07ee28963ca4a3cf54 /unittest_utils.py | |
| parent | 6f132c0342ab7aa438ed88d7c5f987cb52d8ca05 (diff) | |
Adding more tests, working on the test harness.
Diffstat (limited to 'unittest_utils.py')
| -rw-r--r-- | unittest_utils.py | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/unittest_utils.py b/unittest_utils.py index 2dc8cfe..8a0556b 100644 --- a/unittest_utils.py +++ b/unittest_utils.py @@ -148,15 +148,19 @@ def check_all_methods_for_perf_regressions(prefix='test_'): def breakpoint(): + """Hard code a breakpoint somewhere; drop into pdb.""" import pdb pdb.set_trace() class RecordStdout(object): """ - with uu.RecordStdout() as record: - print("This is a test!") - print({record().readline()}) + Record what is emitted to stdout. + + >>> with RecordStdout() as record: + ... print("This is a test!") + >>> print({record().readline()}) + {'This is a test!\\n'} """ def __init__(self) -> None: @@ -176,9 +180,13 @@ class RecordStdout(object): class RecordStderr(object): """ - with uu.RecordStderr() as record: - print("This is a test!", file=sys.stderr) - print({record().readline()}) + Record what is emitted to stderr. + + >>> import sys + >>> with RecordStderr() as record: + ... print("This is a test!", file=sys.stderr) + >>> print({record().readline()}) + {'This is a test!\\n'} """ def __init__(self) -> None: @@ -198,12 +206,9 @@ class RecordStderr(object): class RecordMultipleStreams(object): """ - with uu.RecordStreams(sys.stderr, sys.stdout) as record: - print("This is a test!") - print("This is one too.", file=sys.stderr) - - print(record().readlines()) + Record the output to more than one stream. """ + def __init__(self, *files) -> None: self.files = [*files] self.destination = tempfile.SpooledTemporaryFile(mode='r+') @@ -219,3 +224,8 @@ class RecordMultipleStreams(object): for f in self.files: f.write = self.saved_writes.pop() self.destination.seek(0) + + +if __name__ == '__main__': + import doctest + doctest.testmod() |
