Create a larry specific assert function to simplify unit testing
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_
Make unit tests for the new larry comparison function.
Here's an example pieced together from the larry-discuss mailing list:
def assert_
#assert equality of attributes of two larries
fail = []
# label
try:
except AssertionError, err:
# Data array
try:
except AssertionError, err:
# dtype
if dtype:
try:
except AssertionError, err:
# Check for references or copies
if noreference:
if original is None:
raise ValueError, 'original must be a larry to run noreference check.'
try:
except AssertionError, err:
elif nocopy:
if original is None:
raise ValueError, 'original must be a larry to run nocopy check.'
try:
except AssertionError, 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
Whiteboard
assert_larry
http://
and the method check_function in test class
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