Skip to content

Add more test cases for cautious-robot #20

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

Merged
merged 28 commits into from
Jul 30, 2024
Merged

Conversation

zoeduan
Copy link
Collaborator

@zoeduan zoeduan commented Jul 24, 2024

Added two test cases: test_download_images.py and test_buddycheck.py

@zoeduan zoeduan mentioned this pull request Jul 24, 2024
@zoeduan zoeduan requested a review from egrace479 July 24, 2024 17:29
@zoeduan zoeduan marked this pull request as ready for review July 24, 2024 17:29
@egrace479 egrace479 linked an issue Jul 24, 2024 that may be closed by this pull request
zoeduan and others added 4 commits July 25, 2024 20:28
Co-authored-by: Elizabeth Campolongo <38985481+egrace479@users.noreply.github.com>
Co-authored-by: Elizabeth Campolongo <38985481+egrace479@users.noreply.github.com>
…h buddy_id initialized. 2. removing the leading whitespace with self.image_source_file and self.check_source_file in setUp. 3. update missing_imgs to retain its original index
Copy link
Member

@egrace479 egrace479 left a comment

Choose a reason for hiding this comment

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

The extra initialization test is up to you, but there were some other areas where it's not quite testing the function (when it's not passed the buddy_id column name it should merge on just checksums regardless of whether there is a filename column in the checksum DataFrame).

zoeduan and others added 12 commits July 26, 2024 19:57
Co-authored-by: Elizabeth Campolongo <38985481+egrace479@users.noreply.github.com>
Co-authored-by: Elizabeth Campolongo <38985481+egrace479@users.noreply.github.com>
Co-authored-by: Elizabeth Campolongo <38985481+egrace479@users.noreply.github.com>
Co-authored-by: Elizabeth Campolongo <38985481+egrace479@users.noreply.github.com>
Co-authored-by: Elizabeth Campolongo <38985481+egrace479@users.noreply.github.com>
Co-authored-by: Elizabeth Campolongo <38985481+egrace479@users.noreply.github.com>
Co-authored-by: Elizabeth Campolongo <38985481+egrace479@users.noreply.github.com>
Co-authored-by: Elizabeth Campolongo <38985481+egrace479@users.noreply.github.com>
…h scenarios: success after retry and failure after retry
Copy link
Member

@egrace479 egrace479 left a comment

Choose a reason for hiding this comment

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

Since we are not removing the filename column from the checksum DataFrame, the filename columns both get suffixes in the merge. This isn't exposed, so I'm not worried about sticking with the default suffixes.

zoeduan and others added 3 commits July 29, 2024 13:27
Co-authored-by: Elizabeth Campolongo <38985481+egrace479@users.noreply.github.com>
Co-authored-by: Elizabeth Campolongo <38985481+egrace479@users.noreply.github.com>
…. Add testcases test_successful_download_with_subfolder and test_downsampled_image_creation_with_subfolder
@zoeduan zoeduan requested a review from thompsonmj July 29, 2024 23:19
@zoeduan
Copy link
Collaborator Author

zoeduan commented Jul 29, 2024

Hello @egrace479 @thompsonmj, I have updated the test cases, and now all the test cases run clear. Thanks for review the code!

@thompsonmj
Copy link
Contributor

In test_download_images.py, I'd add wait=0.1 to the test_success_after_retries and test_failure_after_retries tests to make tests go more quickly.

@thompsonmj
Copy link
Contributor

I also receive 1 error:

FAILED tests/test_buddycheck.py::TestBuddyCheck::test_check_alignment_empty_img_df - ValueError: Unable to fill values because RangeIndex cannot contain NA

Details:

=================================================================== FAILURES ====================================================================
_______________________________________________ TestBuddyCheck.test_check_alignment_empty_img_df ________________________________________________

self = <test_buddycheck.TestBuddyCheck testMethod=test_check_alignment_empty_img_df>

    def test_check_alignment_empty_img_df(self):
        source_df = pd.DataFrame(columns=['filename', 'checksum'])
        checksum_df = pd.read_csv(self.checksum_source_file.name)
>       merged_df = self.buddy_check.merge_on_filename_checksum(source_df, checksum_df, 'filename', 'checksum')

tests/test_buddycheck.py:136: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
src/cautiousrobot/buddy_check.py:34: in merge_on_filename_checksum
    merged_df = pd.merge(source_df,
../../.local/lib/python3.8/site-packages/pandas/core/reshape/merge.py:156: in merge
    return op.get_result(copy=copy)
../../.local/lib/python3.8/site-packages/pandas/core/reshape/merge.py:813: in get_result
    self._maybe_add_join_keys(result, left_indexer, right_indexer)
../../.local/lib/python3.8/site-packages/pandas/core/reshape/merge.py:986: in _maybe_add_join_keys
    rvals = algos.take_nd(taker, right_indexer, fill_value=rfill)
../../.local/lib/python3.8/site-packages/pandas/core/array_algos/take.py:110: in take_nd
    return arr.take(
../../.local/lib/python3.8/site-packages/pandas/core/indexes/base.py:1084: in take
    allow_fill = self._maybe_disallow_fill(allow_fill, fill_value, indices)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = RangeIndex(start=0, stop=3, step=1), allow_fill = True, fill_value = 0, indices = array([], dtype=int64)

    @final
    def _maybe_disallow_fill(self, allow_fill: bool, fill_value, indices) -> bool:
        """
        We only use pandas-style take when allow_fill is True _and_
        fill_value is not None.
        """
        if allow_fill and fill_value is not None:
            # only fill if we are passing a non-None fill_value
            if self._can_hold_na:
                if (indices < -1).any():
                    raise ValueError(
                        "When allow_fill=True and fill_value is not None, "
                        "all indices must be >= -1"
                    )
            else:
                cls_name = type(self).__name__
>               raise ValueError(
                    f"Unable to fill values because {cls_name} cannot contain NA"
                )
E               ValueError: Unable to fill values because RangeIndex cannot contain NA

../../.local/lib/python3.8/site-packages/pandas/core/indexes/base.py:1117: ValueError

@zoeduan
Copy link
Collaborator Author

zoeduan commented Jul 30, 2024

In test_download_images.py, I'd add wait=0.1 to the test_success_after_retries and test_failure_after_retries tests to make tests go more quickly.

Thank you! I updated test_download_images.py, it runs much faster!! Will commit my changes later.

@egrace479
Copy link
Member

I also receive 1 error:

FAILED tests/test_buddycheck.py::TestBuddyCheck::test_check_alignment_empty_img_df - ValueError: Unable to fill values because RangeIndex cannot contain NA

Details:
...

Strange, @thompsonmj, I see everything passing.

I very much like your wait = .1 suggestion for the retry tests!

@zoeduan
Copy link
Collaborator Author

zoeduan commented Jul 30, 2024

I also receive 1 error:

FAILED tests/test_buddycheck.py::TestBuddyCheck::test_check_alignment_empty_img_df - ValueError: Unable to fill values because RangeIndex cannot contain NA

Details:
...

Strange, @thompsonmj, I see everything passing.

I very much like your wait = .1 suggestion for the retry tests!

Same with me.

Copy link
Member

@egrace479 egrace479 left a comment

Choose a reason for hiding this comment

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

One fix and a question on the images.

Copy link
Member

Choose a reason for hiding this comment

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

What is the source of this (and the other) image?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I downloaded them from google image. If it is inappropriate, we can use other images.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What is the source of this (and the other) image?

Thank you! @egrace479 I have updated the testing images.

zoeduan and others added 2 commits July 30, 2024 12:09
Co-authored-by: Elizabeth Campolongo <38985481+egrace479@users.noreply.github.com>
Co-authored-by: Elizabeth Campolongo <38985481+egrace479@users.noreply.github.com>
@thompsonmj
Copy link
Contributor

On the issue of the test_check_alignment_empty_img_df test, when I execute that test with pytest, it raises the ValueError, but the test passes when run with unittest, which seems odd to me.

Regardless though, since the merge_on_filename_checksum method is only called in validate_download, we could add an assertion that neither input DataFrame for that method is empty since it would mean the user is doing something that doesn't match their expectations. Then we could remove the tests for empty inputs to merge_on_filename_checksum and add a test for validate_download with empty inputs, asserting that a custom exception is raised.

How does that sound?

@zoeduan zoeduan force-pushed the feature/enhance-testing branch from 90c07c0 to 98a3fd9 Compare July 30, 2024 20:57
…-e6316e1855d4 & 94c53a1f-6bd9-469f-85b9-b2ce93e90c21)

https://huggingface.co/datasets/imageomics/rare-species, Original source Smithsonian Institution, NMNH,
image1 from Invertebrate Zoology, CC-0 by Patricia Perez,
image2 from Entomology, CC-0 by Pixel Acuity LLC"
@zoeduan zoeduan force-pushed the feature/enhance-testing branch from 98a3fd9 to 90237f1 Compare July 30, 2024 21:07
Switch test from the merge method to the custom error in the validate method
Copy link
Member

@egrace479 egrace479 left a comment

Choose a reason for hiding this comment

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

Thanks for all the hard work on this one!!

@zoeduan zoeduan merged commit 2c986a2 into main Jul 30, 2024
2 checks passed
@zoeduan zoeduan deleted the feature/enhance-testing branch August 30, 2024 14:37
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.

Add tests
3 participants