Skip to content

Commit

Permalink
Merge pull request #66 from uclahs-cds/nwiltsie-fix-tests
Browse files Browse the repository at this point in the history
Resolve non-determinism with NFTestENV tests
  • Loading branch information
nwiltsie authored Jun 24, 2024
2 parents c9cbf2e + 0d05f30 commit 84ffdbd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

### Fixed
- Make `nftest` with no arguments print usage and exit
- Resolve non-determinism in NFTestENV unit tests

---

Expand Down
3 changes: 3 additions & 0 deletions test/unit/test_NFTestAssert.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
@mock.patch("nftest.NFTestAssert.NFTestAssert", wraps=NFTestAssert)
def test_get_assert_method_value_error(mock_assert):
"""Tests value error from get_assert_method when given `method` is not supported"""
# Make an NFTestAssert object
NFTestAssert("", "")

assert_method = "nomethod"
mock_assert.return_value.script = None
mock_assert.return_value.method = assert_method
Expand Down
9 changes: 9 additions & 0 deletions test/unit/test_NFTestEnv.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ def test_nftest_env_load(monkeypatch):
monkeypatch.setenv("NFT_LOG_LEVEL", test_log_level)
monkeypatch.setenv("NFT_LOG", test_log_file)

# Clear any existing singleton value
NFTestENV._instances.pop(NFTestENV, None) # pylint: disable=protected-access
nftest_env = NFTestENV()

assert NFTestENV in NFTestENV._instances # pylint: disable=protected-access

assert nftest_env.NFT_OUTPUT == test_out_directory
assert nftest_env.NFT_TEMP == test_temp_directory
assert nftest_env.NFT_INIT == test_init_directory
Expand All @@ -32,3 +36,8 @@ def test_singleton():
nftest_env2 = NFTestENV()

assert id(nftest_env1) == id(nftest_env2)

NFTestENV._instances.pop(NFTestENV, None) # pylint: disable=protected-access
nftest_env3 = NFTestENV()

assert id(nftest_env1) != id(nftest_env3)

0 comments on commit 84ffdbd

Please sign in to comment.