-
Notifications
You must be signed in to change notification settings - Fork 45
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
Add assert methods for drawing and compiled paths #123
Changes from 1 commit
dc34da1
d73de13
de70b7d
3525787
c0b8e2e
34b0e34
77ffa14
f3c6af1
272c4b9
acc2c3f
7b12d9a
4761ec7
ced7aee
6252681
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,13 @@ def create_mock_window(self): | |
window.control.set_pointer = Mock() | ||
return window | ||
|
||
def create_a_mock_gc(self, width, height): | ||
gc = PlotGraphicsContext((width, height)) | ||
gc.clear((0.0, 0.0, 0.0, 0.0)) | ||
gc.stroke_path = Mock() | ||
gc.draw_path = Mock() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps the methods which will be mocked could be a list passed in by the caller? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I meant was you might want to mock any number of
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have not found yet a need for such behaviour, but if you think that it would be useful, I will add it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
return gc | ||
|
||
def create_key_press(self, key, window=None, alt_down=False, | ||
control_down=False, shift_down=False): | ||
""" Creates a KeyEvent for the given Key. | ||
|
@@ -379,3 +386,63 @@ def _key_event_dispatch(self, interactor, event): | |
interactor.dispatch(event, 'key_pressed') | ||
else: | ||
focus_owner.dispatch(event, 'key_pressed') | ||
|
||
def assertPathsAreProcessed(self, drawable, width=200, height=200): | ||
""" Check that drawing does not leave paths unused in the GC cache. | ||
|
||
Parameters | ||
---------- | ||
drawable : | ||
A drawable object that has a draw method. | ||
|
||
width : int, optional | ||
The width of the array buffer | ||
|
||
height : int, optional | ||
The height of the array buffer | ||
|
||
""" | ||
gc = PlotGraphicsContext((width, height)) | ||
drawable.draw(gc) | ||
compiled_path = gc._get_path() | ||
self.assertEqual( | ||
compiled_path.total_vertices(), 0, | ||
msg='There are compiled paths that ' | ||
'have not been processed: {0}'.format(compiled_path)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have augmented the error message |
||
|
||
def assertPathsAreCreated(self, drawable, width=200, height=200): | ||
""" Check that drawing creates paths. | ||
|
||
Parameters | ||
---------- | ||
drawable : | ||
A drawable object that has a draw method. | ||
|
||
width : int, optional | ||
The width of the array buffer | ||
|
||
height : int, optional | ||
The height of the array buffer | ||
|
||
""" | ||
gc = self.create_a_mock_gc(width, height) | ||
drawable.draw(gc) | ||
compiled_path = gc._get_path() | ||
self.assertGreater( | ||
compiled_path.total_vertices(), 0, | ||
msg='There are no compiled paths ' | ||
'created: {0}'.format(compiled_path)) | ||
|
||
def _mouse_event_dispatch(self, interactor, event, suffix): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you intend to add these two methods? As far as I can see, they're private methods that aren't used anywhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. No they're not; they're duplicates of existing methods. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
mouse_owner = event.window.mouse_owner | ||
if mouse_owner is None: | ||
interactor.dispatch(event, suffix) | ||
else: | ||
mouse_owner.dispatch(event, suffix) | ||
|
||
def _key_event_dispatch(self, interactor, event): | ||
focus_owner = event.window.focus_owner | ||
if focus_owner is None: | ||
interactor.dispatch(event, 'key_pressed') | ||
else: | ||
focus_owner.dispatch(event, 'key_pressed') |
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.
I suggest naming this
create_mock_gc
, for consistency withcreate_mock_window
.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.
(Or perhaps even
create_mock_graphics_context
, thoughgc
seems sufficiently clear in this context.)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.
I will go with
create_mock_gc
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.
Done