Page MenuHomec4science

basic_routines.py
No OneTemporary

File Metadata

Created
Fri, May 10, 17:14

basic_routines.py

# Copyright (C) 2018 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
import pytest
import numpy as np
from rrompy.utilities.exception_manager import RROMPyException, RROMPyWarning
from rrompy.utilities.base import (findDictStrKey, purgeDict, purgeList,
lowDiscrepancy, verbosityDepth)
def test_exception():
with pytest.raises(Exception):
raise RROMPyException("This is an exception!")
def test_warning(capsys):
RROMPyWarning("This is a warning.")
out, err = capsys.readouterr()
assert "This is a warning." in out
assert len(err) == 0
def test_dict_list():
dictBase = {str(x): str(x**2) for x in range(10)}
assert findDictStrKey("-1", dictBase.keys()) is None
assert findDictStrKey("5", dictBase.keys()) == "5"
dictPurged = purgeDict(dictBase, [str(x) for x in range(4)], silent = True)
assert len(dictPurged.keys()) == 4
listBase = list(dictBase.values())
listPurged = purgeList(listBase, [str(x**2) for x in range(4,6)],
silent = True)
assert len(listPurged) == 2
def test_vandercorput():
idxs = lowDiscrepancy(8)
assert np.all(idxs == np.array([0,4,2,6,1,5,3,7]))
def test_verbositydepth(capsys):
verbosityDepth("INIT", "Start message", timestamp = False)
out, err = capsys.readouterr()
assert out == "┌Start message\n"
assert len(err) == 0
verbosityDepth("MAIN", "Main message", end = "\n\n", timestamp = False)
out, err = capsys.readouterr()
assert out == "├Main message\n\n"
assert len(err) == 0
verbosityDepth("INIT", "Start message2")
verbosityDepth("DEL", "Delete message2")
verbosityDepth("DEL", "Delete message")
with pytest.raises(Exception):
verbosityDepth("DEL", "Wrong deletion")

Event Timeline