Skip to content

Commit

Permalink
Add misc gpg test updates
Browse files Browse the repository at this point in the history
- Updates gpg tests to cover missing lines in gpg-subpackage.

- One feature, a warning about unhashed information added in
in-toto/in-toto#288, remains uncovered. To not break tox builds,
the required coverage threshold is lowered to 99%

- This commit also enables output buffering on the unittest runner,
i.e. to hide most of the test output until a test fails. See
in-toto/in-toto#240 for details.
  • Loading branch information
lukpueh committed Aug 9, 2019
1 parent 5934d68 commit 2453d98
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion tests/aggregate_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def check_usable_gpg():
if __name__ == '__main__':
check_usable_gpg()
suite = unittest.TestLoader().discover("tests", top_level_dir=".")
all_tests_passed = unittest.TextTestRunner(verbosity=1).run(suite).wasSuccessful()
all_tests_passed = unittest.TextTestRunner(
verbosity=1, buffer=True).run(suite).wasSuccessful()
if not all_tests_passed:
sys.exit(1)
11 changes: 10 additions & 1 deletion tests/test_gpg.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,12 @@ def test_get_verified_subkeys(self):


def test_get_pubkey_bundle_errors(self):
"""Pass wrong keyid with valid gpg data to trigger KeyNotFoundError. """
"""Test correct error raising in get_pubkey_bundle. """
# Call without key data
with self.assertRaises(KeyNotFoundError):
get_pubkey_bundle(None, "deadbeef")

# Pass wrong keyid with valid gpg data to trigger KeyNotFoundError.
not_associated_keyid = "8465A1E2E0FB2B40ADB2478E18FB3F537E0C8A17"
with self.assertRaises(KeyNotFoundError):
get_pubkey_bundle(self.raw_key_data, not_associated_keyid)
Expand Down Expand Up @@ -496,6 +501,10 @@ def tearDownClass(self):
os.chdir(self.working_dir)
shutil.rmtree(self.test_dir)

def test_gpg_export_pubkey_error(self):
"""Test correct error is raised if function called incorrectly. """
with self.assertRaises(ValueError):
gpg_export_pubkey("not-a-key-id")

def test_gpg_export_pubkey(self):
""" export a public key and make sure the parameters are the right ones:
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ deps =

commands =
coverage run tests/aggregate_tests.py
coverage report -m --fail-under 100
coverage report -m --fail-under 99

0 comments on commit 2453d98

Please sign in to comment.