Exemple #1
0
    def __setitem__(self, key, obj):
        if obj is ABSENT:
            self.pop(key, None)
        else:
            super(AbsentDict, self).__setitem__(key, obj)


#: Value which indicates that its key is absent from :class:`AbsentDict`.
#: This is the same object as ``taipan.lang.ABSENT``.
ABSENT = taipan.lang.ABSENT

# Compatibility shims

# Helper function to call a method of a dictionary
_m = lambda method: compose(dotcall(method), ensure_mapping)

#: Return an iterator over key-value pairs stored within the dictionary.
iteritems = compose(iter, _m('items')) if IS_PY3 else _m('iteritems')

#: Return an iterator over keys stored within the dictionary.
iterkeys = compose(iter, _m('keys')) if IS_PY3 else _m('iterkeys')

#: Return an iterator over values stored within the dictionary
itervalues = compose(iter, _m('values')) if IS_PY3 else _m('itervalues')

#: Return a list of key-value pairs stored within the dictionary.
items = compose(list, _m('items')) if IS_PY3 else _m('items')

#: Return a list of keys stored within the dictionary.
keys = compose(list, _m('keys')) if IS_PY3 else _m('keys')
Exemple #2
0
 def test_string__with_args__class(self):
     call = __unit__.dotcall('qux', self.ARGUMENT)
     class_ = self._create_class()
     self.assertEquals(self.ARGUMENT, call(class_))
Exemple #3
0
 def test_string__with_args__module(self):
     call = __unit__.dotcall(__unit__.const.__name__, self.ARGUMENT)
     self.assertResultsEqual(__unit__.const(self.ARGUMENT), call(__unit__))
Exemple #4
0
 def test_string__no_args__module(self):
     call = __unit__.dotcall(__unit__.true.__name__)
     self.assertResultsEqual(__unit__.true(), call(__unit__))
Exemple #5
0
 def test_string__with_args__class_instance(self):
     call = __unit__.dotcall('baz', self.ARGUMENT)
     instance = self._create_class_instance()
     self.assertEquals(self.ARGUMENT, call(instance))
Exemple #6
0
 def test_string__no_args__class(self):
     call = __unit__.dotcall('bar')
     class_ = self._create_class()
     self.assertEquals(Dotcall.CLASS_RETURN_VALUE, call(class_))
Exemple #7
0
 def test_string__no_args__class_instance(self):
     call = __unit__.dotcall('foo')
     instance = self._create_class_instance()
     self.assertEquals(Dotcall.INSTANCE_RETURN_VALUE, call(instance))
Exemple #8
0
 def test_some_object(self):
     with self.assertRaises(TypeError):
         __unit__.dotcall(object())
Exemple #9
0
 def test_none(self):
     with self.assertRaises(TypeError):
         __unit__.dotcall(None)
Exemple #10
0
 def test_no_args(self):
     with self.assertRaises(TypeError):
         __unit__.dotcall()