Did I find the right examples for you? yes no

All Samples(24)  |  Call(18)  |  Derive(2)  |  Import(4)

src/c/o/cogent-1.5.3/cogent/core/info.py   cogent(Download)
"""
from cogent.parse.record import MappedRecord
from cogent.util.misc import Delegator, FunctionWrapper, ConstrainedDict
 
__author__ = "Rob Knight"
class DbRefs(MappedRecord, ConstrainedDict):
    """Holds Database -> [Accessions] mapping.
 
    The accessions for a particular database are always stored as a list.
 

src/p/y/pycogent-HEAD/cogent/core/info.py   pycogent(Download)
"""
from cogent.parse.record import MappedRecord
from cogent.util.misc import Delegator, FunctionWrapper, ConstrainedDict
 
__author__ = "Rob Knight"
class DbRefs(MappedRecord, ConstrainedDict):
    """Holds Database -> [Accessions] mapping.
 
    The accessions for a particular database are always stored as a list.
 

src/c/o/cogent-1.5.3/tests/test_util/test_misc.py   cogent(Download)
from cogent.app.util import get_tmp_filename
from cogent.util.unit_test import TestCase, main
from cogent.util.misc import (iterable, max_index, min_index,
    flatten, is_iterable, is_char, is_char_or_noniterable,
    is_str_or_noniterable, not_list_tuple, list_flatten,
    def test_setitem(self):
        """ConstrainedDict setitem should work only if key in constraint"""
        a = ConstrainedDict(dict.fromkeys('12'), '123')
        a['1'] = '3'
        self.assertEqual(a, {'1':'3','2':None})
        self.assertRaises(ConstraintError, a.__setitem__, 1, '3')
 
    def test_copy(self):
        """ConstrainedDict copy should retain constraint"""
        a = ConstrainedDict(dict.fromkeys('12'), '123')
    def test_fromkeys(self):
        """ConstrainedDict instance fromkeys should retain constraint"""
        a = ConstrainedDict(dict.fromkeys('12'), '123')
        b = a.fromkeys('23')
        self.assertEqual(a.Constraint, b.Constraint)
    def test_setdefault(self):
        """ConstrainedDict setdefault shouldn't allow bad keys"""
        a = ConstrainedDict({'1':None, '2': 'xyz'}, '123')
        self.assertEqual(a.setdefault('2', None), 'xyz')
        self.assertEqual(a.setdefault('1', None), None)

src/p/y/pycogent-HEAD/tests/test_util/test_misc.py   pycogent(Download)
from cogent.app.util import get_tmp_filename
from cogent.util.unit_test import TestCase, main
from cogent.util.misc import (iterable, max_index, min_index,
    flatten, is_iterable, is_char, is_char_or_noniterable,
    is_str_or_noniterable, not_list_tuple, list_flatten,
    def test_setitem(self):
        """ConstrainedDict setitem should work only if key in constraint"""
        a = ConstrainedDict(dict.fromkeys('12'), '123')
        a['1'] = '3'
        self.assertEqual(a, {'1':'3','2':None})
        self.assertRaises(ConstraintError, a.__setitem__, 1, '3')
 
    def test_copy(self):
        """ConstrainedDict copy should retain constraint"""
        a = ConstrainedDict(dict.fromkeys('12'), '123')
    def test_fromkeys(self):
        """ConstrainedDict instance fromkeys should retain constraint"""
        a = ConstrainedDict(dict.fromkeys('12'), '123')
        b = a.fromkeys('23')
        self.assertEqual(a.Constraint, b.Constraint)
    def test_setdefault(self):
        """ConstrainedDict setdefault shouldn't allow bad keys"""
        a = ConstrainedDict({'1':None, '2': 'xyz'}, '123')
        self.assertEqual(a.setdefault('2', None), 'xyz')
        self.assertEqual(a.setdefault('1', None), None)