forked from facebookresearch/fairo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_utils.py
55 lines (43 loc) · 1.47 KB
/
test_utils.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
import os
from functools import wraps
import urllib.request
def download_asset(
filename,
folder_prefix=".",
prefix="test_assets/",
bucket_url="https://locobot-bucket.s3.amazonaws.com/",
):
prefix_url = bucket_url + prefix
final_url = prefix_url + filename
final_path = os.path.join(folder_prefix, filename)
os.makedirs(folder_prefix, exist_ok=True)
urllib.request.urlretrieve(final_url, final_path)
_downloaded = set()
def download_assets(assets, folder_prefix, url_prefix, refresh=False):
global _downloaded
status = False
failed = False
try:
for asset in assets:
full_path = os.path.join(folder_prefix, asset)
if full_path not in _downloaded:
if refresh or not os.path.isfile(full_path):
_downloaded.add(full_path)
download_asset(
asset,
folder_prefix=folder_prefix,
prefix=url_prefix,
)
except:
failed = True
return not failed
def skipIfOfflineDecorator(files, folder_prefix, url_prefix):
def decorator(fn):
@wraps(fn)
def wrapper(*args, **kwargs):
if not download_assets(files, folder_prefix, url_prefix):
raise unittest.SkipTest("Not able to download test assets, so skipping test")
else:
return fn(*args, **kwargs)
return wrapper
return decorator