Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #313 from enthought/enh/cython-disallow-getattr
Cython port: handle Disallow
- Loading branch information
Showing
3 changed files
with
69 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,3 +14,6 @@ docs/build/ | |
|
||
# Auto-generated by setup.py | ||
traits/_version.py | ||
|
||
# Cython C files | ||
traits/ctraits.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
""" Unit tests for the Disallow singleton. | ||
""" | ||
from traits.testing.unittest_tools import unittest | ||
from ..api import Disallow, HasTraits, TraitError | ||
|
||
|
||
class A(HasTraits): | ||
|
||
x = Disallow | ||
|
||
|
||
class B(HasTraits): | ||
|
||
_ = Disallow | ||
|
||
|
||
class TestDisallow(unittest.TestCase): | ||
|
||
def test_trait_get_set(self): | ||
a = A() | ||
|
||
with self.assertRaises(AttributeError): | ||
a.x | ||
|
||
with self.assertRaises(TraitError): | ||
a.x = 123 | ||
|
||
def test_wildcard_get_set(self): | ||
b = B() | ||
|
||
with self.assertRaises(AttributeError): | ||
b.some_attribute | ||
|
||
with self.assertRaises(TraitError): | ||
b.some_attribute = 'foo' |