diff options
| author | Scott Gasch <[email protected]> | 2022-04-30 10:59:48 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2022-04-30 10:59:48 -0700 |
| commit | f2901184ccb5415cf40b3ec61c128a6a59ab3aa7 (patch) | |
| tree | f9c29997f888de27fe129728b65c854b8454de89 /persistent.py | |
| parent | 6fd34b009eec9cda18f1bdd9d8184b7a317a156d (diff) | |
Add some docs and doctests to things that have 0% coverage.
Diffstat (limited to 'persistent.py')
| -rw-r--r-- | persistent.py | 39 |
1 files changed, 38 insertions, 1 deletions
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() |
