This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #335 from ndawe/master
Silence cling error in tests and some clarification in docs
- Loading branch information
Showing
4 changed files
with
89 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
include MANIFEST.in | ||
recursive-include root_numpy *.root *.h *.cpp *.pyx *.pxi | ||
recursive-include examples *.py | ||
include *.py | ||
include README.rst | ||
include LICENSE | ||
global-exclude *.pyc *.pyo *.pyd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,82 @@ | ||
import os | ||
import sys | ||
import warnings | ||
import ROOT | ||
import root_numpy as rnp | ||
from numpy.random import RandomState | ||
import tempfile | ||
from contextlib import contextmanager | ||
import root_numpy as rnp | ||
from root_numpy.testdata import get_filepath | ||
import threading | ||
|
||
LOCK = threading.RLock() | ||
|
||
ROOT.gErrorIgnoreLevel = ROOT.kFatal | ||
warnings.filterwarnings('ignore', category=DeprecationWarning) | ||
warnings.filterwarnings('ignore', category=rnp.RootNumpyUnconvertibleWarning) | ||
RNG = RandomState(42) | ||
|
||
from root_numpy.testdata import get_filepath | ||
|
||
def load(data): | ||
if isinstance(data, list): | ||
return [get_filepath(x) for x in data] | ||
return get_filepath(data) | ||
|
||
import tempfile | ||
from contextlib import contextmanager | ||
|
||
@contextmanager | ||
def temp(): | ||
tmp_fd, tmp_path = tempfile.mkstemp(suffix='.root') | ||
tmp_root = ROOT.TFile.Open(tmp_path, 'recreate') | ||
yield tmp_root | ||
tmp_root.Close() | ||
os.close(tmp_fd) | ||
os.remove(tmp_path) | ||
try: | ||
yield tmp_root | ||
finally: | ||
tmp_root.Close() | ||
os.close(tmp_fd) | ||
os.remove(tmp_path) | ||
|
||
|
||
@contextmanager | ||
def silence_sout(): | ||
LOCK.acquire() | ||
sys.__stdout__.flush() | ||
origstdout = sys.__stdout__ | ||
oldstdout_fno = os.dup(sys.__stdout__.fileno()) | ||
devnull = os.open(os.devnull, os.O_WRONLY) | ||
newstdout = os.dup(1) | ||
os.dup2(devnull, 1) | ||
os.close(devnull) | ||
sys.__stdout__ = os.fdopen(newstdout, 'w') | ||
try: | ||
yield | ||
finally: | ||
sys.__stdout__ = origstdout | ||
sys.__stdout__.flush() | ||
os.dup2(oldstdout_fno, 1) | ||
LOCK.release() | ||
|
||
|
||
@contextmanager | ||
def silence_serr(): | ||
LOCK.acquire() | ||
sys.__stderr__.flush() | ||
origstderr = sys.__stderr__ | ||
oldstderr_fno = os.dup(sys.__stderr__.fileno()) | ||
devnull = os.open(os.devnull, os.O_WRONLY) | ||
newstderr = os.dup(2) | ||
os.dup2(devnull, 2) | ||
os.close(devnull) | ||
sys.__stderr__ = os.fdopen(newstderr, 'w') | ||
try: | ||
yield | ||
finally: | ||
sys.__stderr__ = origstderr | ||
sys.__stderr__.flush() | ||
os.dup2(oldstderr_fno, 2) | ||
LOCK.release() | ||
|
||
|
||
@contextmanager | ||
def silence(): | ||
with silence_sout(): | ||
with silence_serr(): | ||
yield |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters