Skip to content

Commit e2acbea

Browse files
committed
Migrate test_fetch_same
1 parent 0a498a6 commit e2acbea

File tree

1 file changed

+65
-55
lines changed

1 file changed

+65
-55
lines changed

tests/test_fetch_same.py

Lines changed: 65 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,72 @@
1-
from nose.tools import assert_equal
1+
import pytest
22
from . import PREFIX, CONN_INFO
33
import numpy as np
44
import datajoint as dj
55

6-
schema = dj.Schema(PREFIX + "_fetch_same", connection=dj.conn(**CONN_INFO))
6+
7+
class ProjData(dj.Manual):
8+
definition = """
9+
id : int
10+
---
11+
resp : float
12+
sim : float
13+
big : longblob
14+
blah : varchar(10)
15+
"""
16+
17+
18+
@pytest.fixture
19+
def schema_fetch_same(connection_root):
20+
schema = dj.Schema(
21+
PREFIX + "_fetch_same",
22+
context=dict(ProjData=ProjData),
23+
connection=connection_root,
24+
)
25+
schema(ProjData)
26+
ProjData().insert(
27+
[
28+
{"id": 0, "resp": 20.33, "sim": 45.324, "big": 3, "blah": "yes"},
29+
{
30+
"id": 1,
31+
"resp": 94.3,
32+
"sim": 34.23,
33+
"big": {"key1": np.random.randn(20, 10)},
34+
"blah": "si",
35+
},
36+
{
37+
"id": 2,
38+
"resp": 1.90,
39+
"sim": 10.23,
40+
"big": np.random.randn(4, 2),
41+
"blah": "sim",
42+
},
43+
]
44+
)
45+
yield schema
46+
schema.drop()
47+
48+
49+
@pytest.fixture
50+
def projdata():
51+
yield ProjData()
752

853

954
class TestFetchSame:
10-
@classmethod
11-
def setup_class(cls):
12-
@schema
13-
class ProjData(dj.Manual):
14-
definition = """
15-
id : int
16-
---
17-
resp : float
18-
sim : float
19-
big : longblob
20-
blah : varchar(10)
21-
"""
22-
23-
ProjData().insert(
24-
[
25-
{"id": 0, "resp": 20.33, "sim": 45.324, "big": 3, "blah": "yes"},
26-
{
27-
"id": 1,
28-
"resp": 94.3,
29-
"sim": 34.23,
30-
"big": {"key1": np.random.randn(20, 10)},
31-
"blah": "si",
32-
},
33-
{
34-
"id": 2,
35-
"resp": 1.90,
36-
"sim": 10.23,
37-
"big": np.random.randn(4, 2),
38-
"blah": "sim",
39-
},
40-
]
41-
)
42-
43-
cls.projdata = ProjData()
44-
45-
def test_object_conversion_one(self):
46-
new = self.projdata.proj(sub="resp").fetch("sub")
47-
assert_equal(new.dtype, np.float64)
48-
49-
def test_object_conversion_two(self):
50-
[sub, add] = self.projdata.proj(sub="resp", add="sim").fetch("sub", "add")
51-
assert_equal(sub.dtype, np.float64)
52-
assert_equal(add.dtype, np.float64)
53-
54-
def test_object_conversion_all(self):
55-
new = self.projdata.proj(sub="resp", add="sim").fetch()
56-
assert_equal(new["sub"].dtype, np.float64)
57-
assert_equal(new["add"].dtype, np.float64)
58-
59-
def test_object_no_convert(self):
60-
new = self.projdata.fetch()
61-
assert_equal(new["big"].dtype, "object")
62-
assert_equal(new["blah"].dtype, "object")
55+
def test_object_conversion_one(self, schema_fetch_same, projdata):
56+
new = projdata.proj(sub="resp").fetch("sub")
57+
assert new.dtype == np.float64
58+
59+
def test_object_conversion_two(self, schema_fetch_same, projdata):
60+
[sub, add] = projdata.proj(sub="resp", add="sim").fetch("sub", "add")
61+
assert sub.dtype == np.float64
62+
assert add.dtype == np.float64
63+
64+
def test_object_conversion_all(self, schema_fetch_same, projdata):
65+
new = projdata.proj(sub="resp", add="sim").fetch()
66+
assert new["sub"].dtype == np.float64
67+
assert new["add"].dtype == np.float64
68+
69+
def test_object_no_convert(self, schema_fetch_same, projdata):
70+
new = projdata.fetch()
71+
assert new["big"].dtype == "object"
72+
assert new["blah"].dtype == "object"

0 commit comments

Comments
 (0)