Skip to content

Commit

Permalink
allow self.filename to be none for testings - won't read or write any…
Browse files Browse the repository at this point in the history
… file
  • Loading branch information
niradar committed May 30, 2024
1 parent 217c6b2 commit 5779c55
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions duplicate_files_in_folders/hash_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def reset_instance(cls):
with cls._lock:
cls._instance = None

def __init__(self, target_folder: str = None, filename: str = 'hashes.pkl'):
def __init__(self, target_folder: str = None, filename='hashes.pkl'):
if self.__initialized:
return
self.__initialized = True
Expand All @@ -54,6 +54,8 @@ def __init__(self, target_folder: str = None, filename: str = 'hashes.pkl'):
def load_data(self) -> pd.DataFrame:
"""Load only data relevant to the target folder from the file, or create a new DataFrame if the file doesn't
exist."""
if self.filename is None: # for testing purposes
return pd.DataFrame(columns=['file_path', 'hash_value', 'last_update'])
if os.path.exists(self.filename):
all_data = pd.read_pickle(self.filename)
if self.target_folder:
Expand All @@ -76,7 +78,8 @@ def ensure_columns(df: pd.DataFrame) -> pd.DataFrame:

def save_data(self) -> None:
"""Save the current persistent DataFrame to a file."""

if self.filename is None: # for testing purposes
return
# Clean expired cache before saving - only for target folder
self.clean_expired_cache()

Expand Down

0 comments on commit 5779c55

Please sign in to comment.