-
Notifications
You must be signed in to change notification settings - Fork 784
Expand file tree
/
Copy pathtest_develop.py
More file actions
55 lines (41 loc) · 1.44 KB
/
Copy pathtest_develop.py
File metadata and controls
55 lines (41 loc) · 1.44 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
49
50
51
52
53
54
55
# Copyright (c) 2023 The InterpretML Contributors
# Distributed under the MIT software license
from interpret.develop import debug_info, debug_mode, print_debug_info, register_log
def test_debug_mode():
import logging
import sys
import pytest
handler = debug_mode(log_filename=sys.stderr, log_level="INFO", native_debug=False)
root = logging.getLogger("interpret")
root.removeHandler(handler)
with pytest.raises(
Exception, match="Cannot call debug_mode more than once in the same session."
):
debug_mode()
def test_debug_info():
debug_dict = debug_info()
assert isinstance(debug_dict, dict)
assert isinstance(debug_dict["interpret.__version__"], str)
def test_print_debug_info():
# Light smoke test.
print_debug_info()
assert 1 == 1
def test_register_log():
# Light smoke test.
import logging
import os
import sys
import tempfile
# Output to stream
handler = register_log(sys.stderr, "DEBUG")
root = logging.getLogger("interpret")
root.removeHandler(handler)
# Output to file
temp_log_path = os.path.join(tempfile.mkdtemp(), "test-log.txt")
handler = register_log(temp_log_path, "DEBUG")
handler.flush()
handler.close()
root = logging.getLogger("interpret")
root.removeHandler(handler)
# NOTE: Logging is not releasing the file despite close. This temporary file simply will not be deleted.
# os.remove(temp_log_path)