blaze / datashape

Language defining a data description protocol
BSD 2-Clause "Simplified" License
183 stars 65 forks source link

DEV: adds datashape.util.testing.assert_dshape_equal #179

Closed llllllllll closed 8 years ago

llllllllll commented 8 years ago

I find that when writing tests with datashape I have a hard time figuring out which part of the dshape is not equal which leads to a slower debug process. This adds an assert_dshape_equal function which aims to provide much better errors. One of the nice pieces path: %s part of the message that shows you the exact path to the parts that are not equal, here are some examples:

In [2]: assert_dshape_equal(dshape('var * int32'), dshape('var * float64'))
AssertionError: ctype names do not match: 'int32' != 'float64'
path: _.measure.name

In [3]: assert_dshape_equal(dshape('2 * int32'), dshape('var * int32'))
AssertionError: dimensions do not match: 2 != var
path: _.shape[0]

In [4]: assert_dshape_equal(dshape('var * 2 * int32'), dshape('var * 3 * int32'))
AssertionError: dimensions do not match: 2 != 3
var * 2 != var * 3
path: _.shape[1]

In [6]: assert_dshape_equal(dshape('var * {a: 3 * {b: int32}}'), dshape('var * {a: 3 * {b: float32}}')) 
AssertionError: ctype names do not match: 'int32' != 'float32'
path: _.measure['a'].measure['b'].name

I do not want to refactor the current tests to use this because I don't want to break anything (there are no tests for the tests); however, it would be nice to use something like this going forward.