Add some more validation checks for process flows#323
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #323 +/- ##
==========================================
+ Coverage 95.29% 95.56% +0.27%
==========================================
Files 26 26
Lines 2613 2751 +138
Branches 2613 2751 +138
==========================================
+ Hits 2490 2629 +139
Misses 47 47
+ Partials 76 75 -1 ☔ View full report in Codecov by Sentry. |
Closes #278.
3cde296 to
2244093
Compare
| .with_context(|| format!("No commodity flows defined for process {id}"))?; | ||
| let pacs = pacs | ||
| .remove(&id) | ||
| .with_context(|| format!("No PACs defined for process {id}"))?; |
There was a problem hiding this comment.
Should we add tests for these two cases?
There was a problem hiding this comment.
Yes, probably. I was being a bit lazy here.
There was a problem hiding this comment.
In order to write tests, I split out the map creation stuff into its own function. I also figured that this function is the right place to check for other missing process data (e.g. flows, availabilities). I had been checking for this by just checking that the data structures had the same length as the process_ids one, but by doing the check when we actually need the data for a given process, we can tell the user which process is missing this data, so I think that's an improvement.
| I: Iterator<Item = ProcessFlowRaw>, | ||
| { | ||
| iter.map(|flow_raw| -> Result<ProcessFlow> { | ||
| iter.map(|flow| -> Result<ProcessFlow> { |
There was a problem hiding this comment.
Why the name change here? As far as I can tell, it is still a ProcessFlowRaw that is being iterated over.
There was a problem hiding this comment.
I thought it was more readable that way... Maybe not though
src/input/process/flow.rs
Outdated
| // Check that flow is not zero, infinity, etc. | ||
| ensure!( | ||
| flow.flow.is_normal(), | ||
| "Invalid value for flow: {}", |
There was a problem hiding this comment.
Maybe explain the restriction on the value in this message?
There was a problem hiding this comment.
I've made a separate check for zero values instead, because I think that's the one that's likely to trip users up. If they put nan as a value for flow, we probably don't need to explain why that's not allowed!
Description
I've added some extra validation steps related to process flows, namely:
I also added a check that every process has at least one PAC.
Closes #277. Closes #278. Closes #279.
Type of change
Key checklist
$ cargo test$ cargo docFurther checks