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

Tests: relocate 'ingredient_groups' from mandatory-tests to optional-tests. #1184

Conversation

jayaddison
Copy link
Collaborator

...and, at the same time, remove the ingredient_groups key from any data-driven test JSON expectation files for scrapers that don't implement custom retrieval of grouped ingredients.

This requires a small change to the test suite so that test expectations are not created when not required.

Resolves #1181.

…expectations where the corresponding scraper does not provide a custom implementation.
… when "ingredient_groups" exists as a key in the JSON test data.
@jayaddison jayaddison requested a review from jknndy July 23, 2024 16:49
@jayaddison jayaddison changed the title Tests: reloate 'ingredient_groups' from mandatory-tests to optional-tests. Tests: relocate 'ingredient_groups' from mandatory-tests to optional-tests. Jul 23, 2024
@jknndy
Copy link
Collaborator

jknndy commented Jul 23, 2024

This a great cleanup!

What do you think about removing the ingredient_group JSON key for the non-ingredient_group test of the sites that do contain the functionality? All sites that contain grouping have 2 test cases one covering the grouping functionality & another not, this could be another substantial clean up but would need to be done manually.

Alternatively, this currently passes if ingredient_groups is removed regardless if the scraper class contains an ingredient_group override. Using AbuelasCounter as an example you can remove the ingredient_groups key from *_2.json and the tests will still pass. I wonder if it would be possible to run a check the scraper class to see if an override exists and if so expect the JSON key. This would remove the possibility to implement the first idea unless we were to check the output to see if it is producing a single set of ingredients with a purpose of null and not expect the key in the JSON.

@jayaddison
Copy link
Collaborator Author

Both good ideas, yep! Just to check I understand them correctly:

  • Remove ingredient_groups from test data in cases where an alternate .json file already exists that covers the non-default / basic single-group case.
  • When a method has a custom implementation in a scraper, ensure that a JSON key exists with the same name (approximately similar to treating it as a mandatory-test field).

@jayaddison
Copy link
Collaborator Author

(and it took a few moments, but I understand what you mean about the first idea being more difficult to do if we implement the second idea)

@jayaddison
Copy link
Collaborator Author

This would remove the possibility to implement the first idea unless we were to check the output to see if it is producing a single set of ingredients with a purpose of null and not expect the key in the JSON.

I'd like to avoid this route if possible - our tests aren't strictly isolated from the library code at the moment, so there can be some behavioural interference between test code and library code -- but generally I think we should write tests that are not allowed to gain much (or ideally any) information about the corresponding scraper and its output before deciding what to assert on.

@jknndy
Copy link
Collaborator

jknndy commented Jul 24, 2024

  • Remove ingredient_groups from test data in cases where an alternate .json file already exists that covers the non-default / basic single-group case.

yep, exactly!

  • When a method has a custom implementation in a scraper, ensure that a JSON key exists with the same name (approximately similar to treating it as a mandatory-test field).

& yep again! I was thinking just about ingredient_groups but this could be implemented across all coverages.

I'd like to avoid this route if possible - our tests aren't strictly isolated from the library code at the moment, so there can be some behavioural interference between test code and library code -- but generally I think we should write tests that are not allowed to gain much (or ideally any) information about the corresponding scraper and its output before deciding what to assert on.

I agree, this is definitely a last resort kind of idea.

@jayaddison
Copy link
Collaborator Author

Ok, so, ignoring the last-resort situation for a moment, I think what we're talking about is whether test coverage should be enforced for overridden methods (case 2), or whether it is optional and we can omit the expectations if so (case 1).

Arguably test coverage reporting tools could already do the check from case 2 for us -- they could tell us that an overridden method hasn't been covered (coverage run -m unittest && coverage html for example, to generate an HTML test coverage report). Perhaps we could configure our continuous integration to let us know about methods without test coverage?

If we did use continuous integration to detect this using coverage tools, that still leaves a question about whether to remove the expectations in cases where we have multiple tests.

Whatever the scraper -- even for ones that don't override ingredient_groups -- we continue to check that the results are retrieval-consistent with ingredients.

@jknndy
Copy link
Collaborator

jknndy commented Jul 24, 2024

Ok, so, ignoring the last-resort situation for a moment, I think what we're talking about is whether test coverage should be enforced for overridden methods (case 2), or whether it is optional and we can omit the expectations if so (case 1).

After thinking about it more, I’m leaning towards case 1. Removing the test data from non-ingredient_groups tests offers the most cleanup. Additionally, if the developer went through the process of working out the ingredient_groups scraping they are likely to include test coverage for it. We can always track this approach for a while and revisit if it causes confusion.

note: are there any doc updates required as a result of this change?

Arguably test coverage reporting tools could already do the check from case 2 for us -- they could tell us that an overridden method hasn't been covered (coverage run -m unittest && coverage html for example, to generate an HTML test coverage report).

Thanks for the tip! Had no idea this existed, lots interesting info here.

Perhaps we could configure our continuous integration to let us know about methods without test coverage?

This sounds worth looking into but that may be a separate discussion. I've written code in the past to generate the missing coverages that could possibly be repurposed to do this.. i'll have to look around to see if i hung on to it.

@jayaddison
Copy link
Collaborator Author

Ok, so, ignoring the last-resort situation for a moment, I think what we're talking about is whether test coverage should be enforced for overridden methods (case 2), or whether it is optional and we can omit the expectations if so (case 1).

After thinking about it more, I’m leaning towards case 1. Removing the test data from non-ingredient_groups tests offers the most cleanup. Additionally, if the developer went through the process of working out the ingredient_groups scraping they are likely to include test coverage for it. We can always track this approach for a while and revisit if it causes confusion.

That makes sense to me - I'll go ahead with cleaning up those files.

note: are there any doc updates required as a result of this change?

Mm, good question - it seems quite likely. I'll check that too.

@jayaddison
Copy link
Collaborator Author

Ok, I think that's more-or-less ready now; glad for any more suggestions/review.

@jknndy
Copy link
Collaborator

jknndy commented Jul 24, 2024

Just one last thing, in the docs/in-depth-guide-ingredient-groups.md i think some changes are needed as well as the tests no longer automatically populate the ingredient_groups key

In addition to the usual tests a scraper requires, the tests also needs to check the groups and the ingredients in each group are correct for the recipe. For the test cases where there are no ingredient groups, this should check for a single IngredientGroup object with purpose=None and ingredients set to the output from the scraper's ingredients() function. For the test case with ingredient groups, the output should match the groups in the recipe.

Each test case will automatically inherit a test that checks to make sure the same ingredients are found in .ingredients() and in the groups returned from .ingredient_groups(), so there is no need to write this test in the scraper test cases.

Otherwise, looks good to go to me!

@jayaddison
Copy link
Collaborator Author

Good catch, thank you!

Copy link
Collaborator

@jknndy jknndy 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!

… existing documentation style uses long-lines.
…ause the existing documentation style uses long-lines."

This reverts commit 9a20e6f.
… existing documentation style uses long-lines.
@jayaddison jayaddison force-pushed the issue-1181/data-driven-tests-skip-unimplemented-ingredient-groups branch 2 times, most recently from d5f9006 to 0e4b446 Compare July 25, 2024 11:35
…is time try an integer `line_length` instead of `false`.
@jayaddison jayaddison force-pushed the issue-1181/data-driven-tests-skip-unimplemented-ingredient-groups branch from 4102f53 to 9066da3 Compare July 28, 2024 21:36
@jayaddison jayaddison merged commit 02bea98 into main Jul 28, 2024
18 checks passed
@jayaddison jayaddison deleted the issue-1181/data-driven-tests-skip-unimplemented-ingredient-groups branch July 28, 2024 21:51
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.

Tests: remove 'ingredient_groups' check for scrapers that don't support/implement ingredient groups.
2 participants