|
59 | 59 | ANY_PUBKEY_DICT_SCHEMA) |
60 | 60 |
|
61 | 61 |
|
| 62 | +class GPGTestUtils: |
| 63 | + """GPG Test utility class""" |
| 64 | + |
| 65 | + @staticmethod |
| 66 | + def ignore_not_found_error(function, path, exc_info): |
| 67 | + """Callback that ignores FileNotFoundError""" |
| 68 | + _, error, _ = exc_info |
| 69 | + if not isinstance(error, FileNotFoundError): |
| 70 | + raise error |
| 71 | + |
| 72 | + |
62 | 73 | @unittest.skipIf(not HAVE_GPG, "gpg not found") |
63 | 74 | class TestUtil(unittest.TestCase): |
64 | 75 | """Test util functions. """ |
@@ -503,7 +514,7 @@ def setUpClass(self): |
503 | 514 | def tearDownClass(self): |
504 | 515 | """Change back to initial working dir and remove temp test directory. """ |
505 | 516 | os.chdir(self.working_dir) |
506 | | - shutil.rmtree(self.test_dir) |
| 517 | + shutil.rmtree(self.test_dir, onerror=GPGTestUtils.ignore_not_found_error) |
507 | 518 |
|
508 | 519 | def test_export_pubkey_error(self): |
509 | 520 | """Test correct error is raised if function called incorrectly. """ |
@@ -664,7 +675,7 @@ def setUpClass(self): |
664 | 675 | def tearDownClass(self): |
665 | 676 | """Change back to initial working dir and remove temp test directory. """ |
666 | 677 | os.chdir(self.working_dir) |
667 | | - shutil.rmtree(self.test_dir) |
| 678 | + shutil.rmtree(self.test_dir, onerror=GPGTestUtils.ignore_not_found_error) |
668 | 679 |
|
669 | 680 | def test_export_pubkey(self): |
670 | 681 | """ export a public key and make sure the parameters are the right ones: |
@@ -749,7 +760,7 @@ def setUpClass(self): |
749 | 760 | def tearDownClass(self): |
750 | 761 | """Change back to initial working dir and remove temp test directory. """ |
751 | 762 | os.chdir(self.working_dir) |
752 | | - shutil.rmtree(self.test_dir) |
| 763 | + shutil.rmtree(self.test_dir, onerror=GPGTestUtils.ignore_not_found_error) |
753 | 764 |
|
754 | 765 | def test_gpg_sign_and_verify_object_with_default_key(self): |
755 | 766 | """Create a signature using the default key on the keyring """ |
|
0 commit comments