Skip to content

Commit

Permalink
Remove a test that uses UITester (#1788)
Browse files Browse the repository at this point in the history
This PR removes a test that's using `UITester` from TraitsUI. This test
exposed the Traits test suite to a class of possible issues with 3rd
party GUI frameworks (in this case PySide6); historically, `UITester`
has also been a particularly fragile part of TraitsUI.

In its place is a test that at least executes the `Enum.create_editor`
method, but doesn't attempt to create an instance of the editor.

We also fix an issue with test dependencies and the latest release of
Sphinx: `defusedxml` is now required to run the tests for the Traits
documenter.

Closes #1787
  • Loading branch information
mdickinson committed Apr 29, 2024
1 parent ba745ce commit 8a36a21
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ def get_long_description():
],
"test": [
"Cython",
# defusedxml is required by the Sphinx test machinery
# for recent versions of Sphinx (including 7.3.7)
"defusedxml",
"flake8",
"flake8-ets",
"mypy",
Expand Down
28 changes: 10 additions & 18 deletions traits/tests/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
from traits.api import (
Any, BaseEnum, Enum, HasTraits, Int, List, Property, Set, TraitError,
Tuple)
from traits.etsconfig.api import ETSConfig
from traits.testing.optional_dependencies import requires_traitsui

is_null = ETSConfig.toolkit == 'null'


class FooEnum(enum.Enum):
foo = 0
Expand Down Expand Up @@ -115,13 +112,6 @@ class EnumCollectionExample(HasTraits):
slow_enum = BaseEnum("yes", "no", "maybe")


class EnumCollectionGUIExample(EnumCollectionExample):
# Override attributes that may fail GUI test
# until traitsui #781 is fixed.
int_set_enum = Enum("int", "set")
correct_int_set_enum = Enum("int", "set")


class EnumTestCase(unittest.TestCase):
def test_valid_enum(self):
example_model = ExampleModel(root="model1")
Expand Down Expand Up @@ -343,12 +333,14 @@ class HasEnumInList(HasTraits):


@requires_traitsui
@unittest.skipIf(is_null, "GUI toolkit not available")
class TestGui(unittest.TestCase):

class TestEnumCreateEditor(unittest.TestCase):
def test_create_editor(self):
from traitsui.testing.api import UITester

obj = EnumCollectionGUIExample()
with UITester().create_ui(obj):
pass
import traitsui.editor_factory

obj = EnumListExample()
trait = obj.trait("value")
editor_factory = trait.trait_type.create_editor()
self.assertIsInstance(
editor_factory,
traitsui.editor_factory.EditorFactory
)

0 comments on commit 8a36a21

Please sign in to comment.