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

Add txt_op unit test #177

Merged
merged 4 commits into from
Feb 18, 2024
Merged

Add txt_op unit test #177

merged 4 commits into from
Feb 18, 2024

Conversation

SayaZhang
Copy link
Collaborator

  1. add txt_op unit test
  2. update tests file directory

@@ -0,0 +1,89 @@
import unittest

from moto import mock_s3
Copy link
Owner

@CambioML CambioML Feb 16, 2024

Choose a reason for hiding this comment

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

It looks like the build is failing due to moto is not in pyproject.toml as a dependency.

I never used moto instead unittest mock. Personally, I would prefer to use mock from unittest https://docs.python.org/3/library/unittest.mock.html. But, let's discuss and maybe leave it to future tasks.

Based on my lower comment, after you delete, test_load_from_s3 and remove from moto import. You unittest should pass build.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, I deleted test_load_from_s3 and removed import moto. The test_load_from_s3 should be added in read_file unit test file.

# arrange
node = Node(
name="node1",
value_dict={"filename": "tests/op/extract/data/empty.txt"},
Copy link
Owner

Choose a reason for hiding this comment

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

qq: this looks like a your must run the unittest in the root folder. However, people might run unittest in the sub load folder which might cause problem for this unittest.

Usually, I will not test I/O as well as external function call such as read_file in extract_txt_op. Instead, I would mock it with return_value to test method specific logic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, I changed reading local file to mock it with return_value.
Does read_file need to test I/O by reading the local file and s3 file?

tests/op/extract/load/test_txt_op.py Outdated Show resolved Hide resolved
Comment on lines 42 to 45
conn = boto3.resource("s3", region_name="us-west-2")
conn.create_bucket(Bucket="uniflow-test")
s3 = boto3.client("s3", region_name="us-west-2")
s3.put_object(Bucket="uniflow-test", Key="test.txt", Body="mycontent")
Copy link
Owner

Choose a reason for hiding this comment

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

qq: is this mocking a file is put in s3?

tests/op/extract/load/test_txt_op.py Outdated Show resolved Hide resolved
)
def test_call(self, mock_read_file):
# arrange
node = Node(name="node1", value_dict={"filename": "mocked_file_path"})
Copy link
Owner

Choose a reason for hiding this comment

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

nit: it might worth to add two more unittest to test with more than one node and no node. You should aggregate all into a single test_call through parameterized unit testing. https://medium.com/@samarthgvasist/parameterized-unit-testing-in-python-9be82fa7e17f

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

tests/op/extract/load/test_txt_op.py Outdated Show resolved Hide resolved
@CambioML CambioML merged commit 05bd767 into CambioML:main Feb 18, 2024
5 checks passed
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

Successfully merging this pull request may close these issues.

2 participants