Skip to content

Commit e87a7d8

Browse files
authored
Merge pull request #1124 from ethho/dev-tests-plat-150-bypass
PLAT-150: Migrate test_bypass_serialization.py
2 parents 3baa4f4 + cc7432c commit e87a7d8

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

tests/test_bypass_serialization.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import pytest
2+
import datajoint as dj
3+
import numpy as np
4+
from . import PREFIX
5+
from numpy.testing import assert_array_equal
6+
7+
test_blob = np.array([1, 2, 3])
8+
9+
10+
class Input(dj.Lookup):
11+
definition = """
12+
id: int
13+
---
14+
data: blob
15+
"""
16+
contents = [(0, test_blob)]
17+
18+
19+
class Output(dj.Manual):
20+
definition = """
21+
id: int
22+
---
23+
data: blob
24+
"""
25+
26+
27+
@pytest.fixture
28+
def schema_in(connection_test):
29+
schema = dj.Schema(
30+
PREFIX + "_test_bypass_serialization_in",
31+
context=dict(Input=Input),
32+
connection=connection_test,
33+
)
34+
schema(Input)
35+
yield schema
36+
schema.drop()
37+
38+
39+
@pytest.fixture
40+
def schema_out(connection_test):
41+
schema = dj.Schema(
42+
PREFIX + "_test_blob_bypass_serialization_out",
43+
context=dict(Output=Output),
44+
connection=connection_test,
45+
)
46+
schema(Output)
47+
yield schema
48+
schema.drop()
49+
50+
51+
def test_bypass_serialization(schema_in, schema_out):
52+
dj.blob.bypass_serialization = True
53+
contents = Input.fetch(as_dict=True)
54+
assert isinstance(contents[0]["data"], bytes)
55+
Output.insert(contents)
56+
dj.blob.bypass_serialization = False
57+
assert_array_equal(Input.fetch1("data"), Output.fetch1("data"))

0 commit comments

Comments
 (0)