@@ -30,12 +30,43 @@ def some_func(x):
3030 assert n_calls == 3
3131
3232
33- def test_backup (tmp_path ) -> None :
33+ def test_backup (tmp_path , monkeypatch ) -> None :
34+ monkeypatch .chdir (tmp_path )
35+ with open ("INCAR" , "w" ) as f :
36+ f .write ("This is a test file." )
37+
38+ backup (["INCAR" ])
39+
40+ assert Path ("error.1.tar.gz" ).exists ()
41+ with tarfile .open ("error.1.tar.gz" , "r:gz" ) as tar :
42+ assert len (tar .getmembers ()) == 1
43+ assert tar .getnames () == ["error.1/INCAR" ]
44+
45+
46+ def test_backup_with_glob (tmp_path , monkeypatch ) -> None :
47+ monkeypatch .chdir (tmp_path )
48+ with open ("INCAR" , "w" ) as f :
49+ f .write ("This is a test file." )
50+ with open ("POSCAR" , "w" ) as f :
51+ f .write ("This is a test file." )
52+ with open ("garbage" , "w" ) as f :
53+ f .write ("This is a test file." )
54+
55+ backup (["*CAR" ])
56+
57+ assert Path ("error.1.tar.gz" ).exists ()
58+ with tarfile .open ("error.1.tar.gz" , "r:gz" ) as tar :
59+ assert len (tar .getmembers ()) == 2
60+ assert tar .getnames () == ["error.1/INCAR" , "error.1/POSCAR" ]
61+
62+
63+ def test_backup_with_directory (tmp_path ) -> None :
3464 with open (tmp_path / "INCAR" , "w" ) as f :
3565 f .write ("This is a test file." )
3666
3767 backup (["INCAR" ], directory = tmp_path )
3868
3969 assert Path (tmp_path / "error.1.tar.gz" ).exists ()
4070 with tarfile .open (tmp_path / "error.1.tar.gz" , "r:gz" ) as tar :
41- assert len (tar .getmembers ()) > 0
71+ assert len (tar .getmembers ()) == 1
72+ assert tar .getnames () == ["error.1/INCAR" ]
0 commit comments