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

fix: Handle dotted parameters in classname #200

Merged

Conversation

taion
Copy link
Contributor

@taion taion commented Apr 21, 2020

Description

This fixes a regression from #197 for tests with parameters with dots in them.

Related Issues

#197, sorta

Checklist

  • This PR has sufficient test coverage.
  • I will merge this pull request with a semantic title.

Additional Comments

Without this change, the dotted parameter name would confuse the earlier iteration of the classname logic.


@pytest.mark.parametrize("parameter_1", ("foo",))
@pytest.mark.parametrize("parameter_2", ("bar",))
def test_doubly_parametrized(parameter_1, parameter_2, snapshot):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was about to implement something that just split on [, on closer inspection, it seemed better to traverse the node's parents.

Copy link
Collaborator

@iamogbz iamogbz left a comment

Choose a reason for hiding this comment

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

Nice catch

Comment on lines +22 to +27
return (
".".join(
node.name for node in self._node.listchain() if isinstance(node, Class)
)
or None
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would prefer we fixed the __valid_ids method so both __parse and classname are using the same logic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suspect classname doesn't need that logic – unlike with the others, in this context, we know that we have some set of valid Python identifiers anyway. It seems like it might, then, be slightly better to actually look for classes in the node hierarchy, as per this implementation?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm missed this yesterday, it's an easy enough refactor to revert. @noahnu what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I mean, that's what this implementation does – listchain shows all the current "nodes" in the test chain (modules, classes, &c.), so I'm going off that directly.

The alternative is just to split on [ and ignoring the part after that in __valid_ids before splitting on ., which gets you to the same place.

@iamogbz iamogbz changed the base branch from master to fix-location-classname April 22, 2020 01:41
@iamogbz iamogbz merged commit d961f7c into syrupy-project:fix-location-classname Apr 22, 2020
syrupy-bot pushed a commit that referenced this pull request Apr 22, 2020
## [0.4.2](v0.4.1...v0.4.2) (2020-04-22)

### Bug Fixes

* Handle dotted parameters in classname ([#200](#200)) ([d961f7c](d961f7c))
@syrupy-bot
Copy link
Contributor

🎉 This PR is included in version 0.4.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@taion taion deleted the fix-location-classname branch April 22, 2020 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants