Skip to content

Commit

Permalink
Merge pull request #216 from quantopian/record-order-recursion
Browse files Browse the repository at this point in the history
Record order recursion
  • Loading branch information
llllllllll committed May 19, 2016
2 parents 2bdf3ea + 2334e88 commit bf06a41
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
3 changes: 2 additions & 1 deletion datashape/util/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def assert_dshape_equal(a, b, check_record_order=True, path=None, **kwargs):

assert len(afields) == len(bfields), \
'records have mismatched field counts: %d != %d\n%r != %r\n%s' % (
len(afields), len(bfields), a, b, _fmt_path(path),
len(afields), len(bfields), a.names, b.names, _fmt_path(path),
)

if not check_record_order:
Expand All @@ -216,6 +216,7 @@ def assert_dshape_equal(a, b, check_record_order=True, path=None, **kwargs):
afield,
bfield,
path=path + ('[%s]' % repr(aname),),
check_record_order=check_record_order,
**kwargs
)

Expand Down
42 changes: 29 additions & 13 deletions datashape/util/tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from datashape.coretypes import (
DateTime,
Record,
R,
String,
Time,
TimeDelta,
Expand Down Expand Up @@ -68,38 +68,54 @@ def test_dim():

def test_record():
assert_dshape_equal(
Record((('a', int32), ('b', float32))),
Record((('a', int32), ('b', float32))),
R['a': int32, 'b': float32],
R['a': int32, 'b': float32],
)

with pytest.raises(AssertionError) as e:
assert_dshape_equal(
Record((('a', int32), ('b', float32))),
Record((('a', int32), ('b', int32))),
R['a': int32, 'b': float32],
R['a': int32, 'b': int32],
)
assert "'float32' != 'int32'" in str(e)
assert "_['b'].name" in str(e.value)

with pytest.raises(AssertionError) as e:
assert_dshape_equal(
Record((('a', int32), ('b', float32))),
Record((('a', int32), ('c', float32))),
R['a': int32, 'b': float32],
R['a': int32, 'c': float32],
)
assert "'b' != 'c'" in str(e.value)

with pytest.raises(AssertionError) as e:
assert_dshape_equal(
R['b': float32, 'a': float32],
R['a': int32, 'b': float32],
check_record_order=False,
)
assert "'float32' != 'int32'" in str(e.value)
assert "_['a']" in str(e.value)

assert_dshape_equal(
Record((('b', float32), ('a', int32))),
Record((('a', int32), ('b', float32))),
R['b': float32, 'a': int32],
R['a': int32, 'b': float32],
check_record_order=False,
)

# check a nested record with and without ordering
assert_dshape_equal(
R['a': R['b': float32, 'a': int32]],
R['a': R['a': int32, 'b': float32]],
check_record_order=False,
)

with pytest.raises(AssertionError) as e:
assert_dshape_equal(
Record((('b', float32), ('a', float32))),
Record((('a', int32), ('b', float32))),
check_record_order=False,
R['a': R['a': int32, 'b': float32]],
R['a': R['b': float32, 'a': int32]],
)
assert "'float32' != 'int32'" in str(e.value)

assert "'a' != 'b'" in str(e.value)
assert "_['a']" in str(e.value)


Expand Down

0 comments on commit bf06a41

Please sign in to comment.