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

PR: Add clip and overflow props #57

Merged
merged 8 commits into from
Jan 27, 2020

Conversation

goanpeca
Copy link
Contributor

No description provided.

@goanpeca goanpeca requested a review from freakboy3742 January 20, 2020 06:16
@goanpeca goanpeca force-pushed the enh/add-clip-overflow branch from 0267476 to 7281a1f Compare January 20, 2020 15:00
Copy link
Member

@freakboy3742 freakboy3742 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 on the whole; but the parser for rect needs a bit more work.

value = value.strip()

if value.startswith('rect'):
value = value.replace('rect(', '').replace(')', '')
Copy link
Member

Choose a reason for hiding this comment

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

There's a few holes in the parsing scheme. If you don't have a closing brace, it will succeed; if you don't have an opening brace, it will fail (but only because the first value won't be parsed cleanly. I understand the desire to keep this parsing scheme simple (and not invoke regexes), but this needs to be a little more robust.

Copy link
Contributor Author

@goanpeca goanpeca Jan 23, 2020

Choose a reason for hiding this comment

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

Move to use a regex 🤷‍♂...I guess it is simple and robust enough for this case?

is_shape('(1px, 3px, 2px, 4px)')

with self.assertRaises(ValidationError):
is_shape('rect(a, b, c, d)')
Copy link
Member

Choose a reason for hiding this comment

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

Some examples of "badly composed attempts at writing rect()" would be helpful here - e.g., mixing spaces and commas, missing open/close brace,...

Copy link
Contributor Author

@goanpeca goanpeca Jan 23, 2020

Choose a reason for hiding this comment

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

Updated tests

@goanpeca goanpeca force-pushed the enh/add-clip-overflow branch from 0fe1043 to f4f732b Compare January 23, 2020 02:32
@goanpeca goanpeca force-pushed the enh/add-clip-overflow branch from f4f732b to acf1e82 Compare January 23, 2020 02:34
@goanpeca
Copy link
Contributor Author

goanpeca commented Jan 23, 2020

Looks good on the whole; but the parser for rect needs a bit more work.

@freakboy3742 I updated the code to use a regex. It is way more robust and yet simple enough.

Thanks for the review! I left a couple of questions

@goanpeca goanpeca requested a review from freakboy3742 January 23, 2020 02:36

def rect(value):
"""Parse a given rect shape."""
from .shapes import Rect
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is here because the shape uses units, so to prevent circular imports.

I could not use shapes.Rect here but use it on validators and have the Rect import there, or I could move the Rect shape to this file.

Thoughts @freakboy3742 ?

Copy link
Member

Choose a reason for hiding this comment

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

Another (any my preferred) approach would be to have the constructor for Rect take fully parsed unit values, rather than deferring part of the parsing to the Rect constructor.

Copy link
Contributor Author

@goanpeca goanpeca Jan 23, 2020

Choose a reason for hiding this comment

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

Fixed

@goanpeca goanpeca force-pushed the enh/add-clip-overflow branch from 7d54f69 to 3616823 Compare January 23, 2020 03:00
Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

This is starting to look pretty good. I probably would have stayed with a simple string parsing approach rather than the regex - but the regex isn't too inscrutable, so I can live with that.

A couple of comments inline - including a recurring theme about splitting up test cases. This sort of test is what pytest parametrization is really good at - which is one of the reasons I've become a fan.


def rect(value):
"""Parse a given rect shape."""
from .shapes import Rect
Copy link
Member

Choose a reason for hiding this comment

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

Another (any my preferred) approach would be to have the constructor for Rect take fully parsed unit values, rather than deferring part of the parsing to the Rect constructor.

class ParseRectTests(TestCase):

def test_rect_valid(self):
# Comma separated
Copy link
Member

Choose a reason for hiding this comment

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

Insert comment about separating tests here. :-)

Copy link
Contributor Author

@goanpeca goanpeca Jan 23, 2020

Choose a reason for hiding this comment

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

Split tests

@goanpeca
Copy link
Contributor Author

This is starting to look pretty good. I probably would have stayed with a simple string parsing approach rather than the regex - but the regex isn't too inscrutable, so I can live with that.

I can go back to simple string parsing if you really really prefer

Copy link
Contributor Author

@goanpeca goanpeca left a comment

Choose a reason for hiding this comment

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

Another (any my preferred) approach would be to have the constructor for Rect take fully parsed unit values, rather than deferring part of the parsing to the Rect constructor.

Fixed

This is starting to look pretty good. I probably would have stayed with a simple string parsing approach rather than the regex - but the regex isn't too inscrutable, so I can live with that.

Went back to simple string parsing

A couple of comments inline - including a recurring theme about splitting up test cases. This sort of test is what pytest parametrization is really good at - which is one of the reasons I've become a fan.

I prefer to move to pytest on a separate PR (or the fonts one...) if that is what you were implying ;-)

@goanpeca goanpeca force-pushed the enh/add-clip-overflow branch from 98b485c to 89009e5 Compare January 23, 2020 06:02
@goanpeca goanpeca requested a review from freakboy3742 January 23, 2020 06:02
@freakboy3742
Copy link
Member

The reference to tests wasn't specifically about moving to pytest. Moving to PyTest makes test parametrization an option, which makes some of these tests a lot less verbose, but it's possible to split tests so they're more granular without necessarily moving to pytest.

I was more noting that the "this should be N little tests, not one big test" is a comment I've made on a couple of PRs.

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

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

Ok - we're definitely getting close now. We're down to some final small nitpicks.


def rect(value):
"""Parse a given rect shape."""
value = ' '.join([val.strip() for val in value.split()])
Copy link
Member

Choose a reason for hiding this comment

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

This could be done slightly more efficiently without constructing the inner list :

value = ' '.join(val.strip() for val in value.split())

will behave exactly the same, but it will process the content on the fly, rather than constructing a full list in memory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

self._bottom = bottom

def __eq__(self, other):
return other.__class__ == self.__class__ and other.to_tuple() == self.to_tuple()
Copy link
Member

Choose a reason for hiding this comment

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

Is this the only reason to have to_tuple? The extra function call isn't free, and the previous check has confirmed both objects are Rect... is there any reason we don't just confirm equality of the four attributes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm nope, the only reason was this, yes!

Fixed

def is_shape(value):
"""Check if given value is a shape and return it."""
try:
value = parser.rect(value)
Copy link
Member

Choose a reason for hiding this comment

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

There's a slight inconsistency in language here - is a rect one of multiple shape options? I know clip-path allows for other options, but in that context rect isn't one of the options. Is there any particular reason to use the word "shape" here? (and also in the exception raised by parser.rect())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

@goanpeca goanpeca requested a review from freakboy3742 January 26, 2020 22:41
@goanpeca
Copy link
Contributor Author

Ok - we're definitely getting close now. We're down to some final small nitpicks.

Fixed!

Thanks for the review @freakboy3742 !

Copy link
Member

@freakboy3742 freakboy3742 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! I'd still like to see more granularity in the tests; but I suspect we're at the point where a single PR to introduct pytest and parametrization would be more productive.

@freakboy3742 freakboy3742 merged commit 7dc27fd into beeware:master Jan 27, 2020
@goanpeca goanpeca deleted the enh/add-clip-overflow branch January 27, 2020 01:08
@goanpeca
Copy link
Contributor Author

Looks good! I'd still like to see more granularity in the tests; but I suspect we're at the point where a single PR to introduct pytest and parametrization would be more productive.

Agreed, that is on my todo. Opened an #61 to keep track of it.

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.

2 participants