예제 #1
0
파일: test_py.py 프로젝트: mbodenhamer/syn
def test_ngzwarn():
    from syn.base_utils import ngzwarn, this_module
    import syn.base_utils.py as sp

    mod = this_module()

    msgs = []
    class FakeLogger(object):
        def warning(self, msg):
            msgs.append(msg)

    logger = FakeLogger()
    with assign(sp, 'test_logger', logger):
        ngzwarn(1, 'FOO')
        assert msgs == []

        ngzwarn(0, 'Test value 1')
        assert msgs[-1] == ('Test value 1 set to value <= 0 (0) in {}'
                            .format(mod.__name__))

        ngzwarn(-1, 'Test value 2')
        assert msgs[-1] == ('Test value 2 set to value <= 0 (-1) in {}'
                            .format(mod.__name__))
예제 #2
0
def test_ngzwarn():
    from syn.base_utils import ngzwarn, this_module
    import syn.base_utils.py as sp

    mod = this_module()

    msgs = []

    class FakeLogger(object):
        def warning(self, msg):
            msgs.append(msg)

    logger = FakeLogger()
    with assign(sp, 'test_logger', logger):
        ngzwarn(1, 'FOO')
        assert msgs == []

        ngzwarn(0, 'Test value 1')
        assert msgs[-1] == ('Test value 1 set to value <= 0 (0) in {}'.format(
            mod.__name__))

        ngzwarn(-1, 'Test value 2')
        assert msgs[-1] == ('Test value 2 set to value <= 0 (-1) in {}'.format(
            mod.__name__))
예제 #3
0
from six import PY2
from syn.five import xrange
from syn.types.a import Type, Numeric, Int, hashable, rstr, serialize, \
    deserialize, estr, generate, TYPE_REGISTRY, Long, visit, find_ne, \
    NotEqual, primitive_form
from syn.types.a import enumerate as enumerate_
from syn.base_utils import is_hashable, collection_comp, assert_equivalent, \
    feq, cfeq, assert_type_equivalent, on_error, elog, ngzwarn, subclasses, \
    is_unique

from syn.globals import TEST_SAMPLES as SAMPLES
SAMPLES //= 10
SAMPLES = max(SAMPLES, 1)
ngzwarn(SAMPLES, 'SAMPLES')

#-------------------------------------------------------------------------------

def examine_numeric(cls, val):
    assert type(val) is cls.type
    assert is_hashable(hashable(val))
    assert deserialize(serialize(val)) == val
    assert deserialize(serialize(cls.type)) is cls.type
    assert isinstance(rstr(val), str)
    assert primitive_form(val) == val

    assert list(visit(val)) == [val]
    assert find_ne(val, val) is None

    eitem = eval(estr(val))
    assert cfeq(eitem, val, relative=True)
    assert type(eitem) is cls.type
예제 #4
0
from nose.tools import assert_raises
from syn.five import xrange, PY2, PY3

from syn.base_utils.rand import MIN_FLOAT, PRIMITIVE_TYPES
from syn.base_utils import is_hashable, ngzwarn, on_error, elog

from syn.globals import TEST_SAMPLES as SAMPLES
SAMPLESII = SAMPLES // 2
SAMPLESIII = SAMPLES // 5

SAMPLES = max(SAMPLES, 1)
SAMPLESII = max(SAMPLESII, 1)
SAMPLESIII = max(SAMPLESIII, 1)
ngzwarn(SAMPLES, 'SAMPLES')
ngzwarn(SAMPLES, 'SAMPLESII')
ngzwarn(SAMPLES, 'SAMPLESIII')

#-------------------------------------------------------------------------------
# Numeric

def test_rand_bool():
    from syn.base_utils import rand_bool

    bools = [rand_bool() for k in xrange(SAMPLESIII)]
    assert all(isinstance(s, bool) for s in bools)

def test_randint():
    from syn.base_utils import rand_int

    ints = [rand_int() for k in xrange(SAMPLESII)]
    assert all(isinstance(i, int) for i in ints)