Beispiel #1
0
def assert_eq(var1, var2, msg='', var1_name=None, var2_name=None, verbose=not util_arg.QUIET):
    import utool as ut
    failed = var1 != var2
    if var1_name is None:
        var1_name = ut.get_varname_from_stack(var1, N=1, default='var1')
    if var2_name is None:
        var2_name = ut.get_varname_from_stack(var2, N=1, default='var2')
    fmtdict = dict(
        msg=msg,
        var1_name=var1_name,
        var2_name=var2_name,
        var1_repr=repr(var1),
        var2_repr=repr(var2))
    if failed:
        msg_fmtstr = ut.codeblock('''
            +=====
            ERROR {var1_name} != {var2_name}
            msg = {msg}
            ---
            {var1_name} = {var1_repr}
            ---
            {var2_name} = {var2_repr}
            L_____
            ''')
        msg = msg_fmtstr.format(**fmtdict)
        raise AssertionError(msg)
    else:
        print('ASSERT_EQ_PASSED: {var1_name} == {var2_name} == {var1_repr}'.format(**fmtdict))
Beispiel #2
0
def assert_eq(var1,
              var2,
              msg='',
              var1_name=None,
              var2_name=None,
              verbose=not util_arg.QUIET):
    import utool as ut
    failed = var1 != var2
    if var1_name is None:
        var1_name = ut.get_varname_from_stack(var1, N=1, default='var1')
    if var2_name is None:
        var2_name = ut.get_varname_from_stack(var2, N=1, default='var2')
    fmtdict = dict(msg=msg,
                   var1_name=var1_name,
                   var2_name=var2_name,
                   var1_repr=repr(var1),
                   var2_repr=repr(var2))
    if failed:
        msg_fmtstr = ut.codeblock('''
            +=====
            ERROR {var1_name} != {var2_name}
            msg = {msg}
            ---
            {var1_name} = {var1_repr}
            ---
            {var2_name} = {var2_repr}
            L_____
            ''')
        msg = msg_fmtstr.format(**fmtdict)
        raise AssertionError(msg)
    else:
        print('ASSERT_EQ_PASSED: {var1_name} == {var2_name} == {var1_repr}'.
              format(**fmtdict))
Beispiel #3
0
def evalprint(str_, globals_=None, locals_=None, simplify=False):
    if globals_ is None:
        globals_ = ut.get_parent_globals()
    if locals_ is None:
        locals_ = ut.get_parent_locals()
    if isinstance(str_, six.string_types):
        var = eval(str_, globals_, locals_)
    else:
        var = str_
        str_ = ut.get_varname_from_stack(var, N=1)
    if simplify is True:
        var = sympy.simplify(var)
    print(ut.hz_str(str_ + " = ", repr(var)))
Beispiel #4
0
def evalprint(str_, globals_=None, locals_=None, simplify=False):
    if globals_ is None:
        globals_ = ut.get_parent_globals()
    if locals_ is None:
        locals_ = ut.get_parent_locals()
    if isinstance(str_, six.string_types):
        var = eval(str_, globals_, locals_)
    else:
        var = str_
        str_ = ut.get_varname_from_stack(var, N=1)
    if simplify is True:
        var = sympy.simplify(var)
    print(ut.hz_str(str_ + ' = ', repr(var)))
Beispiel #5
0
def print_list(list_, **kwargs):
    import utool as ut
    list_name = ut.get_varname_from_stack(list_, N=1)
    print(list_name + ' = ' + util_str.list_str(list_, **kwargs))
Beispiel #6
0
def print_dict(dict_, dict_name=None, **kwargs):
    import utool as ut
    if dict_name is None:
        dict_name = ut.get_varname_from_stack(dict_, N=1)
    dict_repr = util_str.dict_str(dict_, **kwargs)
    print(dict_name + ' = ' + dict_repr)
Beispiel #7
0
def print_list(list_, **kwargs):
    import utool as ut
    list_name = ut.get_varname_from_stack(list_, N=1)
    print(list_name + ' = ' + util_str.repr4(list_, **kwargs))
Beispiel #8
0
def print_dict(dict_, dict_name=None, **kwargs):
    import utool as ut
    if dict_name is None:
        dict_name = ut.get_varname_from_stack(dict_, N=1)
    dict_repr = util_str.repr4(dict_, **kwargs)
    print(dict_name + ' = ' + dict_repr)
Beispiel #9
0
def print_list(list_):
    import utool as ut
    list_name = ut.get_varname_from_stack(list_, N=1)
    print(list_name + ' = ' + util_str.list_str(list_))