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 several tests for different formatting methods #260

Merged
merged 21 commits into from
Apr 10, 2024
Merged

Conversation

rich-iannone
Copy link
Member

@rich-iannone rich-iannone commented Apr 2, 2024

Quite a few of the formatting methods had very low test coverage so this PR provides some testing for the following:

  • fmt_roman()
  • fmt_bytes()
  • fmt_time()
  • fmt_datetime()
  • fmt_markdown()
  • fmt_nanoplot()

@github-actions github-actions bot temporarily deployed to pr-260 April 2, 2024 00:44 Destroyed
@codecov-commenter
Copy link

codecov-commenter commented Apr 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.92%. Comparing base (d4178e0) to head (c9ff081).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #260      +/-   ##
==========================================
+ Coverage   75.26%   79.92%   +4.66%     
==========================================
  Files          41       41              
  Lines        4180     4180              
==========================================
+ Hits         3146     3341     +195     
+ Misses       1034      839     -195     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot temporarily deployed to pr-260 April 2, 2024 00:54 Destroyed
@github-actions github-actions bot temporarily deployed to pr-260 April 2, 2024 01:15 Destroyed
@github-actions github-actions bot temporarily deployed to pr-260 April 2, 2024 01:22 Destroyed
@github-actions github-actions bot temporarily deployed to pr-260 April 2, 2024 01:31 Destroyed
@github-actions github-actions bot temporarily deployed to pr-260 April 2, 2024 01:48 Destroyed
@github-actions github-actions bot temporarily deployed to pr-260 April 2, 2024 04:50 Destroyed
@github-actions github-actions bot temporarily deployed to pr-260 April 2, 2024 05:00 Destroyed
@github-actions github-actions bot temporarily deployed to pr-260 April 2, 2024 05:04 Destroyed
@github-actions github-actions bot temporarily deployed to pr-260 April 2, 2024 13:49 Destroyed
@github-actions github-actions bot temporarily deployed to pr-260 April 2, 2024 13:53 Destroyed
@rich-iannone rich-iannone marked this pull request as ready for review April 2, 2024 14:00
@rich-iannone rich-iannone requested a review from machow April 2, 2024 14:00
Copy link
Collaborator

@machow machow 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 working on upping our test game. I left some feedback on...

  • reducing the number of parameters set in @pytest.mark.parametrize (which were resulting in things having to be constantly reset back to defaults)
  • leaning away from using the same long list of inputs across many case, in favor of individual inputs which test new & distinct bits of underlying logic
  • providing more informative assertions for fmt_nanoplot, and using fewer inputs (or clarifying what we're testing their above and beyond what's tested for _generate_nanoplot).

tests/test_formats.py Outdated Show resolved Hide resolved


@pytest.mark.parametrize(
"time_style,x_out",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since each case is run against the same 7 input times, it's not clear which of these inputs tests something new per timestyle, and which is redundant.

Rather than each case involving a time_style and a the same list of 7 inputs, can you make each case a time_style, 1 input, and the output expected? A case should only be added if it tests some new bit underlying logic.

# ------------------------------------------------------------------------------


@pytest.mark.parametrize(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same feedback as above, on splitting into single input cases. It appears the underlying logic is largely babel's format_datetime, so you don't need to re-test that (but it makes sense there's a lot of stitching of arguments to fmt_datetime that need to get tested).



@pytest.mark.parametrize(
"standard,decimals,use_seps,force_sign,incl_space,x_out",
Copy link
Collaborator

Choose a reason for hiding this comment

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

See feedback on avoiding using many parameters, and resetting things to their default arguments.

See also feedback on using 1 long input across all cases. I can't tell which values in the output tell us something new. For example all the outputs contain "-342 B", so it's not clear what I should learn there across the 5 parameter set cases.

(Sometimes tests do need to validate that some result is unchanged, but it seems likely the testing here is maybe doing that repeatedly for the same underlying logic)

),
],
)
def test_fmt_bytes(
Copy link
Collaborator

Choose a reason for hiding this comment

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

See feedback on parametrizing and not using the same inputs for everything

# ------------------------------------------------------------------------------


@pytest.mark.parametrize(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I strongly suspect you don't need to test that upper works on many variations of inputs values. (one is probably fine).

return all(bool(re.match("^<div><svg.*</svg></div>$", x)) for x in nanoplot_str)


@pytest.mark.parametrize(
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like many of the tests below...

  • test across a wide range of inputs (10 rows in a DataFrame)
  • only assert that the nanoplot exists with a div and svg tag

Please re-write so that it clear what each cases is testing, and their is a more specific assertion. For example, if reference line is "mean", does that mean the line is the average across rows? If so, in order to write these tests, you may need to reduce the number of input rows (e.g. to two), and test the exact value of the reference line in resulting nanoplots.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If some of these parameters end up being tested more thoroughly in another place (e.g. _generate_nanoplots), then we should think about what parameters need to be tested at this level and how thoroughly (based on the underlying logic in the fmt_nanoplot function).

assert _all_vals_nanoplot_output(res)


@pytest.mark.parametrize(
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above feedback. It's not clear what specific behaviors are being tested here. There are likely too many inputs, and the assertions are not specific enough.

It's okay to include the inputs in the parameters, if each case requires it's own (minimal) set of inputs to be meaningful. If the specification of arguments, inputs, and results checks are two cumbersome for @pytest.mark.parametrize, then it may be a signal to put each in its own function.

assert _all_vals_nanoplot_output(res_2)


@pytest.mark.parametrize(
Copy link
Collaborator

Choose a reason for hiding this comment

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

See above feedback

@github-actions github-actions bot temporarily deployed to pr-260 April 3, 2024 15:00 Destroyed
@github-actions github-actions bot temporarily deployed to pr-260 April 3, 2024 20:02 Destroyed
@github-actions github-actions bot temporarily deployed to pr-260 April 3, 2024 20:59 Destroyed
@github-actions github-actions bot temporarily deployed to pr-260 April 4, 2024 02:39 Destroyed
@github-actions github-actions bot temporarily deployed to pr-260 April 5, 2024 18:31 Destroyed
@github-actions github-actions bot temporarily deployed to pr-260 April 5, 2024 18:31 Destroyed
@rich-iannone
Copy link
Member Author

I believe all the comments have been addressed through the changes we made during code pairing. I handled a merge conflict and reformatted to satisfy the pre-commit error.

Copy link
Collaborator

@machow machow left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for spending time to up the coverage here :)

@machow machow merged commit b22072d into main Apr 10, 2024
9 checks passed
@rich-iannone rich-iannone deleted the add-fmt-method-tests branch April 10, 2024 18:14
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.

None yet

3 participants