def __set__(self, obj, _val): # self is the attribute we're about to change # obj is the object we're about to make the change in # val is the value we're setting the attribute to. # item is the schema entry of the attribute we're about to change ## Try to remove all proxies val = ProxyDataDescriptor.__recursive_strip(_val) #logger.debug("__set__") item = stripProxy(obj)._schema[getName(self)] if item['protected']: raise ProtectedAttributeError( '"%s" attribute is protected and cannot be modified' % (getName(self), )) if stripProxy(obj)._readonly(): if not item.getProperties()['changable_at_resubmit']: raise ReadOnlyObjectError( 'object %s is read-only and attribute "%s" cannot be modified now' % (repr(obj), getName(self))) # mechanism for locking of preparable attributes if item['preparable']: self.__preparable_set__(obj, val, getName(self)) # if we set is_prepared to None in the GPI, that should effectively # unprepare the application if getName(self) == 'is_prepared': # Replace is_prepared on an application for another ShareDir object self.__prep_set__(obj, val) # catch assignment of 'something' to a preparable application if getName(self) == 'application': self.__app_set__(obj, val) # unwrap proxy if item.isA(ComponentItem): from .Filters import allComponentFilters cfilter = allComponentFilters[item['category']] stripper = lambda v: stripComponentObject(v, cfilter, item) else: stripper = None if item['sequence']: val = self.__sequence_set__(stripper, obj, val, getName(self)) else: if stripper is not None: val = stripper(val) else: val = self._stripAttribute(obj, val, getName(self)) # apply attribute filter to component items if item.isA(ComponentItem): val = self._stripAttribute(obj, val, getName(self)) self._check_type(obj, val) GangaObject = _getGangaObject() GangaObject.__setattr__(stripProxy(obj), getName(self), val)
def __set__(self, obj, _val): # self is the attribute we're about to change # obj is the object we're about to make the change in # val is the value we're setting the attribute to. # item is the schema entry of the attribute we're about to change ## Try to remove all proxies val = ProxyDataDescriptor.__recursive_strip(_val) #logger.debug("__set__") item = stripProxy(obj)._schema[getName(self)] if item['protected']: raise ProtectedAttributeError('"%s" attribute is protected and cannot be modified' % (getName(self),)) if stripProxy(obj)._readonly(): if not item.getProperties()['changable_at_resubmit']: raise ReadOnlyObjectError('object %s is read-only and attribute "%s" cannot be modified now' % (repr(obj), getName(self))) # mechanism for locking of preparable attributes if item['preparable']: self.__preparable_set__(obj, val, getName(self)) # if we set is_prepared to None in the GPI, that should effectively # unprepare the application if getName(self) == 'is_prepared': # Replace is_prepared on an application for another ShareDir object self.__prep_set__(obj, val) # catch assignment of 'something' to a preparable application if getName(self) == 'application': self.__app_set__(obj, val) # unwrap proxy if item.isA(ComponentItem): from .Filters import allComponentFilters cfilter = allComponentFilters[item['category']] stripper = lambda v: stripComponentObject(v, cfilter, item) else: stripper = None if item['sequence']: val = self.__sequence_set__(stripper, obj, val, getName(self)) else: if stripper is not None: val = stripper(val) else: val = self._stripAttribute(obj, val, getName(self)) # apply attribute filter to component items if item.isA(ComponentItem): val = self._stripAttribute(obj, val, getName(self)) self._check_type(obj, val) GangaObject = _getGangaObject() GangaObject.__setattr__(stripProxy(obj), getName(self), val)
def test__ne__(self): self.obj != GangaObject()
def test__eq__(self): self.obj == GangaObject()
def setUp(self): self.obj = GangaObject()
def testCopyFrom(self): temp = GangaObject() temp.copyFrom(self.obj)
class TestGangaObject(TestCase): def setUp(self): self.obj = GangaObject() def test_getReadAccess(self): self.obj._getReadAccess() def test_getWriteAccess(self): self.obj._getWriteAccess() def test_releaseWriteAccess(self): self.obj._releaseWriteAccess() def test_setRegistry(self): self.obj._setRegistry(None) def test_getRegistryID(self): print self.obj._getRegistryID() def test_setDirty(self): self.obj._setDirty() def test_setFlushed(self): self.obj._setFlushed() def test_declared_property(self): self.obj._declared_property('NotAProperty') def testGetJobObject(self): try: self.obj.getJobObject() raise Exception("didn't expect to have a Job") except AssertionError: pass except: raise def test_attribute_filter__set__(self): self.obj._attribute_filter__set__('a', 1) def testCopy(self): from copy import deepcopy myTestObj = deepcopy(self.obj) def test_readonly(self): self.obj._readonly() def test__getstate__(self): self.obj.__getstate__() def testClone(self): temp = self.obj.clone() def testCopyFrom(self): temp = GangaObject() temp.copyFrom(self.obj) def testPrintTree(self): self.obj.printTree() def testPrintPrepTree(self): self.obj.printPrepTree() def testPrintSummaryTree(self): self.obj.printSummaryTree() def test__eq__(self): self.obj == GangaObject() def test__ne__(self): self.obj != GangaObject() def tearDown(self): pass
class TestGangaObject(TestCase): def setUp(self): self.obj = GangaObject() def test_getReadAccess(self): self.obj._getReadAccess() def test_getWriteAccess(self): self.obj._getWriteAccess() def test_releaseWriteAccess(self): self.obj._releaseWriteAccess() def test_setRegistry(self): self.obj._setRegistry(None) def test_getRegistryID(self): print self.obj._getRegistryID() def test_setDirty(self): self.obj._setDirty() def test_setFlushed(self): self.obj._setFlushed() def test_declared_property(self): self.obj._declared_property('NotAProperty') def testGetJobObject(self): try: self.obj.getJobObject() raise Exception("didn't expect to have a Job") except AssertionError, err: pass except:
def __set__(self, obj, _val): # self is the attribute we're about to change # obj is the object we're about to make the change in # val is the value we're setting the attribute to. # item is the schema entry of the attribute we're about to change ## Try to remove all proxies val = ProxyDataDescriptor.__recursive_strip(_val) attr_name = getName(self) raw_obj = stripProxy(obj) new_val = None if not raw_obj._schema.hasAttribute(attr_name): raise GangaAttributeError("Cannot assign %s, as it is NOT an attribute in the schema for class: %s" % (attr_name, getName(obj))) #logger.debug("__set__") item = raw_obj._schema[attr_name] if item['protected']: raise ProtectedAttributeError('"%s" attribute is protected and cannot be modified' % (attr_name,)) if stripProxy(obj)._readonly(): if not item.getProperties()['changable_at_resubmit']: raise ReadOnlyObjectError('object %s is read-only and attribute "%s" cannot be modified now' % (repr(obj), attr_name)) # mechanism for locking of preparable attributes if item['preparable']: ## Does not modify val self.__preparable_set__(obj, val, attr_name) # if we set is_prepared to None in the GPI, that should effectively # unprepare the application if getName(self) == 'is_prepared': # Replace is_prepared on an application for another ShareDir object ## Does not modify val self.__prep_set__(obj, val) # catch assignment of 'something' to a preparable application if getName(self) == 'application': ## Does not modify val self.__app_set__(obj, val) # unwrap proxy if item.isA(ComponentItem): from .Filters import allComponentFilters cfilter = allComponentFilters[item['category']] stripper = lambda v: stripComponentObject(v, cfilter, item) else: stripper = None if item['sequence']: ## Does not modify val new_val = self.__sequence_set__(stripper, obj, val, attr_name) else: if stripper is not None: ## Shouldn't modify val new_val = stripper(val) else: ## Does not modify val new_val = self._stripAttribute(obj, val, attr_name) if new_val is None and val is not None: new_val = val final_val = None # apply attribute filter to component items if item.isA(ComponentItem): ## Does not modify val final_val = self._stripAttribute(obj, new_val, attr_name) else: final_val = new_val if final_val is None and val is not None: final_val = val ## Does not modify val? self._check_type(obj, final_val) GangaObject.__setattr__(raw_obj, attr_name, final_val)