Debian Codegraph @

traitsui/examples/demo/Standard_Editors/tests/test_TableEditor_demo.py

raw
1 """
2 This example demonstrates how to test interacting with a TableEditor.
3
4 The GUI being tested is written in the demo under the same name (minus the
5 preceding 'test') in the outer directory.
6 """
7
8 import os
9 import runpy
10 import unittest
11
12
13 from traitsui.testing.api import (
14 Cell, KeyClick, KeySequence, MouseClick, UITester
15 )
16 from traitsui.tests._tools import requires_toolkit, ToolkitName
17
18 #: Filename of the demo script
19 FILENAME = "TableEditor_demo.py"
20
21 #: Path of the demo script
22 DEMO_PATH = os.path.join(os.path.dirname(__file__), "..", FILENAME)
23
24
25 class TestTableEditorDemo(unittest.TestCase):
26
27 @requires_toolkit([ToolkitName.qt])
28 def test_list_editor_demo(self):
29 demo = runpy.run_path(DEMO_PATH)["demo"]
30
31 tester = UITester()
32 with tester.create_ui(demo) as ui:
33 employees_table = tester.find_by_name(ui, "employees")
34
35 # clicking a cell enters edit mode and selects full text
36 cell_21 = employees_table.locate(Cell(2, 1))
37 cell_21.perform(MouseClick())
38 cell_21.perform(KeySequence("Jones"))
39 cell_21.perform(KeyClick("Enter"))
40
41 self.assertEqual(demo.employees[0].last_name, 'Jones')
42
43 # third column corresponds to Full Name property
44 cell_32 = employees_table.locate(Cell(3, 2))
45 cell_32.perform(MouseClick())
46
47
48 # Run the test(s)
49 unittest.TextTestRunner().run(
50 unittest.TestLoader().loadTestsFromTestCase(TestTableEditorDemo)
51 )