File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 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" ))
You can’t perform that action at this time.
0 commit comments