Skip to content

Commit

Permalink
Test integration Hatch CLI a bit
Browse files Browse the repository at this point in the history
This is documented behavior so it should have tests.
  • Loading branch information
twm committed Jul 20, 2024
1 parent 14fea8b commit d68f189
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand All @@ -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+"),
)

0 comments on commit d68f189

Please sign in to comment.