mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-04-22 22:22:54 +02:00
test(data-extraction): Delay file creation in test_rename_latest_file to avoid same timestamps
This commit is contained in:
parent
7269e7e6a4
commit
56c2ed55ec
@ -1,4 +1,3 @@
|
|||||||
import glob
|
|
||||||
import os
|
import os
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
|
|
||||||
@ -15,7 +14,9 @@ def prepare_temporary_dir(directory: str, formats: list[str]) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_rename_latest_file() -> None:
|
def test_rename_latest_file() -> None:
|
||||||
with TemporaryDirectory() as temp_dir:
|
import time
|
||||||
|
|
||||||
|
with TemporaryDirectory("-4711") as temp_dir:
|
||||||
# Create some test files in the temporary directory
|
# Create some test files in the temporary directory
|
||||||
test_file1 = os.path.join(temp_dir, "file1.xml")
|
test_file1 = os.path.join(temp_dir, "file1.xml")
|
||||||
test_file2 = os.path.join(temp_dir, "file2.xml")
|
test_file2 = os.path.join(temp_dir, "file2.xml")
|
||||||
@ -24,15 +25,16 @@ def test_rename_latest_file() -> None:
|
|||||||
# Create files with different modification times
|
# Create files with different modification times
|
||||||
with open(test_file1, "w") as f:
|
with open(test_file1, "w") as f:
|
||||||
f.write("Content 1")
|
f.write("Content 1")
|
||||||
|
time.sleep(0.15)
|
||||||
with open(test_file2, "w") as f:
|
with open(test_file2, "w") as f:
|
||||||
f.write("Content 2")
|
f.write("Content 2")
|
||||||
|
time.sleep(0.15)
|
||||||
with open(test_file3, "w") as f:
|
with open(test_file3, "w") as f:
|
||||||
f.write("Content 3")
|
f.write("Content 3")
|
||||||
|
time.sleep(0.15)
|
||||||
|
|
||||||
# Rename the latest file to 'new_file.xml'
|
# Rename the latest file to 'new_file.xml'
|
||||||
extract.rename_latest_file(temp_dir, "new_file.xml")
|
extract.rename_latest_file(temp_dir, "new_file.xml")
|
||||||
|
|
||||||
glob.glob1(temp_dir, "*.xml")
|
|
||||||
# Verify that 'file3.xml' is renamed to 'new_file.xml'
|
# Verify that 'file3.xml' is renamed to 'new_file.xml'
|
||||||
assert not os.path.exists(test_file3)
|
assert not os.path.exists(test_file3)
|
||||||
assert os.path.exists(os.path.join(temp_dir, "new_file.xml"))
|
assert os.path.exists(os.path.join(temp_dir, "new_file.xml"))
|
||||||
@ -60,7 +62,7 @@ def test_rename_latest_file() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_get_num_files_default_pattern() -> None:
|
def test_get_num_files_default_pattern() -> None:
|
||||||
with TemporaryDirectory() as temp_dir:
|
with TemporaryDirectory("-4712") as temp_dir:
|
||||||
prepare_temporary_dir(temp_dir, ["xml", "xml", "xml"])
|
prepare_temporary_dir(temp_dir, ["xml", "xml", "xml"])
|
||||||
|
|
||||||
expected_result = 3
|
expected_result = 3
|
||||||
@ -68,7 +70,7 @@ def test_get_num_files_default_pattern() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_get_num_files_different_pattern() -> None:
|
def test_get_num_files_different_pattern() -> None:
|
||||||
with TemporaryDirectory() as temp_dir:
|
with TemporaryDirectory("-4713") as temp_dir:
|
||||||
prepare_temporary_dir(temp_dir, ["xml", "txt", "json"])
|
prepare_temporary_dir(temp_dir, ["xml", "txt", "json"])
|
||||||
|
|
||||||
num_files = extract.get_num_files(temp_dir, "*.txt")
|
num_files = extract.get_num_files(temp_dir, "*.txt")
|
||||||
@ -76,6 +78,6 @@ def test_get_num_files_different_pattern() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def test_wait_for_download_condition() -> None:
|
def test_wait_for_download_condition() -> None:
|
||||||
with TemporaryDirectory() as temp_dir:
|
with TemporaryDirectory("-4714") as temp_dir:
|
||||||
prepare_temporary_dir(temp_dir, ["xml", "txt"])
|
prepare_temporary_dir(temp_dir, ["xml", "txt"])
|
||||||
assert extract.wait_for_download_condition(temp_dir, 2) is False
|
assert extract.wait_for_download_condition(temp_dir, 2) is False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user