46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
from z.z import main
|
|
import glob
|
|
import utils
|
|
import sys
|
|
import os
|
|
from unittest.mock import patch
|
|
import re
|
|
from pathlib import Path
|
|
|
|
def path_search(glob_str:str):
|
|
return glob.glob(glob_str)
|
|
|
|
def read_file(file_path:str):
|
|
with open(file_path, "r") as f:
|
|
return f.read()
|
|
|
|
def test_rename_denote(tmp_path):
|
|
utils.pre_test(tmp_path)
|
|
|
|
# New timestamp
|
|
src = "19700101T000000--example-file-3__test1_test2_test3"
|
|
input = "new example file 3"
|
|
with patch("sys.argv", ["", "rename", src, input]):
|
|
main()
|
|
# original file gone
|
|
assert not path_search(src)
|
|
# new file created
|
|
files = path_search("*--new-example-file-3__test1_test2_test3")
|
|
assert len(files) == 1
|
|
# contents unchanged
|
|
assert read_file(files[0]) == "test 3"
|
|
|
|
# Keep old timestamp
|
|
src = "19700101T000000--example-file-4__test1_test2_test3"
|
|
input = "new example file 4"
|
|
with patch("sys.argv", ["", "rename", src, input, "-t"]):
|
|
main()
|
|
# original file gone
|
|
assert not path_search(src)
|
|
# new file created
|
|
files = path_search("19700101T000000--new-example-file-4__test1_test2_test3")
|
|
assert len(files) == 1
|
|
# contents unchanged
|
|
assert read_file(files[0]) == "test 4"
|
|
|
|
utils.post_test(tmp_path) |