-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f4008f
commit 9e7afcd
Showing
2 changed files
with
55 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,60 @@ | ||
import pytest | ||
|
||
|
||
def test_remove_widget(): | ||
@pytest.fixture( | ||
scope='session', params=(True, False), ids=lambda v: 'loop=' + str(v)) | ||
def loop(request): | ||
return request.param | ||
|
||
|
||
def test_remove_widget(loop): | ||
from kivy.uix.carousel import Carousel | ||
from kivy.uix.widget import Widget | ||
|
||
c = Carousel() | ||
w = Widget() | ||
c.add_widget(w) | ||
c = Carousel(loop=loop) | ||
assert c.index is None | ||
assert c.current_slide is None | ||
assert len(c.children) == 0 | ||
assert len(c.slides) == 0 | ||
|
||
N_SLIDES = 4 | ||
for i in range(N_SLIDES): | ||
c.add_widget(Widget()) | ||
assert c.index == 0 | ||
assert c.current_slide == c.slides[0] | ||
assert len(c.children) == 3 if loop else 2 | ||
assert len(c.slides) == N_SLIDES | ||
|
||
# test issue #6370 | ||
c.index = len(c.slides) - 1 | ||
c.remove_widget(c.slides[0]) | ||
|
||
# remove a slide(smaller index than the current_slide's). | ||
c.index = 1 | ||
old_current_slide = c.current_slide | ||
c.remove_widget(c.slides[c.index - 1]) | ||
assert c.index == 0 | ||
assert c.current_slide is old_current_slide | ||
assert len(c.children) == 2 | ||
assert len(c.slides) == 2 | ||
|
||
# remove a slide(bigger index than the current_slide's). | ||
old_current_slide = c.current_slide | ||
c.remove_widget(c.slides[c.index + 1]) | ||
assert c.index == 0 | ||
assert c.current_slide is old_current_slide | ||
assert len(c.children) == 1 | ||
assert len(c.slides) == 1 | ||
c.remove_widget(w) | ||
|
||
# remove the current_slide(the last one left). | ||
c.remove_widget(c.current_slide) | ||
assert c.index is None | ||
assert c.current_slide is None | ||
assert len(c.children) == 0 | ||
assert len(c.slides) == 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
pytest.main(args=[ | ||
__file__, | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters