From 533c8cadf4d06ae818ae67a8db6997c59c9c4978 Mon Sep 17 00:00:00 2001 From: Tim Hatch Date: Thu, 1 Feb 2024 20:59:37 -0800 Subject: [PATCH] Add cmdline tests, trying to increase coverage --- honesty/cmdline.py | 2 +- honesty/tests/__init__.py | 4 ++++ honesty/tests/cmdline.py | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 honesty/tests/cmdline.py diff --git a/honesty/cmdline.py b/honesty/cmdline.py index cc74feb..b85ddd4 100644 --- a/honesty/cmdline.py +++ b/honesty/cmdline.py @@ -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") diff --git a/honesty/tests/__init__.py b/honesty/tests/__init__.py index cc69bd0..909769a 100644 --- a/honesty/tests/__init__.py +++ b/honesty/tests/__init__.py @@ -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, @@ -16,6 +17,9 @@ "ArchiveTest", "CacheTest", "CheckerTest", + "LicenseTest", + "DownloadTest", + "ExtractTest", "ConvertSdistRequiresTest", "EnvironmentMarkersTest", "FindCompatibleVersionTest", diff --git a/honesty/tests/cmdline.py b/honesty/tests/cmdline.py new file mode 100644 index 0000000..171d49e --- /dev/null +++ b/honesty/tests/cmdline.py @@ -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 + )