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

Enhance the test coverage #339

Merged
merged 3 commits into from
May 22, 2024
Merged

Enhance the test coverage #339

merged 3 commits into from
May 22, 2024

Conversation

jrycw
Copy link
Contributor

@jrycw jrycw commented May 14, 2024

This PR tries to enhance our test coverage.

@codecov-commenter
Copy link

codecov-commenter commented May 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.61%. Comparing base (7eae1f2) to head (bc868dd).
Report is 37 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #339      +/-   ##
==========================================
+ Coverage   83.51%   85.61%   +2.09%     
==========================================
  Files          41       41              
  Lines        4308     4317       +9     
==========================================
+ Hits         3598     3696      +98     
+ Misses        710      621      -89     

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

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 test coverage! This is asking for changes beyond tests, so feel free to punt to me if you want.

I left a comment discussing whether pulling the font data outside of the _get_font_stack() function can...

  • cut out some of the recoding of font data in the tests
  • up test coverage by removing the big if/elif font name block

Thanks again for taking a look at this. It was really helpful to see _get_font_stack() surfaced, and to think of coverage here!

),
],
)
def test_get_font_stack_add_emoji_false(name, font_stack):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test seems like it has to recode the data in _get_font_stack(), which is a bit cumbersome. WDYT of...

  • pulling the data in _get_font_stack out of the function. For example, _helpers.py could have a top-level variable called FONT_STACKS that is a dictionary.
  • since add emoji does a single action---extend the font list---how about a single test case, checking that add emoji did that in one situation?

This will have the effect that a couple of lines in _get_font_stack() can replace all the if/elif font name checks.

Here's an example of what FONT_STACKS my look like in _helpers.py:

FONT_STACKS = {
    "system-ui": ["system-ui", "sans-serif"],
    "transitional": ["Charter", ...],
    ...
}

EMOJI_FONTS =  ["Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"]

This way, the test of add emoji can just check that the flag does something like...


# this could be wrong, but hopefully the gist of it makes sense :o 
# CASE 1:
assert _get_font_stack("system-ui", add_emoji=False) == FONT_STACK["system-ui"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@machow , thanks for your review. I'm not sure if the latest commit meets your expectations. I'm happy to hear your feedback if it doesn't.

@@ -38,3 +60,144 @@ def test_uppercases():

bad_letters = "#$!^%#tables"
assert set(bad_letters).difference(uppercases)


def test_get_font_stack_raises(font_stack_names):
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 font_stack_names might not be used here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good spot 😅.

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.

This looks great, thanks a ton! One tiny improvement could be adding a trailing comma to the shorter lists of fonts. E.g.

  • old: ["system-ui", "sans-serif"]
  • new: ["system-ui", "sans-serif",]

This way, the list entries will be put onto newlines. But I'm happy to merge as is!

@jrycw
Copy link
Contributor Author

jrycw commented May 16, 2024

Thanks for sharing this tip with me. Actually, there are times when I get confused about why the formatter doesn't perform as I expected, but now I understand the reason.

@machow
Copy link
Collaborator

machow commented May 22, 2024

Thanks again for this---this kind of stuff is so helpful!

@machow machow merged commit dd59578 into posit-dev:main May 22, 2024
11 checks passed
@jrycw jrycw deleted the improve-tests branch May 23, 2024 06:35
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