From 6628bb711619ece19482e8a581fc7dcc15528f03 Mon Sep 17 00:00:00 2001 From: Mark Dickinson Date: Fri, 3 May 2024 14:30:57 +0100 Subject: [PATCH] Remove Cython-based tests --- .github/workflows/test-from-pypi.yml | 8 +- etstool.py | 1 - setup.py | 1 - traits/has_traits.py | 2 +- traits/testing/optional_dependencies.py | 3 - traits/tests/test_cythonized_traits.py | 215 ------------------------ 6 files changed, 5 insertions(+), 225 deletions(-) delete mode 100644 traits/tests/test_cythonized_traits.py diff --git a/.github/workflows/test-from-pypi.yml b/.github/workflows/test-from-pypi.yml index e5f465ced..0a1e6a4cf 100644 --- a/.github/workflows/test-from-pypi.yml +++ b/.github/workflows/test-from-pypi.yml @@ -48,11 +48,11 @@ jobs: allow-prereleases: true - name: Install test dependencies and Traits from PyPI sdist (no PySide6) run: | - python -m pip install --no-binary traits Cython numpy setuptools Sphinx traits traitsui + python -m pip install --no-binary traits numpy setuptools Sphinx traits traitsui if: matrix.python-version == '3.12' || matrix.python-architecture == 'x86' - name: Install test dependencies and Traits from PyPI sdist (PySide6) run: | - python -m pip install --no-binary traits Cython numpy PySide6 setuptools Sphinx traits traitsui + python -m pip install --no-binary traits numpy PySide6 setuptools Sphinx traits traitsui if: matrix.python-version != '3.12' && matrix.python-architecture != 'x86' - name: Create clean test directory run: | @@ -100,11 +100,11 @@ jobs: allow-prereleases: true - name: Install test dependencies and Traits from PyPI wheel (no PySide6) run: | - python -m pip install --only-binary traits Cython numpy setuptools Sphinx traits traitsui + python -m pip install --only-binary traits numpy setuptools Sphinx traits traitsui if: matrix.python-version == '3.12' || matrix.python-architecture == 'x86' - name: Install test dependencies and Traits from PyPI wheel (PySide6) run: | - python -m pip install --only-binary traits Cython numpy PySide6 setuptools Sphinx traits traitsui + python -m pip install --only-binary traits numpy PySide6 setuptools Sphinx traits traitsui if: matrix.python-version != '3.12' && matrix.python-architecture != 'x86' - name: Create clean test directory run: | diff --git a/etstool.py b/etstool.py index 76b7917ff..3076456ef 100644 --- a/etstool.py +++ b/etstool.py @@ -89,7 +89,6 @@ common_dependencies = { "configobj", "coverage", - "cython", "enthought_sphinx_theme", "flake8", "flake8_ets", diff --git a/setup.py b/setup.py index 52172096c..5e1f2a111 100644 --- a/setup.py +++ b/setup.py @@ -301,7 +301,6 @@ def get_long_description(): "sphinx-copybutton", ], "test": [ - "Cython", # defusedxml is required by the Sphinx test machinery # for recent versions of Sphinx (including 7.3.7) "defusedxml", diff --git a/traits/has_traits.py b/traits/has_traits.py index 58d056a84..987b928da 100644 --- a/traits/has_traits.py +++ b/traits/has_traits.py @@ -184,7 +184,7 @@ def is_unbound_method_type(method): and _name_fired methods. """ - # The ismethoddescriptor check catches methods written in C or Cython + # The ismethoddescriptor check catches methods written in C # extensions. It excludes things that pass an isfunction check, so we have # to explicitly re-include that check. return inspect.isfunction(method) or inspect.ismethoddescriptor(method) diff --git a/traits/testing/optional_dependencies.py b/traits/testing/optional_dependencies.py index 87c565c18..00c649f7b 100644 --- a/traits/testing/optional_dependencies.py +++ b/traits/testing/optional_dependencies.py @@ -36,9 +36,6 @@ def optional_import(name): # Commonly-used unittest skip decorators. -cython = optional_import("cython") -requires_cython = unittest.skipIf(cython is None, "Cython not available") - mypy = optional_import("mypy") requires_mypy = unittest.skipIf(mypy is None, "Mypy not available") diff --git a/traits/tests/test_cythonized_traits.py b/traits/tests/test_cythonized_traits.py deleted file mode 100644 index a9b462a60..000000000 --- a/traits/tests/test_cythonized_traits.py +++ /dev/null @@ -1,215 +0,0 @@ -# (C) Copyright 2005-2024 Enthought, Inc., Austin, TX -# All rights reserved. -# -# This software is provided without warranty under the terms of the BSD -# license included in LICENSE.txt and may be redistributed only under -# the conditions described in the aforementioned license. The license -# is also available online at http://www.enthought.com/licenses/BSD.txt -# -# Thanks for using Enthought open source! - -""" Test some usage of Trait classes when the code is cythonized. - -The tests reflects some of the patterns needed in different applications. They -probably don't cover all of the user case. - -Each test case is written as if the test code was in a separate module then -compiled with Cython Inline before evaluation the produced object behaves -properly. - -The tests need a Cython version > 0.19 and a compiler. - -""" -import unittest - -from traits.testing.unittest_tools import UnittestTools -from traits.testing.optional_dependencies import cython, requires_cython - - -@requires_cython -class CythonizedTraitsTestCase(unittest.TestCase, UnittestTools): - def test_simple_default_methods(self): - - code = """ -from traits.api import HasTraits, Str - -class Test(HasTraits): - name = Str - - def _name_default(self): - return 'Joe' - -return Test() -""" - - obj = self.execute(code) - self.assertEqual(obj.name, "Joe") - - def test_basic_events(self): - - code = """ -from traits.api import HasTraits, Str - -class Test(HasTraits): - name = Str - -return Test() -""" - - obj = self.execute(code) - with self.assertTraitChanges(obj, "name", count=1): - obj.name = "changing_name" - - def test_on_trait_static_handlers(self): - - code = """ -from traits.api import HasTraits, Str, Int - -class Test(HasTraits): - name = Str - value = Int - - def _name_changed(self): - self.value += 1 - -return Test() -""" - - obj = self.execute(code) - with self.assertTraitChanges(obj, "value", count=1): - obj.name = "changing_name" - - self.assertEqual(obj.value, 1) - - def test_on_trait_on_trait_change_decorator(self): - - code = """ -from traits.api import HasTraits, Str, Int, on_trait_change - -class Test(HasTraits): - name = Str - value = Int - - @on_trait_change('name') - def _update_value(self): - self.value += 1 - -return Test() -""" - - obj = self.execute(code) - with self.assertTraitChanges(obj, "value", count=1): - obj.name = "changing_name" - - self.assertEqual(obj.value, 1) - - def test_on_trait_properties(self): - - code = """ -from traits.api import HasTraits, Str, Int, Property, cached_property - -class Test(HasTraits): - name = Str - name_len = Property(depends_on='name') - - @cached_property - def _get_name_len(self): - return len(self.name) - -return Test() -""" - - obj = self.execute(code) - self.assertEqual(obj.name_len, len(obj.name)) - - # Assert dependency works - obj.name = "Bob" - self.assertEqual(obj.name_len, len(obj.name)) - - def test_on_trait_properties_with_standard_getter(self): - - code = """ -from traits.api import HasTraits, Str, Int, Property - -class Test(HasTraits): - name = Str - - def _get_name_length(self): - return len(self.name) - - name_len = Property(_get_name_length) - -return Test() -""" - - obj = self.execute(code) - self.assertEqual(obj.name_len, len(obj.name)) - - # Assert dependency works - obj.name = "Bob" - self.assertEqual(obj.name_len, len(obj.name)) - - def test_on_trait_aliasing(self): - - code = """ -from traits.api import HasTraits, Str, Int, Property - -def Alias(name): - def _get_value(self): - return getattr(self, name) - def _set_value(self, value): - return setattr(self, name, value) - - return Property(_get_value, _set_value) - -class Test(HasTraits): - name = Str - - funky_name = Alias('name') - -return Test() -""" - - obj = self.execute(code) - self.assertEqual(obj.funky_name, obj.name) - - # Assert dependency works - obj.name = "Bob" - self.assertEqual(obj.funky_name, obj.name) - - def test_on_trait_aliasing_different_scope(self): - - code = """ -from traits.api import HasTraits, Str, Int, Property - -def _get_value(self, name): - return getattr(self, 'name') -def _set_value(self, name, value): - return setattr(self, 'name', value) - - -class Test(HasTraits): - name = Str - - funky_name = Property(_get_value, _set_value) - -return Test() -""" - - obj = self.execute(code) - self.assertEqual(obj.funky_name, obj.name) - - # Assert dependency works - obj.name = "Bob" - self.assertEqual(obj.funky_name, obj.name) - - def execute(self, code): - """ - Helper function to execute the given code under cython.inline and - return the result. - """ - return cython.inline( - code, - force=True, - language_level="3", - )