Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
yliu120 committed Nov 12, 2024
1 parent 1c0f107 commit 5dec645
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/version_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
(?P<version>[0-9]+\.[0-9]+\.[0-9]+) # main version; like '0.4.16'
(?:\.dev(?P<dev>[0-9]+))? # optional dev version; like '.dev20230908'
(?:\+(?P<local>[a-zA-Z0-9_]+))? # optional local version; like '+g6643af3c3'
(?:\+(?P<suffix>[a-zA-Z0-9_]+))? # optional custom suffix; like 'test'
$ # end of string
""", re.VERBOSE)

Expand Down Expand Up @@ -61,11 +62,12 @@ def assert_no_subprocess_call():


@contextlib.contextmanager
def assert_subprocess_call():
def assert_subprocess_call(stdout: bytes | None = None):
"""Run code, asserting that subprocess.Popen *is* called at least once."""
with mock.patch("subprocess.Popen") as mock_Popen:
mock_Popen.return_value.communicate.return_value = (stdout, b"")
yield
mock_Popen.assert_called()
mock_Popen.return_value.communicate.assert_called()


class JaxVersionTest(unittest.TestCase):
Expand Down Expand Up @@ -150,7 +152,7 @@ def testBuildVersionFromEnvironment(self):
with jtu.set_env(JAX_RELEASE=None, JAXLIB_RELEASE=None,
JAX_NIGHTLY=None, JAXLIB_NIGHTLY=None,
JAX_CUSTOM_VERSION_SUFFIX="test"):
with assert_subprocess_call():
with assert_subprocess_call(stdout=b"1731433958-1c0f1076e"):
version = jax.version._get_version_for_build()
self.assertTrue(version.startswith(f"{base_version}.dev"))
self.assertTrue(version.endswith("test"))
Expand Down

0 comments on commit 5dec645

Please sign in to comment.