/usr/lib/python2.7/dist-packages/traits/tests/test_validated_tuple.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 | # -----------------------------------------------------------------------------
#
# Copyright (c) 2014, Enthought, Inc.
# All rights reserved.
#
# This software is provided without warranty under the terms of the BSD
# license included in enthought/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!
#
# -----------------------------------------------------------------------------
from traits.api import HasStrictTraits, Int, TraitError
from traits.testing.unittest_tools import unittest
from traits.tests.tuple_test_mixin import TupleTestMixin
from traits.trait_types import ValidatedTuple
class Simple(HasStrictTraits):
scalar_range = ValidatedTuple(
Int(0), Int(1), fvalidate=lambda x: x[0] < x[1])
class ValidatedTupleTestCase(TupleTestMixin, unittest.TestCase):
def setUp(self):
self.trait = ValidatedTuple
def test_initialization(self):
simple = Simple()
self.assertEqual(simple.scalar_range, (0, 1))
def test_custom_validation(self):
simple = Simple()
simple.scalar_range = (2, 5)
self.assertEqual(simple.scalar_range, (2, 5))
with self.assertRaises(TraitError):
simple.scalar_range = (5, 2)
def test_error_during_custom_validation(self):
def fvalidate(x):
if x == (5, 2):
raise RuntimeError()
return True
class Simple(HasStrictTraits):
scalar_range = ValidatedTuple(Int(0), Int(1), fvalidate=fvalidate)
simple = Simple()
with self.assertRaises(RuntimeError):
simple.scalar_range = (5, 2)
|