64
64
# File we will request in dump mode
65
65
DUMP_FILE = "__version__.py"
66
66
67
+
67
68
class RedirectedStdout :
68
69
"""
69
70
Balantly copied from https://stackoverflow.com/a/45899925/2635443
@@ -183,7 +184,7 @@ def test_npbackup_cli_init():
183
184
print (str (logs ))
184
185
assert "created restic repository" in str (logs ), "Did not create repo"
185
186
assert "Repo initialized successfully" in str (logs ), "Repo init failed"
186
-
187
+
187
188
188
189
def test_npbackup_cli_has_no_recent_snapshots ():
189
190
"""
@@ -198,11 +199,11 @@ def test_npbackup_cli_has_no_recent_snapshots():
198
199
print (str (logs ))
199
200
json_logs = json .loads (str (logs ))
200
201
assert json_logs ["result" ] == False , "Should not have recent snapshots"
201
-
202
+
202
203
203
204
def test_npbackup_cli_create_backup ():
204
205
# Let's remove the repo before creating a backup since backup should auto init the repo
205
- shutil .rmtree (repo_config .g ("repo_uri" ), ignore_errors = True )
206
+ shutil .rmtree (repo_config .g ("repo_uri" ), ignore_errors = True )
206
207
sys .argv = ["" , "-c" , str (CONF_FILE ), "-b" ]
207
208
208
209
try :
@@ -299,8 +300,7 @@ def test_npbackup_cli_list_snapshots():
299
300
json_logs = json .loads (str (logs ))
300
301
assert json_logs ["result" ], "Bad list result"
301
302
assert json_logs ["operation" ] == "list" , "Bogus operation name for list"
302
- assert len (json_logs ["output" ]["data" ]) == 64 , "No snapshot data found"
303
-
303
+ assert len (json_logs ["output" ]["data" ]) == 64 , "No snapshot data found"
304
304
305
305
306
306
def test_npbackup_cli_find ():
@@ -311,7 +311,9 @@ def test_npbackup_cli_find():
311
311
print (e )
312
312
except SystemExit :
313
313
print (logs )
314
- assert "Found matching entries in snapshot" in str (logs ), "Did not find match for find"
314
+ assert "Found matching entries in snapshot" in str (
315
+ logs
316
+ ), "Did not find match for find"
315
317
assert "__version__.py" , "Did not find __version__.py in find"
316
318
317
319
@@ -327,9 +329,7 @@ def test_npbackup_cli_check_quick():
327
329
logs
328
330
), "Failed quick checking repo"
329
331
print (logs )
330
- assert "Repo checked successfully" in str (
331
- logs
332
- ), "Quick check failed"
332
+ assert "Repo checked successfully" in str (logs ), "Quick check failed"
333
333
334
334
335
335
def test_npbackup_cli_check_full ():
@@ -344,9 +344,7 @@ def test_npbackup_cli_check_full():
344
344
logs
345
345
), "Failed full checking repo"
346
346
print (logs )
347
- assert "Repo checked successfully" in str (
348
- logs
349
- ), "Full check failed"
347
+ assert "Repo checked successfully" in str (logs ), "Full check failed"
350
348
351
349
352
350
def test_npbackup_cli_repair_index ():
@@ -357,13 +355,9 @@ def test_npbackup_cli_repair_index():
357
355
print (e )
358
356
except SystemExit :
359
357
print (logs )
360
- assert "Repairing index in repo" in str (
361
- logs
362
- ), "Index repair failed"
358
+ assert "Repairing index in repo" in str (logs ), "Index repair failed"
363
359
print (logs )
364
- assert "Repo successfully repaired:" in str (
365
- logs
366
- ), "Missing repair info"
360
+ assert "Repo successfully repaired:" in str (logs ), "Missing repair info"
367
361
368
362
369
363
def test_npbackup_cli_repair_snapshots ():
@@ -374,13 +368,9 @@ def test_npbackup_cli_repair_snapshots():
374
368
print (e )
375
369
except SystemExit :
376
370
print (logs )
377
- assert "Repairing snapshots in repo" in str (
378
- logs
379
- ), "Snapshot repair failed"
371
+ assert "Repairing snapshots in repo" in str (logs ), "Snapshot repair failed"
380
372
print (logs )
381
- assert "Repo successfully repaired:" in str (
382
- logs
383
- ), "Missing repair info"
373
+ assert "Repo successfully repaired:" in str (logs ), "Missing repair info"
384
374
385
375
386
376
def test_npbackup_cli_retention ():
@@ -434,9 +424,7 @@ def test_npbackup_cli_prune():
434
424
print (e )
435
425
except SystemExit :
436
426
print (logs )
437
- assert "Pruning snapshots for repo" in str (
438
- logs
439
- ), "Could not prune repo"
427
+ assert "Pruning snapshots for repo" in str (logs ), "Could not prune repo"
440
428
assert "unused size after prune" in str (logs ), "Did not prune"
441
429
assert "Successfully pruned repository" in str (logs ), "Prune failed"
442
430
@@ -451,11 +439,15 @@ def test_npbackup_cli_housekeeping():
451
439
print (logs )
452
440
json_logs = json .loads (str (logs ))
453
441
assert json_logs ["result" ], "Bad housekeeping result"
454
- assert json_logs ["operation" ] == "housekeeping" , "Bogus operation name for housekeeping"
442
+ assert (
443
+ json_logs ["operation" ] == "housekeeping"
444
+ ), "Bogus operation name for housekeeping"
455
445
assert json_logs ["detail" ]["unlock" ]["result" ], "Unlock failed in housekeeping"
456
446
assert json_logs ["detail" ]["check" ]["result" ], "check failed in housekeeping"
457
447
assert json_logs ["detail" ]["forget" ]["result" ], "forget failed in housekeeping"
458
- assert len (json_logs ["detail" ]["forget" ]["args" ]["policy" ]) > 4 , "policy missing in housekeeping"
448
+ assert (
449
+ len (json_logs ["detail" ]["forget" ]["args" ]["policy" ]) > 4
450
+ ), "policy missing in housekeeping"
459
451
assert json_logs ["detail" ]["prune" ]["result" ], "prune failed in housekeeping"
460
452
461
453
@@ -469,9 +461,7 @@ def test_npbackup_cli_raw():
469
461
print (e )
470
462
except SystemExit :
471
463
print (logs )
472
- assert "Running raw command" in str (
473
- logs
474
- ), "Did not run raw command"
464
+ assert "Running raw command" in str (logs ), "Did not run raw command"
475
465
assert "Successfully run raw command" in str (logs ), "Did not run raw command"
476
466
assert DUMP_FILE in str (logs ), "raw ls output should contain DUMP_FILE name"
477
467
for line in str (logs ).split ("\n " ):
@@ -490,11 +480,10 @@ def test_npbackup_cli_dump():
490
480
except SystemExit :
491
481
print ("DUMPED FILE" , DUMP_FILE )
492
482
print (logs )
493
- assert '__intname__ = "npbackup"' in str (
483
+ assert '__intname__ = "npbackup"' in str (logs ), "version file seems bogus"
484
+ assert 'version_string = f"{__intname__}' in str (
494
485
logs
495
- ), "version file seems bogus"
496
- assert 'version_string = f"{__intname__}' in str (logs ), "Version file still seems bogus"
497
-
486
+ ), "Version file still seems bogus"
498
487
499
488
500
489
if __name__ == "__main__" :
@@ -529,13 +518,11 @@ def test_npbackup_cli_dump():
529
518
test_npbackup_cli_check_full ()
530
519
test_npbackup_cli_repair_index ()
531
520
test_npbackup_cli_repair_snapshots ()
532
-
521
+
533
522
# Repairing packs needs pack ids
534
- #test_npbackup_cli_repair_packs()
523
+ # test_npbackup_cli_repair_packs()
535
524
536
525
test_npbackup_cli_housekeeping ()
537
526
538
527
test_npbackup_cli_raw ()
539
528
test_npbackup_cli_dump ()
540
-
541
-
0 commit comments