-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
2,702 additions
and
25 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 |
---|---|---|
@@ -0,0 +1,155 @@ | ||
""" | ||
Unit test for Boolean parameters. | ||
""" | ||
import datetime as dt | ||
|
||
import param | ||
|
||
from . import API1TestCase | ||
from .utils import check_defaults | ||
|
||
|
||
class TestBooleanParameters(API1TestCase): | ||
|
||
def setUp(self): | ||
super(TestBooleanParameters, self).setUp() | ||
class P(param.Parameterized): | ||
e = param.Boolean() | ||
f = param.Boolean(default=None) | ||
|
||
self.P = P | ||
|
||
def _check_defaults(self, p): | ||
assert p.default is False | ||
assert p.allow_None is False | ||
assert p.bounds == (0, 1) | ||
|
||
def test_defaults_class(self): | ||
class A(param.Parameterized): | ||
b = param.Boolean() | ||
|
||
check_defaults(A.param.b, label='B') | ||
self._check_defaults(A.param.b) | ||
|
||
def test_defaults_inst(self): | ||
class A(param.Parameterized): | ||
b = param.Boolean() | ||
|
||
a = A() | ||
|
||
check_defaults(a.param.b, label='B') | ||
self._check_defaults(a.param.b) | ||
|
||
def test_defaults_unbound(self): | ||
b = param.Boolean() | ||
|
||
check_defaults(b, label=None) | ||
self._check_defaults(b) | ||
|
||
def test_default_is_None(self): | ||
p = self.P() | ||
assert p.f is None | ||
assert p.param.f.allow_None is True | ||
|
||
p.f = True | ||
p.f = None | ||
assert p.f is None | ||
|
||
def test_raise_None_when_not_allowed(self): | ||
p = self.P() | ||
|
||
msg = r"Boolean parameter 'e' must be True or False, not None" | ||
with self.assertRaisesRegex(ValueError, msg): | ||
p.e = None | ||
|
||
with self.assertRaisesRegex(ValueError, msg): | ||
self.P.e = None | ||
|
||
def test_bad_type(self): | ||
msg = r"Boolean parameter 'e' must be True or False, not test" | ||
|
||
with self.assertRaisesRegex(ValueError, msg): | ||
self.P.e = 'test' | ||
|
||
with self.assertRaisesRegex(ValueError, msg): | ||
self.P(e='test') | ||
|
||
p = self.P() | ||
|
||
with self.assertRaisesRegex(ValueError, msg): | ||
p.e = 'test' | ||
|
||
|
||
class TestEventParameters(API1TestCase): | ||
|
||
def setUp(self): | ||
super(TestEventParameters, self).setUp() | ||
class P(param.Parameterized): | ||
e = param.Event() | ||
f = param.Event(default=None) | ||
|
||
self.P = P | ||
|
||
def _check_defaults(self, p): | ||
assert p.default is False | ||
assert p.allow_None is False | ||
assert p.bounds == (0, 1) | ||
|
||
def test_defaults_class(self): | ||
class A(param.Parameterized): | ||
b = param.Event() | ||
|
||
check_defaults(A.param.b, label='B') | ||
self._check_defaults(A.param.b) | ||
|
||
def test_defaults_inst(self): | ||
class A(param.Parameterized): | ||
b = param.Event() | ||
|
||
a = A() | ||
|
||
check_defaults(a.param.b, label='B') | ||
self._check_defaults(a.param.b) | ||
|
||
def test_defaults_unbound(self): | ||
b = param.Event() | ||
|
||
check_defaults(b, label=None) | ||
self._check_defaults(b) | ||
|
||
def test_resets_to_false(self): | ||
p = self.P() | ||
p.e = True | ||
assert p.e is False | ||
|
||
def test_default_is_None(self): | ||
p = self.P() | ||
assert p.f is None | ||
assert p.param.f.allow_None is True | ||
|
||
p.f = None | ||
assert p.f is False | ||
|
||
def test_raise_None_when_not_allowed(self): | ||
p = self.P() | ||
|
||
msg = r"Boolean parameter 'e' must be True or False, not None" | ||
with self.assertRaisesRegex(ValueError, msg): | ||
p.e = None | ||
|
||
with self.assertRaisesRegex(ValueError, msg): | ||
self.P.e = None | ||
|
||
def test_bad_type(self): | ||
msg = r"Boolean parameter 'e' must be True or False, not test" | ||
|
||
with self.assertRaisesRegex(ValueError, msg): | ||
self.P.e = 'test' | ||
|
||
with self.assertRaisesRegex(ValueError, msg): | ||
self.P(e='test') | ||
|
||
p = self.P() | ||
|
||
with self.assertRaisesRegex(ValueError, msg): | ||
p.e = 'test' |
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
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
Oops, something went wrong.