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

Change from tempconfig to a config fixture in tests #3853

Merged
merged 2 commits into from
Jul 12, 2024

Conversation

JasonGrace2282
Copy link
Member

Before we were often doing

with tempconfig({}):
    ...

Which is just stupid, and it means that if one test forgets to do that, every test that depends on a value changed in that test is now screwed up. This is impossible to debug.
Instead, we can just create a fixture that resets config after every test.

@JasonGrace2282 JasonGrace2282 added enhancement Additions and improvements in general testing Anything related to testing the library labels Jul 12, 2024
@JasonGrace2282 JasonGrace2282 requested a review from behackl July 12, 2024 18:20
Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great change, thanks! I think we can merge this as-is, ignore the comments about the NamedTemporaryFiles for now; we should probably work on the tests in a more systematic way anyways.

Comment on lines +53 to +63
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
tmp_cfg.write(
"""
[CLI]
media_dir = this_is_my_favorite_path
video_dir = {media_dir}/videos
frame_height = 10
""",
)
tmp_cfg.close()
config.digest_file(tmp_cfg.name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It practically doesn't matter because the tests are run in an isolated environment anyways, but what do you think about rewriting this test such that the config file is deleted in the end? The tests could just be moved inside an appropriate context manager. (I can take care of it.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably a good idea, I'm all for cleaning up after our messes :)

np.testing.assert_allclose(config.frame_height, 10.0)
np.testing.assert_allclose(config.frame_width, 10.0)
def test_frame_size_if_frame_width(config, using_opengl_renderer, tmp_path):
tmp_cfg = tempfile.NamedTemporaryFile("w", dir=tmp_path, delete=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above for this test

frame_height = 10
""",
)
tmp_cfg.close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, is this the same test as before? 🧐

@behackl behackl merged commit 7562596 into ManimCommunity:main Jul 12, 2024
18 checks passed
@JasonGrace2282 JasonGrace2282 deleted the config-fixture branch July 12, 2024 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Additions and improvements in general testing Anything related to testing the library
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants