Skip to content

Commit

Permalink
improve test helper ieq() for testing None
Browse files Browse the repository at this point in the history
  • Loading branch information
juarezr committed Oct 6, 2020
1 parent 52447c0 commit e501fe9
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions petl/test/helpers.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,47 @@
from __future__ import absolute_import, print_function, division

import sys

from petl.compat import izip_longest
from nose.tools import eq_, assert_almost_equal

from petl.compat import izip_longest


def ieq(expect, actual, cast=None):
'''test when values are equals for eacfh row and column'''
ie = iter(expect)
ia = iter(actual)
for e, a in izip_longest(ie, ia, fillvalue=None):
for re, ra in izip_longest(ie, ia, fillvalue=None):
if cast:
a = cast(a)
eq_(e, a)


ra = cast(ra)
if re is None and ra is None:
continue
if type(re) in (int, float, bool, str):
eq_(re, ra)
continue
for ve, va in izip_longest(re, ra, fillvalue=None):
if isinstance(ve, list):
for je, ja in izip_longest(ve, va, fillvalue=None):
_eq_print(je, ja, re, ra)
elif not isinstance(ve, dict):
_eq_print(ve, va, re, ra)


def _eq_print(ve, va, re, ra):
try:
eq_(ve, va)
except AssertionError as ea:
print('\nrow: ', re, ' != ', ra, file=sys.stderr)
print('val: ', ve, ' != ', va, file=sys.stderr)
raise ea


def ieq2(expect, actual, cast=None):
'''test twice when values are equals for eacfh row and column'''
ieq(expect, actual, cast)
ieq(expect, actual, cast)


def test_iassertequal():
x = ['a', 'b']
y = ['a', 'b', 'c']
Expand Down

0 comments on commit e501fe9

Please sign in to comment.