-
Notifications
You must be signed in to change notification settings - Fork 10
/
conftest.py
58 lines (38 loc) · 1.47 KB
/
conftest.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
import hashlib
import os
import sys
from urllib.parse import urljoin
import pytest
import requests
TEST_DATA_URL = "https://cdat.llnl.gov/cdat/sample_data/"
def pytest_sessionstart(session):
download_all_test_data()
def download_all_test_data():
for x in ["test_big_data_files.txt", "test_data_files.txt"]:
download_test_data(x)
def download_test_data(test_data_info):
test_data_info_path = os.path.join("share", test_data_info)
test_data_local_path = os.path.join(sys.prefix, "share", "cdat",
"sample_data")
if not os.path.exists(test_data_local_path):
os.makedirs(test_data_local_path)
with open(test_data_info_path) as fd:
data = fd.readlines()
for x in data[1:]:
md5, name = x.split()
local_file = os.path.join(test_data_local_path, name)
remote_url = urljoin(TEST_DATA_URL, name)
if os.path.exists(local_file):
print(f"Skipping {remote_url}, already exists")
continue
print(f"Downloading {remote_url} to {local_file}")
response = requests.get(remote_url, stream=True)
response.raise_for_status()
m = hashlib.md5()
with open(local_file, "wb") as fd:
for chunk in response.iter_content(2048):
m.update(chunk)
fd.write(chunk)
assert m.hexdigest() == md5, f"Missmatch hash for {remote_url!r}"
if __name__ == "__main__":
download_all_test_data()