test coverage: datamodel
At 79%. Mostly missing some testing of exceptional cases and of toCDF (and some of the other to/from).
Stuff to hit:
- toCDF
- exceptional handling in toHDF5
- fromNC3 completely untested
- readJSONheadedASCII missing some cases.
I was poking at this issue a bit. A few questions.
Anyone know how to hit this code? I have not been able to. https://github.com/spacepy/spacepy/blob/6e46d699942dfba93ff63047e4726882cfacb3f5/spacepy/datamodel.py#L449-L452
dm.dmfilled(3, 'bac') is a ValueError, not sure how to get type error.
Best way to improve test coverage is to remove code.
I think that special cases for when you pass None as the fill value.
I think that special cases for when you pass None as the fill value.
Tested, nope.
related: createISTPattrs needs some help, will do that one now.
_maketup looks to be a sort of broadcast-a-value-across-a-structured-record sort of function.
I suspect in earlier versions of numpy this didn't work:
dt = [('foo', 'f4'), ('bar', 'i2')]
a = numpy.empty((5,), dt)
a.fill(5)
Or it might be with a dtype like:
dt = [('foo', '5f4')]
Here's the source:
def _maketup(descr, val):
dt = dtype(descr)
# Place val in all scalar tuples:
fields = dt.fields
if fields is None:
return val
else:
res = [_maketup(fields[name][0], val) for name in dt.names]
return tuple(res)
Have you tried running coverage on test_all.py to see if this is hit anywhere in our test suite, even if not in datamodel? If it's not hit, and we can confirm that works on numpy 1.10, then I'd be all for pulling out that special case as probably not ever hit. (With probably adding tests like the above for having a structured dmarray, just to make sure it isn't different on subclasses!)
Doing dumb stuff with inputs will definitely hit that code...
E.g.,
dm.dmfilled((2,2), fillval=None, dtype=int)
will raise a TypeError on calling the fill method, fall through, but then fail.
It probably should fail, so I don't think we need to test unless we want to keep track of the fact that it should raise an exception when handed exceptionally stupid inputs..
But yes, it isn't handled by the _maketup call. I have no reason to doubt @jtniehof on this one, so sure, let's go with probably legacy recarray support.
Sounds good I will add a recarray test as suggested. Not sure if I can compile numpy 1.10 but will try...
Take a look at developer/scripts/test_all.sh . I haven't had any problem with installing numpy 1.10 (via pip) in a recent miniconda environment.
Verified, code not hit in test_all.py and recarray test included. Tested both on new and 1.10 numpy