azavea / climate-change-api

Apache License 2.0
0 stars 0 forks source link

Refactor Indicator tests to assert data dicts almost equal #647

Open CloudNiner opened 7 years ago

CloudNiner commented 7 years ago

The ArrayIndicator change required extensive changes to some indicators which rely on float operations which subtly change the exact value of the response. It would be nice to have something like an assertDictAlmostEqual method which allows us to compare the Indicator response with its approximate correct value such that we don't have to tweak these data dicts all of the time.

See https://github.com/azavea/climate-change-api/pull/639#discussion_r135610986 for additional discussion.

This could potentially be done as part of #627 or as a separate minor improvement.

rmartz commented 7 years ago

With #627 it might not be necessary for the indicator tests to deal with dict equality at all, since the dicts are from using IndicatorSerializer on the output of ArrayIndicator.collate_results(), which falls squarely in #627. I think we should be fine writing tests directly for Indicator.agg_function() of Indicator.aggregate() (Given the triviality of ArrayIndicator.aggregate(), we might also be safe just merging the two), which should alleviate a lot of the boilerplate we currently need.

Rewriting the tests to focus on the indicator specific logic will take a lot of doing, but long term I think it'll allow us to have much more effective test coverage.