Skip to content

Commit

Permalink
Add test that covers the CALLABLE_AND_ARGS case
Browse files Browse the repository at this point in the history
  • Loading branch information
mdickinson committed Dec 14, 2023
1 parent 45a2e1d commit 4819297
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions traits/tests/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,26 @@ def _mass_default(self):
# ... and the returned dictionary does not include the mass.
self.assertEqual(traits, {"weight": 12.3})

def test_warn_on_attribute_error_in_factory(self):

def bad_range(start, stop):
self.this_attribute_doesnt_exist
return range(start, stop)

class HasBrokenFactory(HasStrictTraits):
ticks = Instance(range, factory=bad_range, args=(0, 10))

# When we try to get all trait values on an instance,
# Then a warning is issued ...
obj = HasBrokenFactory()
with self.assertWarnsRegex(
UserWarning, "default value resolution raised an AttributeError"
):
traits = obj.trait_get()

# ... and the returned dictionary does not include the bad trait
self.assertEqual(traits, {})


class NestedContainerClass(HasTraits):
# Used in regression test for changes to nested containers
Expand Down

0 comments on commit 4819297

Please sign in to comment.