Skip to content

Commit

Permalink
Merge pull request #67 from Kota-Karthik/revert-52-test_compare_and_r…
Browse files Browse the repository at this point in the history
…eplace

Revert "Test compare and replace"
  • Loading branch information
Kota-Karthik authored Oct 4, 2024
2 parents 28f2e5b + dda2119 commit 760a90c
Showing 1 changed file with 2 additions and 77 deletions.
79 changes: 2 additions & 77 deletions tests/allFileMetadata.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from twinTrim.dataStructures import allFileMetadata
import threading
from twinTrim.dataStructures.allFileMetadata import add_or_update_file, store
from twinTrim.dataStructures.allFileMetadata import AllFileMetadata
from twinTrim.dataStructures.allFileMetadata import add_or_update_file, store, store_lock

# Mocking the get_file_hash function for different file paths
def mock_get_file_hash(file_path):
Expand Down Expand Up @@ -101,81 +101,6 @@ def worker(file_path):
assert store["hash_file_2"].filepath == "file_2"
assert store["hash_file_3"].filepath == "file_3"

def test_compare_and_replace_new_file_is_newer(mocker):

file1 = "file1.txt"
file2 = "file2.txt"

metadata1 = allFileMetadata.AllFileMetadata(file1)
metadata2 = allFileMetadata.AllFileMetadata(file2)


metadata1.file_modified_time = 100
metadata2.file_modified_time = 200
mocker.patch("os.path.getmtime", side_effect=lambda x: {"file1.txt": 100, "file2.txt": 200}[x])

mock_handle_and_remove = mocker.patch("twinTrim.dataStructures.allFileMetadata.handle_and_remove")

metadata1.compare_and_replace(metadata2)
mock_handle_and_remove.assert_called_once_with(file1)

assert metadata1.filepath == file2
assert metadata1.file_modified_time == 200

def test_compare_and_replace_new_file_is_older(mocker):

file1 = "file1.txt"
file2 = "file2.txt"

metadata1 = allFileMetadata.AllFileMetadata(file1)
metadata2 = allFileMetadata.AllFileMetadata(file2)


metadata1.file_modified_time = 200
metadata2.file_modified_time = 100
mocker.patch("os.path.getmtime", side_effect=lambda x: {"file1.txt": 200, "file2.txt": 100}[x])

mock_handle_and_remove = mocker.patch("twinTrim.dataStructures.allFileMetadata.handle_and_remove")
metadata1.compare_and_replace(metadata2)
mock_handle_and_remove.assert_called_once_with(file2)

assert metadata1.filepath == file1
assert metadata1.file_modified_time == 200

def test_compare_and_replace_new_file_is_missing(mocker):

file1 = "file1.txt"
file2 = "file2.txt"

metadata1 = allFileMetadata.AllFileMetadata(file1)
metadata2 = allFileMetadata.AllFileMetadata(file2)

metadata1.file_modified_time = 200
metadata2.file_modified_time = -1
mocker.patch("os.path.getmtime", side_effect=lambda x: {"file1.txt": 200, "file2.txt": -1}[x])

metadata1.compare_and_replace(metadata2)

assert metadata1.filepath == file1
assert metadata1.file_modified_time == 200

def test_compare_and_replace_old_file_is_missing(mocker):

file1 = "file1.txt"
file2 = "file2.txt"

metadata1 = allFileMetadata.AllFileMetadata(file1)
metadata2 = allFileMetadata.AllFileMetadata(file2)

metadata1.file_modified_time = -1
metadata2.file_modified_time = 200
mocker.patch("os.path.getmtime", side_effect=lambda x: {"file1.txt": -1, "file2.txt": 200}[x])

metadata1.compare_and_replace(metadata2)

assert metadata1.filepath == file1
assert metadata1.file_modified_time == -1

def test_add_or_update_file_when_file_doesnt_exist(mocker):
mockfile = "mockfile.txt"
mocker.patch("twinTrim.dataStructures.allFileMetadata.os.path.exists", return_value=False)
Expand Down

0 comments on commit 760a90c

Please sign in to comment.