-
Notifications
You must be signed in to change notification settings - Fork 321
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
Convert some tests to pytest #1693
base: main
Are you sure you want to change the base?
Convert some tests to pytest #1693
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For your test plan, include the steps you ran to make sure that things worked - in this case it's straightforward, I'd accept both
Ran py.test on updated tests
and
CI will show new tests work
I think we can clean up some of the extra features a little, comments inline
@pytest.fixture | ||
def file_content(): | ||
""" | ||
Fixture to open and yield file content for testing, | ||
then close the file after the test. | ||
""" | ||
with open(TEST_FILE, "rb") as f: | ||
yield f.read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure that you need a fixture of this - the test can just open itself.
Fixtures are helpful when you are sharing setup between tests, and here's there is only one test.
return [ | ||
("a", "a"), | ||
("a ", "a"), | ||
] | ||
|
||
def get_compare_hash_cases(self): | ||
@pytest.fixture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blocking: This is definitely doesn't need a fixture! You can just use a list!
@pytest.fixture | ||
def validate_hash_cases(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blocking: This doesn't look like it needs to be a fixture - it looks like a better fit for pytest.mark.parametrize
return [] | ||
|
||
def get_matches_str_cases(self): | ||
@pytest.fixture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blocking: Ditto that this looks like a better match for pytest.mark.parametrize
@@ -1,21 +1,14 @@ | |||
# Copyright (c) Meta Platforms, Inc. and affiliates. | |||
|
|||
import unittest | |||
|
|||
import pytest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file looks good
assert UrlMD5Signal.hash_from_str(URL_TEST) == URL_TEST_MD5, "MD5 hash does not match" | ||
|
||
class UrlMD5SignalTestCase(unittest.TestCase): | ||
def test_can_hash_simple_url(self): | ||
assert URL_TEST_MD5 == UrlMD5Signal.hash_from_str( | ||
URL_TEST | ||
), "MD5 hash does not match" | ||
|
||
def test_can_hash_full_url(self): | ||
assert URL_TEST_MD5 == UrlMD5Signal.hash_from_str( | ||
FULL_URL_TEST | ||
), "MD5 hash does not match" | ||
def test_can_hash_full_url(): | ||
assert UrlMD5Signal.hash_from_str(FULL_URL_TEST) == URL_TEST_MD5, "MD5 hash does not match" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: The existing asset comments don't seem to add much, but I think it's fine to ignore
), | ||
], | ||
) | ||
@pytest.fixture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignorable: While this might be a misuse of feature, fixtures are basically a 1:1 mapping for setUp, so I think this a faithful translation
Summary
Fixes #1686
Test Plan
Fixes #1686