MCPcopy
hub / github.com/mne-tools/mne-python / test_logging_options

Function test_logging_options

mne/utils/tests/test_logging.py:83–158  ·  view source on GitHub ↗

Test logging (to file).

(tmp_path)

Source from the content-addressed store, hash-verified

81
82
83def test_logging_options(tmp_path):
84 """Test logging (to file)."""
85 with use_log_level(None): # just ensure it's set back
86 with pytest.raises(ValueError, match="Invalid value for the 'verbose"):
87 set_log_level("foo")
88 test_name = tmp_path / "test.log"
89 with open(fname_log) as old_log_file:
90 # [:-1] used to strip an extra "No baseline correction applied"
91 old_lines = clean_lines(old_log_file.readlines())
92 old_lines.pop(-1)
93 with open(fname_log_2) as old_log_file_2:
94 old_lines_2 = clean_lines(old_log_file_2.readlines())
95 old_lines_2.pop(14)
96 old_lines_2.pop(-1)
97
98 if test_name.is_file():
99 os.remove(test_name)
100 # test it one way (printing default off)
101 set_log_file(test_name)
102 set_log_level("WARNING")
103 # should NOT print
104 evoked = read_evokeds(fname_evoked, condition=1)
105 with open(test_name) as fid:
106 assert fid.readlines() == []
107 # should NOT print
108 evoked = read_evokeds(fname_evoked, condition=1, verbose=False)
109 with open(test_name) as fid:
110 assert fid.readlines() == []
111 # should NOT print
112 evoked = read_evokeds(fname_evoked, condition=1, verbose="WARNING")
113 with open(test_name) as fid:
114 assert fid.readlines() == []
115 # SHOULD print
116 evoked = read_evokeds(fname_evoked, condition=1, verbose=True)
117 with open(test_name) as new_log_file:
118 new_lines = clean_lines(new_log_file.readlines())
119 assert new_lines == old_lines
120 set_log_file(None) # Need to do this to close the old file
121 os.remove(test_name)
122
123 # now go the other way (printing default on)
124 set_log_file(test_name)
125 set_log_level("INFO")
126 # should NOT print
127 evoked = read_evokeds(fname_evoked, condition=1, verbose="WARNING")
128 with open(test_name) as fid:
129 assert fid.readlines() == []
130 # should NOT print
131 evoked = read_evokeds(fname_evoked, condition=1, verbose=False)
132 with open(test_name) as fid:
133 assert fid.readlines() == []
134 # SHOULD print
135 evoked = read_evokeds(fname_evoked, condition=1)
136 with open(test_name) as new_log_file:
137 new_lines = clean_lines(new_log_file.readlines())
138 assert new_lines == old_lines
139 # check to make sure appending works (and as default, raises a warning)
140 set_log_file(test_name, overwrite=False)

Callers

nothing calls this directly

Calls 8

use_log_levelClass · 0.90
set_log_levelFunction · 0.90
set_log_fileFunction · 0.90
read_evokedsFunction · 0.90
catch_loggingClass · 0.90
clean_linesFunction · 0.85
getvalueMethod · 0.80
removeMethod · 0.45

Tested by

no test coverage detected