diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 553fc91..ce17c61 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -29,7 +29,7 @@ jobs: - name: Install histogram run: python -m pip install -e . - name: Run tests - run: xvfb-run --server-args="-screen 0 1920x1080x24" -a python -m pytest --cov --cov-report=xml --cov-report=term --cov-config=.coveragerc + run: python -m pytest --log-cli-level=INFO --cov=src --cov-report=xml --cov-report=term - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4 with: diff --git a/.travis.yml b/.travis.yml index 7f97e42..f45987b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ install: - conda update conda - conda config --add channels conda-forge - conda config --add channels mcvine - - conda create -n testenv python=$TRAVIS_PYTHON_VERSION anaconda-client future pytest gxx_linux-64=7 cmake danse.ins journal pyre h5py matplotlib + - conda create -n testenv python=$TRAVIS_PYTHON_VERSION anaconda-client future pytest gxx_linux-64=7 cmake danse.ins pyre h5py matplotlib - source activate testenv - conda config --set anaconda_upload no - export SRC=$PWD diff --git a/CMakeLists.txt b/CMakeLists.txt index 217d393..b363698 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,13 +30,13 @@ set (PKGCLOUD_REPO "ins") # set(DOCKER_PKGING_DEB_DIST_NAME "ubuntu") # set(DOCKER_PKGING_DEB_DIST_VERSION "12.04") # dependencies -set (DOCKER_PKGING_DEPS_DEB "python-numpy danse.ins journal pyre") -set (DOCKER_PKGING_DEPS_RPM "numpy danse.ins journal pyre") +set (DOCKER_PKGING_DEPS_DEB "python-numpy danse.ins pyre") +set (DOCKER_PKGING_DEPS_RPM "numpy danse.ins pyre") set (DOCKER_PKGING_TEST_SRPM ". /opt/danse/bin/setup-danse.sh && python -c 'import histogram as p; print p'") set (DOCKER_PKGING_TEST_RPM ${DOCKER_PKGING_TEST_SRPM}) set (DOCKER_PKGING_TEST_DEB ${DOCKER_PKGING_TEST_SRPM}) -set (CONDA_PKGING_BUILD_DEPS "python numpy journal") -set (CONDA_PKGING_RUN_DEPS "python numpy danse.ins journal pyre h5py") +set (CONDA_PKGING_BUILD_DEPS "python numpy") +set (CONDA_PKGING_RUN_DEPS "python numpy danse.ins pyre h5py") # variables set (PYBINDING_NAME "${PROJECT_NAME}module") diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index 825e242..77acafa 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -36,8 +36,7 @@ requirements: - versioningit run: - numpy - - pyre - - journal + - pyre=0.8.3 test: imports: diff --git a/environment.yml b/environment.yml index d5aa904..53ba0b9 100644 --- a/environment.yml +++ b/environment.yml @@ -13,15 +13,15 @@ dependencies: - coverage - cmake - gxx_linux-64 - - numpy >= 1.20.3,< 2.0 - - python >=3.8 + - numpy == 1.26.4 + - python >=3.10 - pyre == 0.8.3 - - journal==0.8.4 - matplotlib - h5py - pre-commit - pytest - pytest-cov + - pytest-xvfb - python-build - sphinx - sphinx-rtd-theme diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index c1e0ec4..8941dc0 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -47,8 +47,6 @@ add_definitions(-DUSE_DANSE_NAMESPACE ) # include python headers include_directories( ${PYTHON_INCLUDE_DIRS} ) -# assume journal is already deployed at the same deployment prefix -# where we are going to deploy histogram include_directories( ${DEPLOYMENT_PREFIX}/include ) # export headers from this project diff --git a/lib/Histogrammer.h b/lib/Histogrammer.h index 4337072..d4e22f9 100644 --- a/lib/Histogrammer.h +++ b/lib/Histogrammer.h @@ -16,7 +16,6 @@ #define H_HISTOGRAM_HISTOGRAMMER #include "OutOfBound.h" -#include "journal/warning.h" HISTOGRAM_NAMESPACE_START @@ -50,10 +49,7 @@ HISTOGRAM_NAMESPACE_START IDataType i = m_e2x( e, m_x ); if (m_fx.isOutofbound(m_x)) { #ifdef DEBUG - journal::warning_t warning("Histogrammer1"); - warning << journal::at(__HERE__) - << "OutOfBound: " << m_x - << journal::endl; + printf("Warning Histogrammer1 %s:%d\n", __FILE__, __LINE__); #endif return; } @@ -65,10 +61,7 @@ HISTOGRAM_NAMESPACE_START } catch (OutOfBound & e) { #ifdef DEBUG - journal::warning_t warning("Histogrammer1"); - warning << journal::at(__HERE__) - << e.what() - << journal::endl; + printf("Warning Histogrammer1 %s:%d\n", __FILE__, __LINE__); #endif } } @@ -117,10 +110,7 @@ HISTOGRAM_NAMESPACE_START IDataType i = m_e2xy( e, m_x, m_y ); if (m_fxy.isOutofbound(m_x, m_y)) { #ifdef DEBUG - journal::warning_t warning("Histogrammer2"); - warning << journal::at(__HERE__) - << "OutOfBound: " << m_x << ", " << m_y - << journal::endl; + printf("Warning Histogrammer1 %s:%d\n", __FILE__, __LINE__); #endif return; } @@ -132,10 +122,7 @@ HISTOGRAM_NAMESPACE_START } catch (OutOfBound & e) { #ifdef DEBUG - journal::warning_t warning("Histogrammer2"); - warning << journal::at(__HERE__) - << e.what() - << journal::endl; + printf("Warning Histogrammer1 %s:%d\n", __FILE__, __LINE__); #endif } } @@ -186,10 +173,7 @@ HISTOGRAM_NAMESPACE_START IDataType i = m_e2xxxx( e, m_x1, m_x2, m_x3, m_x4 ); if (m_fxxxx.isOutofbound( m_x1, m_x2, m_x3, m_x4 )) { #ifdef DEBUG - journal::warning_t warning("Histogrammer4"); - warning << journal::at(__HERE__) - << "OutOfBound: " << m_x1 << ", " << m_x2 << ", " << m_x3 << ", " << m_x4 - << journal::endl; + printf("Warning Histogrammer1 %s:%d\n", __FILE__, __LINE__); #endif return; } @@ -201,10 +185,7 @@ HISTOGRAM_NAMESPACE_START } catch (OutOfBound & e) { #ifdef DEBUG - journal::warning_t warning("Histogrammer4"); - warning << journal::at(__HERE__) - << e.what() - << journal::endl; + printf("Warning Histogrammer1 %s:%d\n", __FILE__, __LINE__); #endif } } diff --git a/lib/NdArray.h b/lib/NdArray.h index 9027e06..924cd22 100644 --- a/lib/NdArray.h +++ b/lib/NdArray.h @@ -18,9 +18,6 @@ #include #include "OutOfBound.h" -#include "journal/debug.h" - - HISTOGRAM_NAMESPACE_START /// Multiple dimensional array. @@ -70,24 +67,17 @@ HISTOGRAM_NAMESPACE_START { m_size1D = 1; #ifdef DEBUG - journal::debug_t debug("NdArray"); - debug << journal::at(__HERE__) - << "dimension: " << dimension() << journal::endl - << "shape: " ; + printf("Warning NdArray %s:%d\n", __FILE__, __LINE__); #endif for (unsigned int i=0; i= 1.20.3,< 2.0", + "numpy == 1.26.4" ] license = { text = "MIT" } keywords = ["neutrons", "histogram", "python"] @@ -56,7 +56,8 @@ histogram-cli = "histogram.Histogram:main" # pytest.ini [tool.pytest.ini_options] - +log_cli = true +log_file_format = "%(asctime)s [%(levelname)8s] (%(path)s:%(lineno)s) %(message)s" norecursedirs = [".svn","_build"] # ignore tests in ndarray due to missing stdVector module not found testpaths =[ diff --git a/rpm.spec.in b/rpm.spec.in index e16ce2a..c53ae2e 100644 --- a/rpm.spec.in +++ b/rpm.spec.in @@ -12,7 +12,6 @@ BuildRequires: gcc-c++ BuildRequires: cmake > 2.6 BuildRequires: make BuildRequires: python-devel -BuildRequires: journal Requires: python Requires: python-h5py diff --git a/src/histogram/AxisMapperCreater.py b/src/histogram/AxisMapperCreater.py index 5986e46..0b405ab 100644 --- a/src/histogram/AxisMapperCreater.py +++ b/src/histogram/AxisMapperCreater.py @@ -2,9 +2,9 @@ # Jiao Lin Copyright (c) 2005 All rights reserved -import journal +import logging -debug = journal.debug("ins.histogram.AxisMapperCreater") +logger = logging.getLogger("Histogram") from .EvenlyContinuousAxisMapper import EvenlyContinuousAxisMapper diff --git a/src/histogram/DatasetBase.py b/src/histogram/DatasetBase.py index 8a408b3..51879a2 100644 --- a/src/histogram/DatasetBase.py +++ b/src/histogram/DatasetBase.py @@ -1,9 +1,9 @@ #!/usr/bin/env python # Timothy M. Kelley Copyright (c) 2005 All rights reserved -import journal +import logging -debug = journal.debug("histogram.DatasetBase") +logger = logging.getLogger("Histogram") msg = "class {0!s} must override {1!s}" diff --git a/src/histogram/DatasetContainer.py b/src/histogram/DatasetContainer.py index 06d8fc5..a4861a6 100644 --- a/src/histogram/DatasetContainer.py +++ b/src/histogram/DatasetContainer.py @@ -1,9 +1,8 @@ #!/usr/bin/env python # Timothy M. Kelley Copyright (c) 2005 All rights reserved +import logging -import journal - -debug = journal.debug("histogram") +logger = logging.getLogger("Histogram") class DatasetContainer(object): @@ -22,7 +21,7 @@ def addDataset(self, name, id, dataset): # 1. store by name if name not in self._byNames: self._byNames[name] = dataset - debug.log("{0!s} added dataset {1!s}".format(self, name)) + logger.debug("{0!s} added dataset {1!s}".format(self, name)) else: msg = "container already has dataset named {0!s}".format(name) raise ValueError(msg) @@ -79,7 +78,7 @@ def replaceDataset(self, name=None, dataset=None, id=None): name = name or self._id2name[id] id = id or self._name2id[name] - debug.log("{0!s} replaced dataset {1!s} (id={2!s})".format(self, name, id)) + logger.debug("{0!s} replaced dataset {1!s} (id={2!s})".format(self, name, id)) self._byNames[name] = dataset self._byIds[id] = [name, dataset] diff --git a/src/histogram/Histogram.py b/src/histogram/Histogram.py index fe94aa8..e30652f 100644 --- a/src/histogram/Histogram.py +++ b/src/histogram/Histogram.py @@ -7,13 +7,13 @@ ## in histogram.__init__ package to create histogram. -import journal from functools import reduce -debug = journal.debug("ins.histogram.Histogram") - import operator from .DictAttributeCont import AttributeCont +import logging + +logger = logging.getLogger("Histogram") class Histogram(AttributeCont): @@ -301,7 +301,7 @@ def __setitem__(self, indexes_or_slice, v): if rhs is not None: lhs[indexSlices] = rhs else: - debug.log("indefinite behavior: setting to None") + logger.debug("indefinite behavior: setting to None") continue return self[indexes_or_slice] @@ -763,7 +763,7 @@ def size(self): def typeCode(self): """type code""" - debug.log( + logger.debug( "Histogram %s: typecode = %s" % (self.getAttribute("name"), self._typeCode) ) return self._typeCode diff --git a/src/histogram/NdArrayDataset.py b/src/histogram/NdArrayDataset.py index b6e0218..44052d4 100644 --- a/src/histogram/NdArrayDataset.py +++ b/src/histogram/NdArrayDataset.py @@ -2,9 +2,9 @@ # Jiao Lin Copyright (c) 2006 All rights reserved from .DatasetBase import DatasetBase -import journal +import logging -debug = journal.debug("NdArrayDataset") +logger = logging.getLogger("Histogram") class Dataset(DatasetBase): @@ -34,8 +34,6 @@ def __init__( attributes = attributes or {} attributeCont = AttributeCont(dict(attributes)) - # debug.log("storage = %s" % str(storage)) - if shape == [] and storage is not None: shape = storage.shape() if shape != [] and storage is not None: @@ -48,8 +46,6 @@ def __init__( shape = list(shape) _checkShape(shape) - # debug.log("shape = %s" % (storage.shape(),)) - DatasetBase.__init__(self, name, unit, attributeCont, shape, storage) return @@ -442,7 +438,7 @@ def isDataset(ds): def isCompatibleDataset(a, b): if not isinstance(a, DatasetBase) or not isinstance(b, DatasetBase): - debug.log( + logger.debug( "either %s or %s is not a dataset" % ( a.__class__.__name__, @@ -452,7 +448,7 @@ def isCompatibleDataset(a, b): return False if a.shape() != b.shape(): - debug.log("incompatible shape: %s, %s" % (a.shape(), b.shape())) + logger.debug("incompatible shape: %s, %s" % (a.shape(), b.shape())) return False return True @@ -464,7 +460,7 @@ def isUnitCompatibleDataset(a, b): try: a.unit() + b.unit() except: - debug.log("incompatible units: %s, %s" % (a.unit(), b.unit())) + logger.debug("incompatible units: %s, %s" % (a.unit(), b.unit())) return False return True diff --git a/src/histogram/__init__.py b/src/histogram/__init__.py index 01a4768..ded595d 100644 --- a/src/histogram/__init__.py +++ b/src/histogram/__init__.py @@ -2,9 +2,6 @@ # # -__version__ = "0.3.9" - - ## \mainpage histogram ## ## \section reference_sec Public Interface @@ -68,6 +65,19 @@ ## Main funtions: ## - histogram ## - axis +from ._version import __version__ as __version__ +import logging + +# Create and configure logger +logging.basicConfig( + format="[%(asctime)s] [%(levelname)s] %(pathname)s:%(lineno)d %(message)s" +) + +# Create a logger +logger = logging.getLogger("Histogram") + +# Set the logging level +logger.setLevel(logging.INFO) # factories @@ -320,7 +330,7 @@ def datasetFromFunction(func, axes, *args, **kwds): except: import traceback - debug.log(traceback.format_exc()) + logger.debug(traceback.format_exc()) return applyFunction_slow(func, xs, *args, **kwds) raise "should not reach here" @@ -347,7 +357,7 @@ def applyFunction_fast(func, xs, *args, **kwds): """ mg = meshgrid(*xs) targs = mg + list(args) - debug.log("%s" % (targs,)) + logger.debug("%s" % (targs,)) return func(*targs, **kwds) @@ -482,12 +492,7 @@ def createContinuousAxis( try: axisMapper = AxisMapper(binBoundaries=boundaries) except NotEvenlySpaced: - import traceback - import journal - - debug = journal.debug("histogram.createContinuousAxis") - # debug.log( traceback.format_exc() ) - debug.log( + logger.debug( "createContinuousAxis(name = %r, unit = %r, centers= %r, boundaries = %r" % (name, unit, centers, boundaries) ) @@ -799,10 +804,6 @@ def _grid(arr, i, shape): return rt -import journal - -debug = journal.debug("histogram") - from ._units import unitFromString diff --git a/src/histogram/hdf/Renderer.py b/src/histogram/hdf/Renderer.py index e0123e4..e1aa7d9 100755 --- a/src/histogram/hdf/Renderer.py +++ b/src/histogram/hdf/Renderer.py @@ -11,10 +11,9 @@ # -import journal +import logging -jrnltag = "histogram.hdf.Renderer" -debug = journal.debug(jrnltag) +logger = logging.getLogger("Histogram") class Renderer(object): @@ -118,7 +117,7 @@ def _setAttrs(self, node, attributecontainer, skip_attrs=None): if __name__ == "__main__": - test() + exit() # version diff --git a/src/histogram/hdf/__init__.py b/src/histogram/hdf/__init__.py index f148061..2e1c905 100755 --- a/src/histogram/hdf/__init__.py +++ b/src/histogram/hdf/__init__.py @@ -19,6 +19,9 @@ import os +import logging + +logger = logging.getLogger("Histogram") def load(filename, pathinfile=None, fs=None, **kwds): @@ -54,9 +57,8 @@ def load(filename, pathinfile=None, fs=None, **kwds): else: # this is obsolete. in the future we should have # a dedicated "url" parameter - import warnings - warnings.warn("filename as url is deprecated") + logger.warning("filename as url is deprecated") url = filename filename, pathinfile = os.path.split(url) if not os.path.exists(filename): diff --git a/src/histogram/hpickle.py b/src/histogram/hpickle.py index 0a8e9b9..6588f67 100644 --- a/src/histogram/hpickle.py +++ b/src/histogram/hpickle.py @@ -11,6 +11,9 @@ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # +import logging + +logger = logging.getLogger("Histogram") use = "system pickle" @@ -31,11 +34,6 @@ def load(filename): pass -import journal - -warning = journal.warning("histogram.hpickle") - - # version __id__ = "$Id: __init__.py 799 2006-02-23 16:45:51Z linjiao $" diff --git a/src/histogram/ndarray/NumpyNdArray.py b/src/histogram/ndarray/NumpyNdArray.py index 26188d0..270009f 100644 --- a/src/histogram/ndarray/NumpyNdArray.py +++ b/src/histogram/ndarray/NumpyNdArray.py @@ -23,6 +23,9 @@ from .AbstractNdArray import NdArray as AbstractNdArray import numpy from functools import reduce +import logging + +logger = logging.getLogger("Histogram") types = { "char": 4, @@ -55,11 +58,6 @@ } ) -import journal - -info = journal.info("NumpyNdArray") -warning = journal.warning("NumpyNdArray") - def arrayFromNumpyArray(arr, datatype=None): "create a NumpyNdArray.NdArray instance from a numpy array" @@ -211,7 +209,7 @@ def integrate(self, start, end, dx): end: index one past the last (integer) dx: \"measure\" Output: - dx*\sum_{i in [start, end)} + dx*\\sum_{i in [start, end)} Exceptions: ValueError, IndexError Notes: end must be <= size of vector; start must be <= end.""" return numpy.sum(self._numarr[start:end]) * dx @@ -286,15 +284,17 @@ def compare(self, other, epsilon=0.000001): and are element-by-element equal to within epsilon. """ if not isinstance(other, AbstractNdArray): - info.log("%s is not a vector" % other) + logging.info("%s is not a vector" % other) return False if self.datatype() != other.datatype(): - info.log( + logging.info( "incompatible data type: %s, %s" % (self.datatype(), other.datatype()) ) return False if self.shape() != other.shape(): - info.log("incompatible array dhape: %s, %s" % (self.shape(), other.shape())) + logging.info( + "incompatible array dhape: %s, %s" % (self.shape(), other.shape()) + ) return False this = self._numarr other = other.asNumarray() @@ -437,7 +437,7 @@ def getAKTypecode(arr): try: return getNumericArray_aktypecode(arr) except: - warning.log("numpy datatype unknown for ndarray: %s" % arr.dtype.name) + logger.warning("numpy datatype unknown for ndarray: %s" % arr.dtype.name) return 10000 + arr.dtype.num raise "Should not reach here" @@ -496,8 +496,6 @@ def _sum(anumarr): # def main(): -# ## journal.debug('instrument').activate() -# ## journal.debug('instrument.elements').activate() # pytests = pysuite() # alltests = unittest.TestSuite((pytests,)) # unittest.TextTestRunner(verbosity=2).run(alltests) diff --git a/src/histogram/plotter.py b/src/histogram/plotter.py index 33cd296..d37863d 100644 --- a/src/histogram/plotter.py +++ b/src/histogram/plotter.py @@ -19,9 +19,9 @@ ## -import journal +import logging -warning = journal.warning("histogram.plotter") +logger = logging.getLogger("Histogram") class HistogramPlotter: @@ -36,7 +36,7 @@ def plot(self, hist, **kwds): if dim > 2: raise NotImplementedError("dim=%s" % (dim,)) - warning.log("NotImplementedError: dim = %s" % dim) + logger.warning("NotImplementedError: dim = %s" % dim) return plot = getattr(self, "plot%dd" % dim) plot(hist, **kwds) diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..af3678e --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,21 @@ +"""pytest config""" + +import pytest + +import logging + +# Create and configure logger +logging.basicConfig( + format="%(levelname)s Histogram %(pathname)s:%(lineno)d %(message)s" +) + +# Create a logger +logger = logging.getLogger("Histogram") + +# Set the logging level +logging_level = logging.DEBUG +logger.setLevel(logging.DEBUG) + +print("\n --------------------------------------------") +print(f" ------ Logger set to {logging.getLevelName(logging_level)} ------") +print(" --------------------------------------------\n") diff --git a/tests/histogram/Axis_TestCase.py b/tests/histogram/Axis_TestCase.py index f25e721..2734a64 100755 --- a/tests/histogram/Axis_TestCase.py +++ b/tests/histogram/Axis_TestCase.py @@ -13,7 +13,7 @@ # import histogramTest_Axis as oldtest -from histogramTest_Axis import log, target, aspects, utilities +from histogramTest_Axis import aspects from histogram import calcBinBoundaries, ndArray, axis diff --git a/tests/histogram/DatasetContainer_TestCase.py b/tests/histogram/DatasetContainer_TestCase.py index eae0e4f..643e0a5 100755 --- a/tests/histogram/DatasetContainer_TestCase.py +++ b/tests/histogram/DatasetContainer_TestCase.py @@ -87,9 +87,6 @@ def pysuite(): def main(): - # journal.debug('DatasetContainer').activate() - ## journal.debug('instrument').activate() - ## journal.debug('instrument.elements').activate() pytests = pysuite() alltests = unittest.TestSuite((pytests,)) unittest.TextTestRunner(verbosity=2).run(alltests) diff --git a/tests/histogram/NdArrayDataset_TestCase.py b/tests/histogram/NdArrayDataset_TestCase.py index 90cc5de..0e9d8ea 100755 --- a/tests/histogram/NdArrayDataset_TestCase.py +++ b/tests/histogram/NdArrayDataset_TestCase.py @@ -444,9 +444,6 @@ def pysuite(): def main(): - # journal.debug('NdArrayDataset').activate() - ## journal.debug('instrument').activate() - ## journal.debug('instrument.elements').activate() pytests = pysuite() alltests = unittest.TestSuite((pytests,)) unittest.TextTestRunner(verbosity=2).run(alltests) diff --git a/tests/histogram/SimpleHistCollection_TestCase.py b/tests/histogram/SimpleHistCollection_TestCase.py index 949cead..1406239 100644 --- a/tests/histogram/SimpleHistCollection_TestCase.py +++ b/tests/histogram/SimpleHistCollection_TestCase.py @@ -51,8 +51,6 @@ def pysuite(): def main(): - ## journal.debug('instrument').activate() - ## journal.debug('instrument.elements').activate() pytests = pysuite() alltests = unittest.TestSuite((pytests,)) unittest.TextTestRunner(verbosity=2).run(alltests) diff --git a/tests/histogram/all_tk_tests.py b/tests/histogram/all_tk_tests.py index 2f1f59d..74ff1f0 100755 --- a/tests/histogram/all_tk_tests.py +++ b/tests/histogram/all_tk_tests.py @@ -73,8 +73,6 @@ def createsuites(): def main(): - ## journal.debug('instrument').activate() - ## journal.debug('instrument.elements').activate() unittest.TextTestRunner(verbosity=2).run(alltests) return diff --git a/tests/histogram/histogramTest_Axis.py b/tests/histogram/histogramTest_Axis.py index e34d320..312dd84 100755 --- a/tests/histogram/histogramTest_Axis.py +++ b/tests/histogram/histogramTest_Axis.py @@ -1,6 +1,14 @@ #!/usr/bin/env python # Copyright (c) 2004 Timothy M. Kelley all rights reserved +import logging + +logger = logging.getLogger("Histogram") + + +from histogram import ndArray +import utilities + aspects = [ "instantiate/intialize", "binCenters()", @@ -9,8 +17,6 @@ ] -from histogram import ndArray - def test_0(**kwds): from histogram.Axis import Axis @@ -28,7 +34,7 @@ def test_0(**kwds): passed = True if axis._shape != [length + 1]: passed = False - log("shape was {0!s} instead of {1!s}".format(axis._shape, [length + 1])) + logger.info("shape was {0!s} instead of {1!s}".format(axis._shape, [length + 1])) # everything else tested in histogramTest_StdvectorDataset.py assert passed @@ -49,9 +55,9 @@ def test_1(**kwds): axis = Axis(name, unit, attributes, length, storage) expected = [i + 1.5 for i in range(23)] - passed = utilities.compareFPLists(expected, axis.binCenters(), 1e-15, log) + passed = utilities.compareFPLists(expected, axis.binCenters(), 1e-15) if not passed: - log( + logger.info( "binCenters(): expected {0!s}, got {1!s}".format( expected, axis.binCenters() ) @@ -76,7 +82,7 @@ def test_2(**kwds): passed = storage == axis.binBoundaries() if not passed: - log( + logger.info( "binBoundaries(): expected {0!s}, got {1!s}".format( storage, axis.binBoundaries() ) @@ -101,7 +107,7 @@ def test_3(**kwds): passed = storage.asList() == axis.binBoundariesAsList() if not passed: - log( + logger.info( "binBoundariesAsList(): expected {0!s}, got {1!s}".format( storage.asList(), axis.binBoundariesAsList() ) @@ -126,18 +132,7 @@ def run(**kwds): return allPassed -# import ARCSTest.utilities as utilities -import utilities - -target = "Axis" - -log = utilities.picklog(target) - if __name__ == "__main__": - import journal - - info = journal.info(target) - info.activate() run() diff --git a/tests/histogram/histogramTest_DatasetContainer.py b/tests/histogram/histogramTest_DatasetContainer.py index 1aaf286..308f388 100755 --- a/tests/histogram/histogramTest_DatasetContainer.py +++ b/tests/histogram/histogramTest_DatasetContainer.py @@ -1,5 +1,8 @@ #!/usr/bin/env python # Copyright (c) 2004 Timothy M. Kelley all rights reserved +import logging + +logger = logging.getLogger("Histogram") aspects = [ "instantiate/initialize", @@ -30,10 +33,16 @@ def test_1(**kwds): passed = True if dc._byNames[name] != ds: passed = False - log("didn't correctly add dataset to _byNames") + logger.debug("didn't correctly add dataset to _byNames") if dc._byIds[id] != [name, ds]: passed = False - log("didn't correctly add dataset to _byIds") + logger.debug("didn't correctly add dataset to _byIds") + try: + logger.info('Attempting to log something') + except Exception as e: + print(f"Logging failed with error: {e}") + print(" \n\n\n\n print't correctly add dataset to _byIds") + assert passed @@ -51,7 +60,7 @@ def test_2(**kwds): if dsbn != ds: passed = False - log("datasetFromName returned {0!s} instead of {1!s}".format(dsbn, ds)) + logger.debug("datasetFromName returned {0!s} instead of {1!s}".format(dsbn, ds)) assert passed @@ -69,7 +78,7 @@ def test_3(**kwds): if dsbi != ds: passed = False - log("datasetFromId returned {0!s} instead of {1!s}".format(dsbi, ds)) + logger.debug("datasetFromId returned {0!s} instead of {1!s}".format(dsbi, ds)) assert passed @@ -87,7 +96,7 @@ def test_4(**kwds): if dslist != [(id, name)]: passed = False - log("listDatasets returned {0!s} instead of {1!s}".format(dslist, [(id, name)])) + logger.debug("listDatasets returned {0!s} instead of {1!s}".format(dslist, [(id, name)])) assert passed @@ -99,24 +108,12 @@ def run(**kwds): for i, aspect in enumerate(aspects): run = eval('test_' + str(i)) - # utilities.preReport(log, target, aspect) passed = run(**kwds) - # utilities.postReport(log, target, aspect, passed) allPassed = allPassed and passed return allPassed -import utilities - -target = "DatasetContainer" - -log = utilities.picklog(target) - if __name__ == "__main__": - import journal - - info = journal.info(target) - info.activate() run() diff --git a/tests/histogram/histogramTest_DictAttCont.py b/tests/histogram/histogramTest_DictAttCont.py index a9f8e68..56086b6 100755 --- a/tests/histogram/histogramTest_DictAttCont.py +++ b/tests/histogram/histogramTest_DictAttCont.py @@ -1,5 +1,8 @@ #!/usr/bin/env python # Copyright (c) 2004 Timothy M. Kelley all rights reserved +import logging + +logger = logging.getLogger("Histogram") aspects = [ "instantiate/initialize", @@ -29,10 +32,10 @@ def test_1(**kwds): name = attDict["name"] if name != "timmah!": passed = False - log("value of 'name' attribute ({0!s}) was incorrect".format(name)) + logger.info("value of 'name' attribute ({0!s}) was incorrect".format(name)) except KeyError: passed = False - log("did not store 'name' as a key") + logger.info("did not store 'name' as a key") assert passed @@ -48,7 +51,7 @@ def test_2(**kwds): name = attCont.getAttribute("name") if name != "timmah!": passed = False - log("value of 'name' attribute ({0!s}) was incorrect".format(name)) + logger.info("value of 'name' attribute ({0!s}) was incorrect".format(name)) assert passed @@ -66,7 +69,7 @@ def test_3(**kwds): acList = attCont.listAttributes() if acList != attList: passed = False - log("listAtts() returned {0!s}, should have been {1!s}".format(acList, attList)) + logger.info("listAtts() returned {0!s}, should have been {1!s}".format(acList, attList)) assert passed @@ -87,17 +90,8 @@ def run(**kwds): return allPassed -import utilities - -target = "DictAttCont" - -log = utilities.picklog(target) if __name__ == "__main__": - import journal - - info = journal.info(target) - info.activate() run() diff --git a/tests/histogram/histogramTest_Histogram.py b/tests/histogram/histogramTest_Histogram.py index 978ad82..7b981ad 100755 --- a/tests/histogram/histogramTest_Histogram.py +++ b/tests/histogram/histogramTest_Histogram.py @@ -1,5 +1,8 @@ #!/usr/bin/env python # Copyright (c) 2004 Timothy M. Kelley all rights reserved +import logging + +logger = logging.getLogger("Histogram") aspects = [ "instantiate/initialize", @@ -86,7 +89,7 @@ def test_1(**kwds): hax1 = hist.axisFromId(1) if hax1 is not ax1: passed = False - log("hax1 was %s instead of %s" % (hax1, ax1)) + logger.info("hax1 was %s instead of %s" % (hax1, ax1)) assert passed @@ -127,7 +130,7 @@ def test_2(**kwds): hax1 = hist.axisFromName("testax1") if hax1 is not ax1: passed = False - log("hax1 was %s instead of %s" % (hax1, ax1)) + logger.info("hax1 was %s instead of %s" % (hax1, ax1)) assert passed @@ -168,7 +171,7 @@ def test_3(**kwds): hdata = hist.data() if hdata is not data: passed = False - log("hdata was %s instead of %s" % (hdata, data)) + logger.info("hdata was %s instead of %s" % (hdata, data)) assert passed @@ -209,7 +212,7 @@ def test_4(**kwds): herror = hist.errors() if herror is not error: passed = False - log("herror was %s instead of %s" % (herror, error)) + logger.info("herror was %s instead of %s" % (herror, error)) assert passed @@ -230,16 +233,6 @@ def run( **kwds): if __name__ == '__main__': - # import ARCSTest.utilities as utilities - import utilities as utilities - - target = "Histogram" - - log = utilities.picklog(target) - import journal - - info = journal.info(target) - info.activate() run() diff --git a/tests/histogram/ndarray/NdArray_TestCase.py b/tests/histogram/ndarray/NdArray_TestCase.py index 1c635f4..828333e 100755 --- a/tests/histogram/ndarray/NdArray_TestCase.py +++ b/tests/histogram/ndarray/NdArray_TestCase.py @@ -373,7 +373,6 @@ def pysuite(): # def main(): -# ## journal.debug('instrument').activate() # pytests = pysuite() # alltests = unittest.TestSuite((pytests,)) # unittest.TextTestRunner(verbosity=2).run(alltests) diff --git a/tests/histogram/plotter_TestCase.py b/tests/histogram/plotter_TestCase.py index 394902f..1b8470d 100755 --- a/tests/histogram/plotter_TestCase.py +++ b/tests/histogram/plotter_TestCase.py @@ -173,8 +173,6 @@ def main(): global interactive interactive = True - ## journal.debug('instrument').activate() - ## journal.debug('instrument.elements').activate() pytests = pysuite() alltests = unittest.TestSuite((pytests,)) unittest.TextTestRunner(verbosity=2).run(alltests) diff --git a/tests/histogram/utilities.py b/tests/histogram/utilities.py index 9391b5f..39fe9ab 100644 --- a/tests/histogram/utilities.py +++ b/tests/histogram/utilities.py @@ -1,19 +1,18 @@ -def picklog(target): - import journal +import logging - return journal.info(target).log +logger = logging.getLogger("Histogram") -def compareFPLists(a, b, tol, log): +def compareFPLists(a, b, tol): if len(a) != len(b): - log("array size is different: {0!s} != {1!s}".format(len(a), len(b))) + logger.info("array size is different: {0!s} != {1!s}".format(len(a), len(b))) return False ret = True for a1, b1 in zip(a, b): if abs(a1 - b1) > tol: - log("{0!s}!={1!s}".format(a1, b1)) + logger.info("{0!s}!={1!s}".format(a1, b1)) ret = False continue