summaryrefslogtreecommitdiff
path: root/numpy/distutils/tests
diff options
context:
space:
mode:
authorMatthew <quitesimplymatt@gmail.com>2021-11-11 15:38:16 +0000
committerMatthew <quitesimplymatt@gmail.com>2021-11-12 17:10:12 +0000
commitd04c9ef75a711c9117f5c5662ca604ed5b88607d (patch)
treeeab51e66cb3397b1b139c5b7384bf718815c7069 /numpy/distutils/tests
parent9c28152850109cdb567eaab7a872aa1429e51f55 (diff)
downloadnumpy-d04c9ef75a711c9117f5c5662ca604ed5b88607d.tar.gz
ENH: add log level as prefixes to respective messages
Diffstat (limited to 'numpy/distutils/tests')
-rw-r--r--numpy/distutils/tests/test_log.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/numpy/distutils/tests/test_log.py b/numpy/distutils/tests/test_log.py
new file mode 100644
index 000000000..36f49f592
--- /dev/null
+++ b/numpy/distutils/tests/test_log.py
@@ -0,0 +1,32 @@
+import io
+import re
+from contextlib import redirect_stdout
+
+import pytest
+
+from numpy.distutils import log
+
+
+def setup_module():
+ log.set_verbosity(2, force=True) # i.e. DEBUG
+
+
+def teardown_module():
+ log.set_verbosity(0, force=True) # the default
+
+
+r_ansi = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])")
+
+
+@pytest.mark.parametrize("func_name", ["error", "warn", "info", "debug"])
+def test_log_prefix(func_name):
+ func = getattr(log, func_name)
+ msg = f"{func_name} message"
+ f = io.StringIO()
+ with redirect_stdout(f):
+ func(msg)
+ out = f.getvalue()
+ assert out # sanity check
+ clean_out = r_ansi.sub("", out)
+ line = next(line for line in clean_out.splitlines())
+ assert line == f"{func_name.upper()}: {msg}"