-
Notifications
You must be signed in to change notification settings - Fork 6
/
testing.py
111 lines (97 loc) · 2.55 KB
/
testing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import unittest
import pandas as pd
from pandas.testing import assert_frame_equal
import bqemulatormanager
class TestBigquery(unittest.TestCase):
def test_query(self):
# test data
service_df = pd.DataFrame([
{
'id': 0,
'name': 'service-A'
},
{
'id': 1,
'name': 'service-B',
},
{
'id': 2,
'name': 'service-C',
},
])
use_df = pd.DataFrame([
{
'code': '0111',
'service_id': 0
},
{
'code': '0111',
'service_id': 1
},
{
'code': '0222',
'service_id': 0
},
])
package_df = pd.DataFrame([
{
'SERVICE_ID': 0,
'ID': 11,
},
{
'SERVICE_ID': 2,
'ID': 33,
},
])
user_df = pd.DataFrame([
{
'ID': '11',
'code': '0111'
},
{
'ID': '22',
'code': '0222'
},
{
'ID': '33',
'code': '0333'
},
{
'ID': '44',
'code': '0444'
},
{
'ID': '55',
'code': '0555'
},
])
expected_df = pd.DataFrame([
{
'code': '0111',
'service_name': 'service-A'
},
{
'code': '0111',
'service_name': 'service-B'
},
{
'code': '0222',
'service_name': 'service-A'
},
{
'code': '0333',
'service_name': 'service-C'
},
])
manager = bqemulatormanager.Manager(project='test', schema_path='examples/resources/schema_testing.yaml')
with manager:
manager.load(use_df, 'dataset1.user_use_list')
manager.load(service_df, 'dataset1.service')
manager.load(package_df, 'dataset1.package_use_list')
manager.load(user_df, 'dataset1.users')
with open('examples/query.sql') as f:
sql = f.read()
result = manager.query(sql)
assert_frame_equal(expected_df, result)
if __name__ == '__main__':
unittest.main()