NSLS-II / nslsii

NSLS-II related devices
BSD 3-Clause "New" or "Revised" License
10 stars 22 forks source link

IPython exception logger #73

Closed jklynch closed 4 years ago

jklynch commented 4 years ago

This PR adds one module with one function for logging exceptions to the IPython log file.

The new module is nslsii.common.ipynb.logutils. Should it be in nslsii.common instead?

Also, is there a way to write tests against IPython?

codecov-io commented 4 years ago

Codecov Report

Merging #73 into master will increase coverage by 0.85%. The diff coverage is 84.21%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #73      +/-   ##
==========================================
+ Coverage   52.16%   53.02%   +0.85%     
==========================================
  Files          11       13       +2     
  Lines         692      711      +19     
==========================================
+ Hits          361      377      +16     
- Misses        331      334       +3
Impacted Files Coverage Δ
nslsii/__init__.py 5.83% <0%> (-0.15%) :arrow_down:
nslsii/tests/test_logutils.py 100% <100%> (ø)
nslsii/common/ipynb/logutils.py 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 637177d...d3b01da. Read the comment docs.

tacaswell commented 4 years ago

Could you also add a call to this to base_config?

I added some ipython driven tests in https://github.com/bluesky/bluesky/pull/1242/files.

You can do something like

from mock import MagicMock
ip = IPython.core.interactiveshell.InteractiveShell()
ip.logger = MagicMock()
ip.set_custom_exc((BaseException, ), log_exception)
ip.run_cell("raise Exception")
assert ip.logger.log_wirte.call_count > 0
jklynch commented 4 years ago

added a test

mrakitin commented 4 years ago

It's good to have a test. We can use it as an example in the future.