Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Degree Day unit tests #160

Merged
merged 2 commits into from
Dec 16, 2016
Merged

Degree Day unit tests #160

merged 2 commits into from
Dec 16, 2016

Conversation

rmartz
Copy link
Contributor

@rmartz rmartz commented Dec 15, 2016

Overview

The Degree Day PR (#154) neglected to include unit tests for the new indicators. This corrects this and fixes a number of issues encountered:

  • Changing the parameter dictionary caused unittests to be unrepeatable
  • Calculated values were being truncated to integer
  • Negative basetemps were considered invalid
  • Basetemps with illegal unit suffixes were considered valid

Testing Instructions

  • Ensure that unit tests pass
  • (Optional) Break something. Ensure that unit tests fail

Also fixes a number of undetected issues:
- Negative basetemp
- Basetemp with invalid suffix unit
- Values truncated to integer
Copy link
Contributor

@CloudNiner CloudNiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks for jumping on this quick.

m = re.match(r'^(?P<value>-?\d+(\.\d+)?)(?P<unit>[%s])?$' % ''.join(self.available_units),
self.parameters['basetemp'])
if not m:
raise ValueError('Parameter basetemp must be numeric and end with C, F or K')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should update error string to reference self.available_units

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm for that, left it like this to make it read nicer. Which do you think is a better way to go?

  • Do a simple join so the list reads kind of funny ("...and end with one of [C, F, K]")
  • Write a slightly more complex function to do two joins so we use proper English conjunctions ("...and end with C, F or K")?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other places, and particularly in the params PR, I've kept it simple and just let python format complex objects like lists/sets via format() or str(). Not that much worse IMO and a lot less effort. And since its an API it would likely be mostly tech savvy people reading these messages.

def __init__(self, *args, **kwargs):
super(BasetempIndicatorMixin, self).__init__(*args, **kwargs)

m = re.match(r'^(?P<value>-?\d+(\.\d+)?)(?P<unit>[%s])?$' % ''.join(self.available_units),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you're using self.available_units here, and that can be things other than temp units, it might be good to also throw an exception if self.variables contains anything other than tasmin or tasmax.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, I may need to change this to be TemperatureConverter.units specifically, since there could possibly be a case where a non-temperature indicator has a temperature input (Say, "Yearly Snowfall" that gives total precipitation on days with tasmin or tasmax below a given threshold).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems even better.

The BasetempIndicatorMixin previously assumed that self.available_units
would match the TemperatureConverter's units, but it isn't necessarily
true that an indicator that accepts a basetemp parameter is a
temperature parameter... for instance, a precipitation indicator may use
temperature to filter which days to inspect.
@rmartz rmartz merged commit 73ec883 into develop Dec 16, 2016
@rmartz rmartz deleted the feature/degree-day-unit-tests branch December 16, 2016 18:24
ddohler pushed a commit that referenced this pull request Aug 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants