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

More tests for local.py #70

Merged
merged 2 commits into from
Dec 18, 2024
Merged

More tests for local.py #70

merged 2 commits into from
Dec 18, 2024

Conversation

mdellabitta
Copy link
Contributor

@mdellabitta mdellabitta commented Dec 18, 2024

Important

Add tests to test_local.py for edge cases and improve coverage, including file not found and empty file scenarios.

  • Tests Added:
    • test_clean_up_tmp_file_none_does_not_raise: Ensures clean_up_tmp_file does not raise errors with None.
    • test_get_file_hash_file_not_found: Checks get_file_hash raises FileNotFoundError for non-existent files.
    • test_get_file_hash_empty_file: Verifies get_file_hash returns correct hash for empty files.
    • test_get_content_type_magic_called: Uses unittest.mock.patch to ensure magic.from_file is called correctly.
    • test_get_content_type_file_not_found: Ensures get_content_type raises FileNotFoundError for non-existent files.
    • test_get_bytes_hash_empty_string: Verifies get_bytes_hash returns correct hash for empty strings.
  • Misc:
    • Removed unnecessary print statement in setup_and_teardown_temp_dir.

This description was created by Ellipsis for cfd00c3. It will automatically update as commits are pushed.

Copy link

codacy-production bot commented Dec 18, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.19% (target: -1.00%) 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (4a691a3) 819 758 92.55%
Head commit (cfd00c3) 841 (+22) 780 (+22) 92.75% (+0.19%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#70) 25 25 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to 42be47c in 1 minute and 3 seconds

More details
  • Looked at 57 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 7 drafted comments based on config settings.
1. tests/test_local.py:58
  • Draft comment:
    The comment is unnecessary as the test name is self-explanatory. Consider removing it.
  • Reason this comment was not posted:
    Confidence changes required: 10%
    The test function test_clean_up_tmp_file_none_does_not_raise is correctly testing that passing None to clean_up_tmp_file does not raise an error. However, the comment is unnecessary as the test name is self-explanatory.
2. tests/test_local.py:62
  • Draft comment:
    Good use of pytest.raises to test for FileNotFoundError.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The test function test_get_file_hash_file_not_found correctly tests that a FileNotFoundError is raised when a non-existent file is passed to get_file_hash. The test is well-structured and clear.
3. tests/test_local.py:66
  • Draft comment:
    Good test for handling empty files in get_file_hash.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The test function test_get_file_hash_empty_file is correctly testing the hash of an empty file. The test is well-structured and clear.
4. tests/test_local.py:73
  • Draft comment:
    Good use of unittest.mock.patch to mock magic.from_file.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The test function test_get_content_type_magic_called uses unittest.mock.patch to mock magic.from_file. This is a good practice to isolate the test from external dependencies.
5. tests/test_local.py:83
  • Draft comment:
    Good use of pytest.raises to test for FileNotFoundError.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The test function test_get_content_type_file_not_found correctly tests that a FileNotFoundError is raised when a non-existent file is passed to get_content_type. The test is well-structured and clear.
6. tests/test_local.py:87
  • Draft comment:
    Good test for handling empty strings in get_bytes_hash.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The test function test_get_bytes_hash_empty_string is correctly testing the hash of an empty string. The test is well-structured and clear.
7. tests/test_local.py:1
  • Draft comment:
    Ensure no hardcoded API keys are present in the code. This file is clear of such issues.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The code does not contain any hardcoded API keys, so it adheres to the rule about not hardcoding API keys in the source code.

Workflow ID: wflow_SXquJTkRilfJNLrm


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Incremental review on cfd00c3 in 21 seconds

More details
  • Looked at 33 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. tests/test_local.py:35
  • Draft comment:
    The use of usedforsecurity=False in hashlib.sha1 is appropriate here since SHA-1 is not recommended for security purposes. This is consistent with its usage in other parts of the code.
  • Reason this comment was not posted:
    Confidence changes required: 0%
    The use of usedforsecurity=False in hashlib.sha1 is not necessary for non-security purposes, but it is a good practice to explicitly state it when using SHA-1, which is considered weak for security purposes. This is consistent across multiple instances in the code.

Workflow ID: wflow_1rmY15jaLBgG9mYV


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

@mdellabitta mdellabitta merged commit 02a9c94 into main Dec 18, 2024
10 checks passed
@mdellabitta mdellabitta deleted the more-local-tests branch December 18, 2024 21:13
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.

1 participant