- Timestamp:
- Oct 8, 2019, 5:05:19 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ipp-259_genericise_backups/tools/backups/backup_test.py
r40923 r40924 5 5 from pathlib import Path 6 6 7 import backups.backup as bckup 7 8 import backups.utils.errors as errs 8 9 from backups.backup import Backup … … 243 244 244 245 245 # class TestRunningTar(): 246 247 # def test_simply_tar(self): 248 # assert True is False 249 250 # def test_tar_with_additional_args(self): 251 # assert True is False 246 class TestRunningTar(): 247 248 def test_simply_tar(self, tmpdir): 249 config = make_default_config(tmpdir, ['bck1']) 250 source = os.path.join(tmpdir, "folder_to_tar") 251 os.makedirs(source) 252 # put a file in it 253 Path(os.path.join(source, "a_file.txt")) 254 255 config['TAR'] = \ 256 { 'sources' : f"{source}" 257 , 'additional_args' : "-C / -cf" 258 , 'target_filename' : 'cool_tar.tar' 259 , 'prefix_date' : 'False' 260 } 261 262 backy = Backup(config) 263 264 expected_tar1 = os.path.join(tmpdir, 'bck1', 'cool_tar.tar') 265 assert not os.path.exists(expected_tar1) 266 backy._run_tar() 267 print(expected_tar1) 268 assert os.path.exists(expected_tar1) 269 270 def test_tar_with_multiple_sources_and_date(self, tmpdir): 271 config = make_default_config(tmpdir, ['bck1', 'bck2']) 272 source1 = os.path.join(tmpdir, "folder_to_tar") 273 source2 = os.path.join(tmpdir, "another_folder_to_tar") 274 os.makedirs(source1) 275 os.makedirs(source2) 276 # put a file in it 277 Path(os.path.join(source1, "a_file.txt")) 278 Path(os.path.join(source2, "other.file")) 279 280 config['TAR'] = \ 281 { 'sources' : f"{source1}, {source2}" 282 , 'additional_args' : "-C / -cf" 283 , 'target_filename' : 'cool_tar.tar' 284 , 'prefix_date' : 'True' 285 } 286 287 backy = Backup(config) 288 289 date = bckup.get_date() 290 291 expected_tar1 = os.path.join(tmpdir, 'bck1', f'{date}_cool_tar.tar') 292 expected_tar2 = os.path.join(tmpdir, 'bck2', f'{date}_cool_tar.tar') 293 assert not os.path.exists(expected_tar1) 294 assert not os.path.exists(expected_tar2) 295 backy._run_tar() 296 print(expected_tar1) 297 print(expected_tar2) 298 assert os.path.exists(expected_tar1) 299 assert os.path.exists(expected_tar2) 252 300 253 301
Note:
See TracChangeset
for help on using the changeset viewer.
