-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_discovery.py
246 lines (219 loc) · 7.95 KB
/
test_discovery.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import asyncio
from http.server import HTTPServer, SimpleHTTPRequestHandler
import logging
import os
import shutil
import threading
from datamart_core import Discoverer
from datamart_core.common import setup_logging
logger = logging.getLogger(__name__)
class TestDiscoverer(Discoverer):
"""Discovery plugin for the test suite.
"""
def discover_datasets(self):
# Put this one on disk
with open('geo.csv', 'rb') as src:
with self.write_to_shared_storage('geo') as dst:
shutil.copyfileobj(src, dst)
self.record_dataset(
dict(),
{
# Omit name, should be set to 'geo' automatically
'description': "Another simple <em>CSV</em> with places",
'source': 'remi',
},
dataset_id='geo',
)
# Use URL for this one
self.record_dataset(
dict(direct_url='http://test-discoverer:8080/geo_wkt.csv'),
{
'name': 'geo_wkt',
'description': "Simple CSV in <a href=\"https://en.wikipedia.o"
+ "rg/wiki/Well-known_text_representation_of_ge"
+ "ometry\">WKT</a> format",
'source': 'remi',
},
dataset_id='geo_wkt',
)
# Put this one on disk
with open('agg.csv', 'rb') as src:
with self.write_to_shared_storage('agg') as dst:
shutil.copyfileobj(src, dst)
self.record_dataset(
dict(),
{
# Omit name, should be set to 'agg' automatically
'description': "Simple CSV with ids and salaries to test "
+ "aggregation for numerical attributes",
'source': 'fernando',
},
dataset_id='agg',
)
# Put this one on disk
with open('lazo.csv', 'rb') as src:
with self.write_to_shared_storage('lazo') as dst:
shutil.copyfileobj(src, dst)
self.record_dataset(
dict(),
{
# Omit name, should be set to 'lazo' automatically
'description': "Simple CSV with states and years"
" to test the Lazo index service",
'source': 'fernando',
},
dataset_id='lazo',
)
# Use URL for this one
self.record_dataset(
dict(direct_url='http://test-discoverer:8080/empty.csv'),
{
# Omit name, should be set to 'empty' automatically
'description': "A CSV with no rows to test alternate index",
'source': 'remi',
},
dataset_id='empty',
)
# Put this one on disk
with open('daily.csv', 'rb') as src:
with self.write_to_shared_storage('daily') as dst:
shutil.copyfileobj(src, dst)
self.record_dataset(
dict(),
{
'name': 'daily',
'description': "Temporal dataset with daily resolution",
'source': 'remi',
},
dataset_id='daily',
)
# Use URL for this one
self.record_dataset(
dict(direct_url='http://test-discoverer:8080/hourly.csv'),
{
# Omit name, should be set to 'hourly' automatically
'description': "Temporal dataset with hourly resolution",
'source': 'remi',
},
dataset_id='hourly',
)
# Use URL for this one
self.record_dataset(
dict(direct_url='http://test-discoverer:8080/invalid.bin'),
{
'name': 'Invalid, binary',
'description': "Some binary data that can't be parsed",
'source': 'remi',
},
dataset_id='invalid',
)
# Use URL for this one
self.record_dataset(
dict(direct_url='http://test-discoverer:8080/dates_pivoted.csv'),
{
'name': 'dates pivoted',
'description': "Temporal dataset but in columns",
'source': 'remi',
},
dataset_id='dates_pivoted',
)
# Use URL for this one
self.record_dataset(
dict(direct_url='http://test-discoverer:8080/years_pivoted.csv'),
{
'name': 'years pivoted',
'description': "Temporal dataset but in columns",
'source': 'remi',
},
dataset_id='years_pivoted',
)
# Use URL for this one
self.record_dataset(
dict(direct_url='http://test-discoverer:8080/spss.sav'),
{
# Omit name, should be set to 'spss' automatically
'description': "SPSS format test",
'source': 'remi',
'source_url': 'https://en.wikipedia.org/wiki/SPSS',
},
dataset_id='spss',
)
# Use URL for this one
self.record_dataset(
dict(direct_url='http://test-discoverer:8080/excel.xlsx'),
{
# Omit name, should be set to 'excel' automatically
'description': "Excel format 2007 test",
'source': 'remi',
'source_url': 'https://en.wikipedia.org/wiki/Microsoft_Excel',
},
dataset_id='excel',
)
# Use URL for this one
self.record_dataset(
dict(direct_url='http://test-discoverer:8080/excel97.xls'),
{
# Omit name, should be set to 'excel97' automatically
'description': "Excel format 1997 test",
'source': 'remi',
'source_url': 'https://en.wikipedia.org/wiki/Microsoft_Excel',
},
dataset_id='excel97',
)
# Use URL for this one
self.record_dataset(
dict(direct_url='http://test-discoverer:8080/parquet.parquet'),
{
# Omit name, should be set to 'excel97' automatically
'description': "Apache Parquet test",
'source': 'remi',
'source_url': 'https://github.com/apache/parquet-format',
},
dataset_id='parquet',
)
# Use URL for this one
self.record_dataset(
dict(direct_url='http://test-discoverer:8080/stata114.dta'),
{
# Omit name, should be set to 'stata114' automatically
'description': "Stata format 114 test",
'source': 'remi',
'source_url': 'https://en.wikipedia.org/wiki/Stata',
},
dataset_id='stata114',
)
# Use URL for this one
self.record_dataset(
dict(direct_url='http://test-discoverer:8080/stata118.dta'),
{
# Omit name, should be set to 'stata118' automatically
'description': "Stata format 118 test",
'source': 'remi',
'source_url': 'https://en.wikipedia.org/wiki/Stata',
},
dataset_id='stata118',
)
# Use URL for this one
self.record_dataset(
dict(direct_url='http://test-discoverer:8080/basic.csv'),
{
'name': "basic",
'description': "This is a very simple CSV with people",
'source': 'remi',
},
dataset_id='basic',
)
def server():
with HTTPServer(('0.0.0.0', 8080), SimpleHTTPRequestHandler) as httpd:
httpd.serve_forever()
if __name__ == '__main__':
setup_logging()
os.chdir('tests/data')
# Start a web server
server_thread = threading.Thread(target=server)
server_thread.setDaemon(True)
server_thread.start()
fut = asyncio.ensure_future(
TestDiscoverer('datamart.test').run()
)
asyncio.get_event_loop().run_forever()