From f2901184ccb5415cf40b3ec61c128a6a59ab3aa7 Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Sat, 30 Apr 2022 10:59:48 -0700 Subject: Add some docs and doctests to things that have 0% coverage. --- persistent.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'persistent.py') diff --git a/persistent.py b/persistent.py index 27aa4b3..b42a5c0 100644 --- a/persistent.py +++ b/persistent.py @@ -64,7 +64,23 @@ class Persistent(ABC): def was_file_written_today(filename: str) -> bool: - """Returns True if filename was written today.""" + """Returns True if filename was written today. + + >>> import os + >>> filename = f'/tmp/testing_persistent_py_{os.getpid()}' + >>> os.system(f'touch {filename}') + 0 + >>> was_file_written_today(filename) + True + >>> os.system(f'touch -d 1974-04-15T01:02:03.99 {filename}') + 0 + >>> was_file_written_today(filename) + False + >>> os.system(f'/bin/rm -f {filename}') + 0 + >>> was_file_written_today(filename) + False + """ if not file_utils.does_file_exist(filename): return False @@ -82,7 +98,22 @@ def was_file_written_within_n_seconds( """Returns True if filename was written within the pas limit_seconds seconds. + >>> import os + >>> filename = f'/tmp/testing_persistent_py_{os.getpid()}' + >>> os.system(f'touch {filename}') + 0 + >>> was_file_written_within_n_seconds(filename, 60) + True + >>> import time + >>> time.sleep(2.0) + >>> was_file_written_within_n_seconds(filename, 2) + False + >>> os.system(f'/bin/rm -f {filename}') + 0 + >>> was_file_written_within_n_seconds(filename, 60) + False """ + if not file_utils.does_file_exist(filename): return False @@ -169,3 +200,9 @@ class persistent_autoloaded_singleton(object): return self.instance return _load + + +if __name__ == '__main__': + import doctest + + doctest.testmod() -- cgit v1.3