-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
Conversation
0267476
to
7281a1f
Compare
There was a problem hiding this 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.
colosseum/validators.py
Outdated
value = value.strip() | ||
|
||
if value.startswith('rect'): | ||
value = value.replace('rect(', '').replace(')', '') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
tests/test_validators.py
Outdated
is_shape('(1px, 3px, 2px, 4px)') | ||
|
||
with self.assertRaises(ValidationError): | ||
is_shape('rect(a, b, c, d)') |
There was a problem hiding this comment.
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,...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated tests
0fe1043
to
f4f732b
Compare
f4f732b
to
acf1e82
Compare
@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 |
colosseum/parser.py
Outdated
|
||
def rect(value): | ||
"""Parse a given rect shape.""" | ||
from .shapes import Rect |
There was a problem hiding this comment.
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 ?
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
7d54f69
to
3616823
Compare
There was a problem hiding this 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.
colosseum/parser.py
Outdated
|
||
def rect(value): | ||
"""Parse a given rect shape.""" | ||
from .shapes import Rect |
There was a problem hiding this 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.
tests/test_parser.py
Outdated
class ParseRectTests(TestCase): | ||
|
||
def test_rect_valid(self): | ||
# Comma separated |
There was a problem hiding this comment.
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. :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split tests
I can go back to simple string parsing if you really really prefer |
There was a problem hiding this 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 ;-)
98b485c
to
89009e5
Compare
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. |
There was a problem hiding this 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.
colosseum/parser.py
Outdated
|
||
def rect(value): | ||
"""Parse a given rect shape.""" | ||
value = ' '.join([val.strip() for val in value.split()]) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
colosseum/shapes.py
Outdated
self._bottom = bottom | ||
|
||
def __eq__(self, other): | ||
return other.__class__ == self.__class__ and other.to_tuple() == self.to_tuple() |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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()
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
Fixed! Thanks for the review @freakboy3742 ! |
There was a problem hiding this 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.
Agreed, that is on my todo. Opened an #61 to keep track of it. |
No description provided.