#!/usr/bin/env python3
+# © Copyright 2021-2022, Scott Gasch
+
"""A Persistent is just a class with a load and save method. This
module defines the Persistent base and a decorator that can be used to
create a persistent singleton that autoloads and autosaves."""
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
"""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
return self.instance
return _load
+
+
+if __name__ == '__main__':
+ import doctest
+
+ doctest.testmod()