Browse Source

much nicer validation checking

Antoine Beaupré 9 years ago
parent
commit
5f6eb87385
1 changed files with 7 additions and 8 deletions
  1. 7 8
      borg/testsuite/convert.py

+ 7 - 8
borg/testsuite/convert.py

@@ -37,22 +37,21 @@ class ConversionTestCase(BaseTestCase):
     def tearDown(self):
     def tearDown(self):
         shutil.rmtree(self.tmppath)
         shutil.rmtree(self.tmppath)
 
 
-    def check_repo(self, state = True):
-        if not state:
-            print("this will show an error, this is expected")
+    def repo_valid(self,):
         repository = self.open(self.tmppath)
         repository = self.open(self.tmppath)
-        assert repository.check() is state # can't check raises() because check() handles the error
+        state = repository.check() # can't check raises() because check() handles the error
         repository.close()
         repository.close()
+        return state
 
 
     def test_convert_segments(self):
     def test_convert_segments(self):
         # check should fail because of magic number
         # check should fail because of magic number
-        self.check_repo(False)
+        assert not self.repo_valid()
         print("opening attic repository with borg and converting")
         print("opening attic repository with borg and converting")
         repo = self.open(self.tmppath, repo_type = AtticRepositoryConverter)
         repo = self.open(self.tmppath, repo_type = AtticRepositoryConverter)
         segments = [ filename for i, filename in repo.io.segment_iterator() ]
         segments = [ filename for i, filename in repo.io.segment_iterator() ]
         repo.close()
         repo.close()
         repo.convert_segments(segments, dryrun=False)
         repo.convert_segments(segments, dryrun=False)
-        self.check_repo()
+        assert self.repo_valid()
 
 
 class EncryptedConversionTestCase(ConversionTestCase):
 class EncryptedConversionTestCase(ConversionTestCase):
     class MockArgs:
     class MockArgs:
@@ -86,7 +85,7 @@ class EncryptedConversionTestCase(ConversionTestCase):
 
 
     def test_convert_all(self):
     def test_convert_all(self):
         # check should fail because of magic number
         # check should fail because of magic number
-        self.check_repo(False)
+        assert not self.repo_valid()
         print("opening attic repository with borg and converting")
         print("opening attic repository with borg and converting")
         with pytest.raises(NotImplementedError):
         with pytest.raises(NotImplementedError):
             self.open(self.tmppath, repo_type = AtticRepositoryConverter).convert(dryrun=False)
             self.open(self.tmppath, repo_type = AtticRepositoryConverter).convert(dryrun=False)
@@ -95,4 +94,4 @@ class EncryptedConversionTestCase(ConversionTestCase):
                                os.path.basename(self.key.path))
                                os.path.basename(self.key.path))
         with open(keyfile, 'r') as f:
         with open(keyfile, 'r') as f:
             assert f.read().startswith(KeyfileKey.FILE_ID)
             assert f.read().startswith(KeyfileKey.FILE_ID)
-        self.check_repo()
+        assert self.repo_valid()