Skip to content

Commit 2549abd

Browse files
committed
take out count condition and update test
1 parent 5dc99c2 commit 2549abd

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

datajoint/blob.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,7 @@ def read_value(self, dtype=None, count=1):
441441
except ValueError:
442442
self.is_32_bit = True
443443
self._pos = self._pos_prev
444-
data = np.frombuffer(self._blob, dtype='uint32',
445-
count=self.read_value() if count != 1 else 1,
446-
offset=self._pos)
444+
data = np.frombuffer(self._blob, dtype='uint32', count=self.read_value(), offset=self._pos)
447445
self._pos_prev = self._pos
448446
self._pos += data.dtype.itemsize * data.size
449447
return data[0] if count == 1 else data

tests/test_blob.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,26 @@ def test_complex():
134134

135135

136136
def test_insert_longblob():
137-
insert_64 = {'id': 1, 'data':
137+
insert_dj_blob = {'id': 1, 'data': [1, 2, 3]}
138+
schema.Longblob.insert1(insert_dj_blob)
139+
assert (schema.Longblob & 'id=1').fetch1() == insert_dj_blob
140+
(schema.Longblob & 'id=1').delete()
141+
142+
query_mym_blob = {'id': 1, 'data': np.array([1, 2, 3])}
143+
schema.Longblob.insert1(query_mym_blob)
144+
assert (schema.Longblob & 'id=1').fetch1()['data'].all() == query_mym_blob['data'].all()
145+
(schema.Longblob & 'id=1').delete()
146+
147+
query_32_blob = ("INSERT INTO djtest_test1.longblob (id, data) VALUES (1, "
148+
"X'6D596D00530200000001000000010000000400000068697473007369646573007461736B73007374"
149+
"616765004D000000410200000001000000070000000600000000000000000000000000F8FF00000000"
150+
"0000F03F000000000000F03F0000000000000000000000000000F03F00000000000000000000000000"
151+
"00F8FF230000004102000000010000000700000004000000000000006C006C006C006C00720072006C"
152+
"0023000000410200000001000000070000000400000000000000640064006400640064006400640025"
153+
"00000041020000000100000008000000040000000000000053007400610067006500200031003000')")
154+
dj.conn().query(query_32_blob).fetchall()
155+
assert (schema.Longblob & 'id=1').fetch1() == {
156+
'id': 1, 'data':
138157
np.rec.array(
139158
[[
140159
(
@@ -147,27 +166,5 @@ def test_insert_longblob():
147166
dtype=[('hits', 'O'), ('sides', 'O'), ('tasks', 'O'), ('stage', 'O')]
148167
)
149168
}
150-
schema.Longblob.insert1(insert_64)
151-
# assert (schema.Longblob & 'id=1').fetch1() == insert_64
152169
(schema.Longblob & 'id=1').delete()
153170

154-
query_32 = ("INSERT INTO djtest_test1.longblob (id, data) VALUES (1, "
155-
"X'6D596D00530200000001000000010000000400000068697473007369646573007461736B73007374"
156-
"616765004D000000410200000001000000070000000600000000000000000000000000F8FF00000000"
157-
"0000F03F000000000000F03F0000000000000000000000000000F03F00000000000000000000000000"
158-
"00F8FF230000004102000000010000000700000004000000000000006C006C006C006C00720072006C"
159-
"0023000000410200000001000000070000000400000000000000640064006400640064006400640025"
160-
"00000041020000000100000008000000040000000000000053007400610067006500200031003000')")
161-
dj.conn().query(query_32).fetchall()
162-
assert (schema.Longblob & 'id=1').fetch1() == insert_64
163-
(schema.Longblob & 'id=1').delete()
164-
165-
query_64 = ("INSERT INTO djtest_test1.longblob (id, data) VALUES (1, "
166-
"X'646A300002060000000000000004000000000000000A01000104000000000000000A010002040000"
167-
"00000000000A01000304000000000000000A01000404000000000000000A0100050400000000000000"
168-
"0A010006')")
169-
170-
dj.conn().query(query_64).fetchall()
171-
query_64_fetch = {'id': 1, 'data': [1, 2, 3, 4, 5, 6]}
172-
assert (schema.Longblob & 'id=1').fetch1() == query_64_fetch
173-
(schema.Longblob & 'id=1').delete()

0 commit comments

Comments
 (0)