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 5 commits into
base: main
Choose a base branch
from

Conversation

ZeyadTarekk
Copy link

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!

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

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

@@ -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

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