Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit tests for dicts #181

Open
jrob93 opened this issue Nov 7, 2024 · 0 comments
Open

Unit tests for dicts #181

jrob93 opened this issue Nov 7, 2024 · 0 comments

Comments

@jrob93
Copy link
Collaborator

jrob93 commented Nov 7, 2024

We use a lot of dicts and these often need to compared via assert in the unit tests. These comparisons should be almost equal as there will be small changes to float values due to reading/writing to/from file. This should be handled by pytest.approx but we also have nan values which seem to make this function fail.

I have written some code to compare key values directly, I should probably wrap this in a function for neatness:

from numpy.testing import assert_almost_equal

for x in test_dict.keys():
    test_val = test_dict[x]
    expect_val = expect_dict[x]
    if type(expect_val) == str:
        assert test_val == expect_val
    else:
        assert_almost_equal(test_val, expect_val)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant