def test_basic_collectable(): c = Collectable() # empty by default assert_equal(c.name, None) assert_equal(c.value, None) assert_equal(c.__doc__, None) # late assignment c.name = 'somename' c.value = 12345 assert_equal(c.name, 'somename') assert_equal(c.value, 12345) # immediate content c = Collectable('value', 'myname', "This is a test") assert_equal(c.name, 'myname') assert_equal(c.value, 'value') assert_equal(c.__doc__, "This is a test") assert_equal(str(c), 'myname') # repr e = eval(repr(c)) assert_equal(e.name, 'myname') assert_equal(e.value, 'value') assert_equal(e.__doc__, "This is a test") # shallow copy does not create a view of value array c.value = np.arange(5) d = copy.copy(c) assert_false(d.value.base is c.value) # names starting with _ are not allowed assert_raises(ValueError, c._set_name, "_underscore")
def __init__(self, index=None, *args, **kwargs): """ Parameters ---------- value : arbitrary (see derived implementations) The actual value of this attribute. **kwargs Passed to `Collectable` """ if index is None: IndexedCollectable._instance_index += 1 index = IndexedCollectable._instance_index else: # TODO: there can be collision between custom provided indexes # and the ones automagically assigned. # Check might be due pass self._instance_index = index self._isset = False self.reset() Collectable.__init__(self, *args, **kwargs) if __debug__ and 'COL' in debug.active: debug("COL", "Initialized new IndexedCollectable #%d:%s %r", (index, self.name, self))
def __init__(self, index=None, *args, **kwargs): """ Parameters ---------- value : arbitrary (see derived implementations) The actual value of this attribute. **kwargs Passed to `Collectable` """ if index is None: IndexedCollectable._instance_index += 1 index = IndexedCollectable._instance_index else: # TODO: there can be collision between custom provided indexes # and the ones automagically assigned. # Check might be due pass self._instance_index = index self._isset = False self.reset() Collectable.__init__(self, *args, **kwargs) if __debug__ and 'COL' in debug.active: debug("COL", "Initialized new IndexedCollectable #%d:%s %r" % (index, self.name, self))
def __reduce__(self): cr = Collectable.__reduce__(self) assert(len(cr) == 2) # otherwise we need to change logic below res = (cr[0], (self._instance_index,) + cr[1], {'_isset' : self._isset}) #if __debug__ and 'COL_RED' in debug.active: # debug('COL_RED', 'Returning %s for %s' % (res, self)) return res