From 1fcc2d9ff87a4b411c871cb0b95bcd29397fd151 Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Mon, 26 Apr 2021 11:16:19 -0500 Subject: [PATCH 1/5] add some basic documentation for EnableTestAssistant --- docs/source/conf.py | 1 + docs/source/index.rst | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/source/conf.py b/docs/source/conf.py index bd5d0130b..496a97d84 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -219,4 +219,5 @@ intersphinx_mapping = { 'traits': ('http://docs.enthought.com/traits', None), 'pyface': ('http://docs.enthought.com/pyface', None), + "python": ("https://docs.python.org/3", None), } diff --git a/docs/source/index.rst b/docs/source/index.rst index a6895bce4..b9193619b 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -31,6 +31,7 @@ Enable enable/constraints_layout enable/traits enable/toolkit_selection + enable/testing credits From e39fc65634ee5bdd1d9ab2484d224c73149af84e Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Mon, 26 Apr 2021 12:26:01 -0500 Subject: [PATCH 2/5] add basic docs for EnableTestAssistant --- docs/source/enable/testing.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 docs/source/enable/testing.rst diff --git a/docs/source/enable/testing.rst b/docs/source/enable/testing.rst new file mode 100644 index 000000000..597ffe475 --- /dev/null +++ b/docs/source/enable/testing.rst @@ -0,0 +1,24 @@ +========================= +Testing Enable Components +========================= + +In order to assist in the testing of enable :class:`~.Component` and +:class:`~.Interactor` objects, Enable provides the +:class:`~.EnableTestAssistant` class. This is a mixin class intended to work +along side :class:`python:unittest.TestCase`. Often times in order to +effectively test an enable component and its supported interactivity, one needs +to simulate user interactions such as moving/clicking/dragging the mouse, using +keys, etc. This involves manually creating the corresponding events with +appropriate state and dispatching them appropriately. This can be rather +tedious and :class:`~.EnableTestAssistant` provides a number of helper methods +to greatly simplify the process, making tests both faster/cleaner to write and +easier to read. Furthermore, in test scenarios it is ofen unnecessary to launch +the full application window and as such :class:`~.EnableTestAssistant` provides +a :meth:`~.create_mock_window` method for simply +mocking out the window itself. This allows for specifically testing the +component of interest alone, as is the goal in a unit test. Please see the api +docs (by clicking :class:`~.EnableTestAssistant`) for the full list of methods +available. + +.. Todo: Add example test. I was going to refer to an existing test, but none + of the exissting tests seem very helpful for documentation purposes From 52e6f8f619d144b73b19e10f41ab1155489d665c Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Wed, 26 May 2021 11:46:53 -0500 Subject: [PATCH 3/5] add a very simple example pulled from test_test_assistant --- docs/source/enable/testing.rst | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/docs/source/enable/testing.rst b/docs/source/enable/testing.rst index 597ffe475..b8e9301f6 100644 --- a/docs/source/enable/testing.rst +++ b/docs/source/enable/testing.rst @@ -22,3 +22,40 @@ available. .. Todo: Add example test. I was going to refer to an existing test, but none of the exissting tests seem very helpful for documentation purposes + +The following is a Dummy TestCase to showcase some basics of the +:class:`~.EnableTestAssistant` functionality. It is not testing things +users would likely want to test, but it showcases the capabilities / usefulness +of the test assistant. + +:: + + import unittest + from unittest import mock + + from enable.component import Component + from enable.testing import EnableTestAssistant, _MockWindow + + class TestExample(unittest.TestCase): + def test_example(self): + test_assistant = EnableTestAssistant() + component = Component(bounds=[100, 200]) + + event = test_assistant.mouse_move(component, 10, 20) + self.assertEqual(event.x, 10) + self.assertEqual(event.y, 20) + self.assertIsInstance(event.window, _MockWindow) + self.assertFalse(event.alt_down) + self.assertFalse(event.control_down) + self.assertFalse(event.shift_down) + self.assertFalse(sevent.left_down) + self.assertEqual(event.window.get_pointer_position(), (10, 20)) + + component.normal_left_down = mock.Mock() + test_assistant.mouse_down(component, x=0, y=0) + component.normal_left_down.assert_called_once() + + event = test_assistant.mouse_move(component, 20, 30, left_down=True) + self.assertEqual(event.x, 20) + self.assertEqual(event.y, 30) + self.assertIs(event.left_down, True) From 58db89e46b952e48b81ef008016cdaaa5baac43a Mon Sep 17 00:00:00 2001 From: aaronayres35 <36972686+aaronayres35@users.noreply.github.com> Date: Tue, 1 Jun 2021 06:53:43 -0500 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: Poruri Sai Rahul --- docs/source/enable/testing.rst | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/source/enable/testing.rst b/docs/source/enable/testing.rst index b8e9301f6..b834dbcad 100644 --- a/docs/source/enable/testing.rst +++ b/docs/source/enable/testing.rst @@ -17,12 +17,9 @@ the full application window and as such :class:`~.EnableTestAssistant` provides a :meth:`~.create_mock_window` method for simply mocking out the window itself. This allows for specifically testing the component of interest alone, as is the goal in a unit test. Please see the api -docs (by clicking :class:`~.EnableTestAssistant`) for the full list of methods +docs (:class:`~.EnableTestAssistant`) for the full list of methods available. -.. Todo: Add example test. I was going to refer to an existing test, but none - of the exissting tests seem very helpful for documentation purposes - The following is a Dummy TestCase to showcase some basics of the :class:`~.EnableTestAssistant` functionality. It is not testing things users would likely want to test, but it showcases the capabilities / usefulness From 1f4f049b10a2685ae2097feaa39d2c4171a3d191 Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Tue, 1 Jun 2021 06:56:24 -0500 Subject: [PATCH 5/5] more review suggestions - use api, remove _MockWindow and be more concise --- docs/source/enable/testing.rst | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/docs/source/enable/testing.rst b/docs/source/enable/testing.rst index b834dbcad..7b7406f72 100644 --- a/docs/source/enable/testing.rst +++ b/docs/source/enable/testing.rst @@ -20,18 +20,15 @@ component of interest alone, as is the goal in a unit test. Please see the api docs (:class:`~.EnableTestAssistant`) for the full list of methods available. -The following is a Dummy TestCase to showcase some basics of the -:class:`~.EnableTestAssistant` functionality. It is not testing things -users would likely want to test, but it showcases the capabilities / usefulness -of the test assistant. +Here is an example :: import unittest from unittest import mock - from enable.component import Component - from enable.testing import EnableTestAssistant, _MockWindow + from enable.api import Component + from enable.testing import EnableTestAssistant class TestExample(unittest.TestCase): def test_example(self): @@ -41,7 +38,6 @@ of the test assistant. event = test_assistant.mouse_move(component, 10, 20) self.assertEqual(event.x, 10) self.assertEqual(event.y, 20) - self.assertIsInstance(event.window, _MockWindow) self.assertFalse(event.alt_down) self.assertFalse(event.control_down) self.assertFalse(event.shift_down)