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
RecycleGridLayout : Fix layout when number of widgets match number of columns #7262
RecycleGridLayout : Fix layout when number of widgets match number of columns #7262
Conversation
The parametrised test seems to repeat the implementation, i think it's better to be less smart in such cases and be explicit about tho expected result, each parameter could be a tuple of (input, exptected_output) instead. Edit: i think it's a situation where a few lines of comments explaining the loogic of the implementation would be fine, up to you. |
Agree. But also, this is not testing the implementation directly, but rather an analog of the implementation. So if one changes the implementation, the test would not be helpful anymore. So it's better to test the actual implementation and use hard-coded input/output values as @tshirtman suggested. |
I think I wasn't clear enough with what I was trying to say, but could you test an actual gridlayout widget? Beause this basically tests that the current implementation is current. But if someone changes the gridlayout in the future, the test will not test that. |
@tshirtman Ah sorry for my explanation being not enough. There is a situation where we cannot just sort the view indices in ascending order as the latest commit shows. @matham No, you were clear enough. I pushed the latest commit before I read your comment.
OK, so is it ok to create a new function that implements that specific part, and use it in the unittests? or I better to use |
When I implemented the 'orientation', I left the original code as possible in order to avoid introducing new bugs. But maybe this |
Yeah, I'd say to call Or even better, create a actual recyclegridlayout (and normal gridlayout) and set the data/children, run |
Ultimately, it'd be nice if we can test that the widgets are laid out correctly, irrespective of the implementation. So I'm not sure if that would help. |
Perfect. Just one more thing, it's probably better if you use the clock fixture rather than the raw clock. |
class Test_layout:
def compute_layout(self, *, clock):
...
def test_case1(self, kivy_clock, ...):
self.compute_layout(..., clock=kivy_clock)
def test_case2(self, kivy_clock, ...):
self.compute_layout(..., clock=kivy_clock) This is not desirable, isn't it? |
I think that's fine!? It's just more verbose, but I don't really see another way that is not hacky. |
@matham OK, how about the following fixture? Do you think it's a good idea? # kivy/tests/fixtures.py
@pytest.fixture(scope='module')
def module_scope_kivy_clock():
# same as kivy_clock
# kivy/tests/test_uix_recyclegridlayout.py
global_kivy_clock = None
@pytest.fixture(scope='module', autouse=True)
def acquire_kivy_clock(module_scope_kivy_clock):
global global_kivy_clock
global_kivy_clock = module_scope_kivy_clock
yield module_scope_kivy_clock
global_kivy_clock = None
class Test_layout:
def compute_layout(...):
global_kivy_clock.tick() I myself am not sure this is good or not. (Also, don't merge the PR yet.) |
|
I think the way it is currently is better. It's simpler even if more verbose, which is not really a big deal.
Extra tests have never hurt anyone 😄 |
Feel free to merge if you're happy with it. |
@matham I think the pr is mergable now. I'd appreciate if you approve it again :) |
… columns (kivy#7262) * fix 'RecycleGridLayout.compute_visible_views()' * add more unittests * test the actual layout not the internal code * reduce the test code * add more test cases * edit comment * re-write the GridLayout's unittests * test the situation where only a part of the data is visible * use 'kivy_clock' fixture instead of raw Clock * make 'compute_visible_views()' readable * might improve performance * refactor the unittests * test the situations where view widgets are L-shaped rather than rectangle-shaped * revert an unnecessary change * avoid unnecessary list creation
Maintainer merge checklist
Component: xxx
label.api-deprecation
orapi-break
label.release-highlight
label to be highlighted in release notes.versionadded
,versionchanged
as needed.fixes #7255
I put "WIP" in the title because I feel like there is a better implemetation.