Skip to content

Commit

Permalink
Add cmdline tests, trying to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
thatch committed Feb 2, 2024
1 parent a633028 commit 533c8ca
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion honesty/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,5 +658,5 @@ def select_versions(package: Package, operator: str, selector: str) -> List[Vers
return [pv]


if __name__ == "__main__":
if __name__ == "__main__": # pragma: no cover
cli(prog_name="honesty")
4 changes: 4 additions & 0 deletions honesty/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .archive import ArchiveTest
from .cache import CacheTest
from .checker import CheckerTest
from .cmdline import DownloadTest, ExtractTest, LicenseTest
from .deps import (
ConvertSdistRequiresTest,
DepWalkerTest,
Expand All @@ -16,6 +17,9 @@
"ArchiveTest",
"CacheTest",
"CheckerTest",
"LicenseTest",
"DownloadTest",
"ExtractTest",
"ConvertSdistRequiresTest",
"EnvironmentMarkersTest",
"FindCompatibleVersionTest",
Expand Down
37 changes: 37 additions & 0 deletions honesty/tests/cmdline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import hashlib
import unittest
from pathlib import Path

from click.testing import CliRunner

from ..cmdline import download, extract, license


class ExtractTest(unittest.TestCase):
def test_honesty_extract(self) -> None:
runner = CliRunner()
result = runner.invoke(extract, ["honesty==0.2.1"])
self.assertTrue(Path(result.output.strip(), "MANIFEST.in").exists())


class LicenseTest(unittest.TestCase):
def test_honesty_license(self) -> None:
runner = CliRunner()
result = runner.invoke(license, ["honesty==0.2.1"])
self.assertEqual("honesty==0.2.1: MIT\n", result.output)
self.assertEqual(0, result.exit_code)


class DownloadTest(unittest.TestCase):
def test_honesty_download(self) -> None:
runner = CliRunner()
result = runner.invoke(download, ["honesty==0.2.1"])
hasher = hashlib.sha1()
hasher.update(Path(result.output.strip()).read_bytes())
self.assertEqual("4c7f15d7f1c291ada81fe333d3672283bc7437f9", hasher.hexdigest())
self.assertEqual(0, result.exit_code)

result = runner.invoke(download, ["honesty==0.2.2"])
self.assertEqual(
"Error: The version 0.2.2 does not exist for honesty\n", result.output
)

0 comments on commit 533c8ca

Please sign in to comment.