def __get__(self, instance, owner): if not instance: return None value = self.method(instance) with change_lock(instance, 'none'): setattr(instance, self.method.__name__, value) return value
def __get__(self, instance, owner): # pylint: disable=missing-function-docstring if not instance: return None value = self.method(instance) with change_lock(instance, 'none'): setattr(instance, self.method.__name__, value) return value
def _calculate_wannier(self): """ Calculates and sets the Wannier charge centers and Wilson loop eigenstates. """ wcc, wilson_eigenstates = self._calculate_wannier_from_wilson( self.wilson ) with change_lock(self, 'none'): self.wcc = wcc self.wilson_eigenstates = wilson_eigenstates
def test_open(locked_instance): a = locked_instance(OpenLocker) assert a.x == 1 a.x = 2 assert a.x == 2 del a.x a.y = 2 with pytest.raises(ValueError): a.attr_mod_ctrl = 'invalid' with change_lock(a, 'all'): with pytest.raises(AttributeError): a.y = 3
def test_superconst(locked_instance): a = locked_instance(SuperConstLocker) assert a.x == 1 with pytest.raises(AttributeError): a.x = 2 with pytest.raises(AttributeError): del a.x with pytest.raises(AttributeError): a.y = 2 with pytest.raises(AttributeError): a.attr_mod_ctrl = 'none' with pytest.raises(AttributeError): with change_lock(a): a.y = 3
def test_const(locked_instance): a = locked_instance(ConstLocker) assert a.x == 1 with pytest.raises(AttributeError): a.x = 2 del a.x with pytest.raises(AttributeError): a.y = 2 with pytest.raises(ValueError): a.attr_mod_ctrl = 'invalid' with change_lock(a): a.x = 3 with pytest.raises(AttributeError): a.x = 2 a.attr_mod_ctrl = 'none' a.x = 2 del a.x a.y = 2
def test_return_nontrivial_getattr(locked_instance): a = locked_instance(Locker) assert a.y == 2 with change_lock(a, 'none'): a.z = 3
def _calculate_gap(self): with change_lock(self, 'none'): self.gap_pos, self.gap_size = _gapfind(self.wcc)
def _calculate_wannier(self): wcc, wilson_eigenstates = super()._calculate_wannier(self.wilson) with change_lock(self, 'none'): self.wcc = wcc self.wilson_eigenstates = wilson_eigenstates