def test_numpy_wrapper(): x = Array(np.random.randn(4).astype(object)) x[0] = get_tdict() x[1] = 0 assert x[1] == 0 x.begin() x[0].arr = x x[1] = 10 assert 'arr' in x[0] assert len(x[0].arr) == len(x) assert x[1] == 10 assert repr(x) == repr(json_unpack(json_pack(x))) x.abort() assert x[1] == 0 assert 'arr' not in x[0] assert repr(json_unpack(json_pack(x))) == repr(x)
def test_complex_array(): x = np.arange(3).astype(object) x[0] = get_tdict() p = json_pack(x) c = json_unpack(p) assert repr(x) == repr(c)
def test_json_pack_transactionable(): data = get_tdict() s = json_pack(data) assert repr(json_unpack(s)) == repr(data) data.begin() data[1234] = 'element' assert 1234 in data assert 'element' == data[1234] data.abc = 123 assert 'abc' in data assert data.abc == 123 assert data['abc'] == 123 data.abort() assert repr(json_unpack(s)) == repr(data)
def load(self, data): obj = json_unpack(data) # load registries self.config_files = obj.config_files # unpack tmembers for mem in self._tmembers: self.__dict__[mem] = obj.__dict__[mem] self.name = obj.name self._in_transaction = obj._in_transaction self._in_progress = obj._in_progress self.DEBUG = obj.DEBUG
def test_numpy_arrays(): x = np.random.randn(10) p = json_pack(x) c = json_unpack(p) assert (c - x).sum() == 0
def load(self, state): self.agents = {user: json_unpack(data) for user, data in state.items()}