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

Convert some tests to pytest #1693

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ZeyadTarekk
Copy link
Contributor

Summary

Fixes #1686

Test Plan

Fixes #1686

Copy link
Contributor

@Dcallies Dcallies left a 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

Comment on lines +12 to +19
@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()
Copy link
Contributor

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
Copy link
Contributor

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!

Copy link
Contributor

Choose a reason for hiding this comment

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

Any response on this unaddressed blocking comment?

Comment on lines +13 to +14
@pytest.fixture
def validate_hash_cases(self):
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Any response on this unadressed blocking comment?

return []

def get_matches_str_cases(self):
@pytest.fixture
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Any response on this unaddressed blocking comment?

@@ -1,21 +1,14 @@
# Copyright (c) Meta Platforms, Inc. and affiliates.

import unittest

import pytest
Copy link
Contributor

Choose a reason for hiding this comment

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

This file looks good

Comment on lines 11 to 14
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"
Copy link
Contributor

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
Copy link
Contributor

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

@ZeyadTarekk ZeyadTarekk requested a review from Dcallies December 9, 2024 22:48
@ZeyadTarekk
Copy link
Contributor Author

@Dcallies could you check that PR? I have fixed the requested changes

Copy link
Contributor

@Dcallies Dcallies left a comment

Choose a reason for hiding this comment

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

Hey @ZeyadTarekk, a few things, you said that you addressed all the feedback. However, I note that there are comments prefixed with "blocking:" which appear unchanged, and so are unaddressed. If you think that there is something I am missing and you think the code should actually be changed, you need to explain why that is. Otherwise, I will send it back to you for unaddressed blocking comments.

I note the presence of unaddressed blocking comments, and so I am sending it back to you to address them with code changes, or respond using github comments with why they should not be addressed. Can you do that, and once you have done so, hit "Request Review"?

return [
("a", "a"),
("a ", "a"),
]

def get_compare_hash_cases(self):
@pytest.fixture
Copy link
Contributor

Choose a reason for hiding this comment

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

Any response on this unaddressed blocking comment?

Comment on lines +13 to +14
@pytest.fixture
def validate_hash_cases(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Any response on this unadressed blocking comment?

return []

def get_matches_str_cases(self):
@pytest.fixture
Copy link
Contributor

Choose a reason for hiding this comment

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

Any response on this unaddressed blocking comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pytx][mlh] Convert some tests in threatexchange/signal_type/ to py.test
3 participants