/usr/lib/python2.7/dist-packages/traits/tests/test_bool.py is in python-traits 4.6.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | # -----------------------------------------------------------------------------
#
# Copyright (c) 2016, Enthought, Inc.
# 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!
#
# -----------------------------------------------------------------------------
"""
Tests for the Bool trait type.
"""
try:
import numpy
except ImportError:
numpy_available = False
else:
numpy_available = True
from traits.testing.unittest_tools import unittest
from ..api import Bool, Dict, HasTraits, Int, TraitError
class A(HasTraits):
foo = Bool
class TestBool(unittest.TestCase):
def test_default_value(self):
a = A()
# We should get something of exact type bool.
self.assertEqual(type(a.foo), bool)
self.assertFalse(a.foo)
def test_accepts_bool(self):
a = A()
a.foo = True
self.assertTrue(a.foo)
a.foo = False
self.assertFalse(a.foo)
def test_does_not_accept_int_or_float(self):
a = A()
bad_values = [-1, 1L, "a string", 1.0]
for bad_value in bad_values:
with self.assertRaises(TraitError):
a.foo = bad_value
# Double check that foo didn't actually change
self.assertEqual(type(a.foo), bool)
self.assertFalse(a.foo)
@unittest.skipUnless(numpy_available, "numpy not available")
def test_accepts_numpy_bool(self):
# A bool trait should accept a NumPy bool_.
a = A()
a.foo = numpy.bool_(True)
self.assertTrue(a.foo)
@unittest.skipUnless(numpy_available, "numpy not available")
def test_numpy_bool_retrieved_as_bool(self):
a = A()
a.foo = numpy.bool_(True)
self.assertIsInstance(a.foo, bool)
a.foo = numpy.bool_(False)
self.assertIsInstance(a.foo, bool)
@unittest.skipUnless(numpy_available, "numpy not available")
def test_numpy_bool_accepted_as_dict_value(self):
# Regression test for enthought/traits#299.
class HasBoolDict(HasTraits):
foo = Dict(Int, Bool)
has_bool_dict = HasBoolDict()
has_bool_dict.foo[1] = numpy.bool_(True)
self.assertTrue(has_bool_dict.foo[1])
@unittest.skipUnless(numpy_available, "numpy not available")
def test_numpy_bool_accepted_as_dict_key(self):
# Regression test for enthought/traits#299.
class HasBoolDict(HasTraits):
foo = Dict(Bool, Int)
has_bool_dict = HasBoolDict()
key = numpy.bool_(True)
has_bool_dict.foo[key] = 1
self.assertEqual(has_bool_dict.foo[key], 1)
|