Create a larry specific assert function to simplify unit testing

Registered by kwgoodman

Create a new function in tests/test.py for comparing two larrys for equal and almost equal. Use numpy.testing functions to compare the x part of the larry and write a function to compare the labels. Set noreference (see tests/test.py) to True by default. Nocopy (see tests/test.py) is also an option. Add an optional dtype comparison.

For examples of why this new function is needed look at all the repeated assert code in tests/deflarry_test.py. Also current assert code does not give useful debug output when the two larry compared are of difference shape.

Make unit tests for the new larry comparison function.

Here's an example pieced together from the larry-discuss mailing list:

def assert_larry_equal(actual, desired, msg='', dtype=True, original=None,
                       noreference=True, nocopy=False, verbose=True):
    #assert equality of attributes of two larries

    fail = []

    # label
    try:
        assert_equal(actual.label, desired.label)
    except AssertionError, err:
        fail.append('\n\nLABEL\n-----\n' + str(err))

    # Data array
    try:
        assert_equal(actual.x, desired.x)
    except AssertionError, err:
        fail.append('\n\nX DATA ARRAY\n------------\n' + str(err))

    # dtype
    if dtype:
        try:
            assert_equal(actual.x.dtype, desired.x.dtype)
        except AssertionError, err:
            fail.append('\n\nDTYPE\n-----\n' + str(err))

    # Check for references or copies
    if noreference:
        if original is None:
            raise ValueError, 'original must be a larry to run noreference check.'
        try:
            assert_(assert_noreference(actual, original))
        except AssertionError, err:
            fail.append('\n\nREFERENCE FOUND\n---------------\n' + str(err))
    elif nocopy:
        if original is None:
            raise ValueError, 'original must be a larry to run nocopy check.'
        try:
            assert_(assert_nocopy(actual, original))
        except AssertionError, err:
            fail.append('\n\nCOPY INSTEAD OF REFERENCE FOUND\n-------------------------------\n' + str(err))
    else: #FIXME check view for different dimensional larries
        pass

    # Did the test pass?
    if len(fail) > 0:
        # No
        msg = ''.join(fail)
        raise AssertionError, msg

Blueprint information

Status:
Complete
Approver:
None
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
New
Series goal:
None
Implementation:
Implemented
Milestone target:
milestone icon 0.2
Started by
kwgoodman
Completed by
kwgoodman

Related branches

Sprints

Whiteboard

assert_larry
http://bazaar.launchpad.net/~kwgoodman/larry/trunk/annotate/head%3A/la/tests/deflarry_nose_test.py#L49

and the method check_function in test class

http://bazaar.launchpad.net/~kwgoodman/larry/trunk/annotate/head%3A/la/tests/deflarry_nose_test.py#L128

already contain the extracted boiler plate assert function to compare a larry with desired data matrix x and labels

the later has a view keyword to choose whether to verify nocopy or noreference

used in nosetests for larry methods

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.