-
Notifications
You must be signed in to change notification settings - Fork 475
Expand file tree
/
Copy pathtest_utils.py
More file actions
48 lines (33 loc) · 1.18 KB
/
test_utils.py
File metadata and controls
48 lines (33 loc) · 1.18 KB
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
import os
import sys
import numpy as np
import pytest
import ctranslate2
def get_data_dir():
data_dir = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "..", "..", "tests", "data"
)
# Verify that downloaded files are present.
translit_model = os.path.join(data_dir, "models", "v1", "aren-transliteration")
if not os.path.isdir(translit_model):
pytest.skip("Data files are not available")
return data_dir
def write_tokens(batch_tokens, path):
with open(path, "w", encoding="utf-8") as f:
for tokens in batch_tokens:
f.write(" ".join(tokens))
f.write("\n")
def array_equal(a, b):
return a.dtype == b.dtype and np.array_equal(a, b)
skip_on_windows = pytest.mark.skipif(
sys.platform == "win32", reason="Test case disabled on Windows"
)
only_on_linux = pytest.mark.skipif(
sys.platform != "linux", reason="Test case only running on Linux"
)
require_cuda = pytest.mark.skipif(
ctranslate2.get_cuda_device_count() == 0, reason="Test case requires a CUDA device"
)
on_available_devices = pytest.mark.parametrize(
"device", ["cpu"] + (["cuda"] if ctranslate2.get_cuda_device_count() > 0 else [])
)