forked from LAMDA-NJU/Deep-Forest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_buffer.py
68 lines (50 loc) · 1.66 KB
/
test_buffer.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
import os
import pytest
import numpy as np
from deepforest import _io as io
open_buffer = io.Buffer(
use_buffer=True,
buffer_dir="./",
store_est=True,
store_pred=True,
store_data=True,
)
close_buffer = io.Buffer(use_buffer=False)
X = np.zeros((42, 42), dtype=np.uint8)
def test_buffer_name():
name = open_buffer.name
assert isinstance(name, str)
name = close_buffer.name
assert name is None
def test_store_data_close_buffer():
"""When `store_data` is False, the buffer directly returns the array."""
ret = close_buffer.cache_data(0, X)
assert isinstance(ret, np.ndarray)
def test_store_data_open_buffer():
"""
When `store_data` is True, the buffer returns the memmap object of the
dumped array.
"""
layer_idx = 0
ret = open_buffer.cache_data(layer_idx, X, is_training_data=True)
assert isinstance(ret, np.memmap)
assert os.path.exists(
os.path.join(
open_buffer.data_dir_, "joblib_train_{}.mmap".format(layer_idx)
)
)
ret = open_buffer.cache_data(layer_idx, X, is_training_data=False)
assert isinstance(ret, np.memmap)
assert os.path.exists(
os.path.join(
open_buffer.data_dir_, "joblib_test_{}.mmap".format(layer_idx)
)
)
def test_load_estimator_missing():
err_msg = "Missing estimator in the path: unknown.est."
with pytest.raises(FileNotFoundError, match=err_msg):
open_buffer.load_estimator("unknown.est")
def test_load_predictor_missing():
err_msg = "Missing predictor in the path: unknown.est."
with pytest.raises(FileNotFoundError, match=err_msg):
open_buffer.load_predictor("unknown.est")