@@ -44,14 +44,35 @@ def test_main_version(std: StringIO) -> None:
44
44
45
45
46
46
def test_create_file_if_missing (tmp_path : Path ) -> None :
47
- tf = tmp_path / "README.txt"
47
+ tf_base = tmp_path / "README"
48
+ tf = tf_base .with_suffix (".txt" )
48
49
assert not tf .exists ()
49
- create_file_if_missing (str (tf ), "content" )
50
+ assert create_file_if_missing (str (tf ), "content" )
50
51
assert tf .exists ()
51
52
assert tf .read_text () == "content"
52
- create_file_if_missing (str (tf ), "content2" )
53
+ assert not create_file_if_missing (str (tf ), "content2" )
53
54
# nothing gets changed
54
55
assert tf .read_text () == "content"
56
+ # matching glob - no change
57
+ for g in [".md" , ".txt" , ".json" ], [".*" ], [".*" , ".txt" ]:
58
+ assert not create_file_if_missing (str (tf_base ), "content2" , glob_suffixes = g )
59
+ assert tf .exists ()
60
+ assert tf .read_text () == "content"
61
+ assert not tf_base .exists () # was not created, since there is .md
62
+
63
+ # non-matching glob - change
64
+ for g in [".md" , ".json" ], [".d*" , ".*d" ]:
65
+ assert create_file_if_missing (str (tf_base ), "content3" , glob_suffixes = g )
66
+ assert tf_base .read_text () == "content3"
67
+ # now that we have suffix less README, we do not match, so we keep creating it
68
+ assert create_file_if_missing (str (tf_base ), "content4" , glob_suffixes = g )
69
+ assert tf_base .read_text () == "content4"
70
+ # unless we list it explicitly
71
+ assert not create_file_if_missing (
72
+ str (tf_base ), "content5" , glob_suffixes = g + ["" ]
73
+ )
74
+ assert tf_base .read_text () == "content4"
75
+ tf_base .unlink ()
55
76
56
77
57
78
def test_populate_bids_templates (tmp_path : Path ) -> None :
0 commit comments