From e1e05d2d9153e17e3505e6c47b0728bfafb6c598 Mon Sep 17 00:00:00 2001 From: Tom Most Date: Sat, 20 Jul 2024 15:59:17 -0700 Subject: [PATCH] Test integration with the Hatch CLI This is documented behavior so it should have tests. --- tests/test_examples.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/tests/test_examples.py b/tests/test_examples.py index 118b7c0..5d83e3c 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -52,8 +52,7 @@ def test_setuptools_version(self): def test_hatchling_get_version(self): """ - example_hatchling has a version of 24.7.0, which may be retrieved - by the ``hatch version`` command. + example_hatchling has a version of 24.7.0. """ build_and_install(TEST_DIR.child("example_hatchling")) @@ -64,3 +63,37 @@ def test_hatchling_get_version(self): Version("example_hatchling", 24, 7, 0), ) self.assertEqual(metadata.version("example_hatchling"), "24.7.0") + + def test_hatch_version(self): + """ + The ``hatch version`` command reports the version of a package + packaged with hatchling. + """ + proc = run( + ["hatch", "version"], + cwd=TEST_DIR.child("example_hatchling").path, + check=True, + capture_output=True, + ) + + self.assertEqual(proc.stdout, b"24.7.0\n") + + def test_hatch_version_set(self): + """ + The ``hatch version`` command can't set the version so its output + tells the user to use ``incremental.update`` instead. + """ + proc = run( + ["hatch", "--no-color", "version", "24.8.0"], + cwd=TEST_DIR.child("example_hatchling").path, + check=False, + capture_output=True, + ) + suggestion = b"Run `python -m incremental.version --newversion 24.8.0` to set the version." + + self.assertGreater(proc.returncode, 0) + self.assertRegex( + proc.stdout, + # Hatch may wrap the output, so we are flexible about the specifics of whitespace. + suggestion.replace(b".", rb"\.").replace(b" ", b"\\s+"), + )