Skip to content

Commit

Permalink
pyo3-build-config: improve test coverage
Browse files Browse the repository at this point in the history
[review] birkenfeld

Co-authored-by: Georg Brandl <[email protected]>
  • Loading branch information
davidhewitt and birkenfeld committed Aug 6, 2021
1 parent 49387e9 commit 2cf2c2f
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 31 deletions.
2 changes: 1 addition & 1 deletion guide/src/building_and_distribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Caused by:
build_flags=WITH_THREAD
```

> Note: if you safe the output config to a file, it is possible to manually override the and feed it back into PyO3 using the `PYO3_CONFIG_FILE` env var. For now, this is an advanced feature that should not be needed for most users. The format of the config file and its contents are deliberately unstable and undocumented. If you have a production use-case for this config file, please file an issue and help us stabilize it!
> Note: if you save the output config to a file, it is possible to manually override the contents and feed it back into PyO3 using the `PYO3_CONFIG_FILE` env var. For now, this is an advanced feature that should not be needed for most users. The format of the config file and its contents are deliberately unstable and undocumented. If you have a production use-case for this config file, please file an issue and help us stabilize it!
## Building Python extension modules

Expand Down
28 changes: 28 additions & 0 deletions pyo3-build-config/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,31 @@ where
})
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn error_report() {
let error: Result<()> = Err(Error::from("there was an internal error"))
.with_context(|| format!("failed to do {}", "something difficult"))
.context("things went wrong");

assert_eq!(
error
.unwrap_err()
.report()
.to_string()
.split('\n')
.collect::<Vec<&str>>(),
vec![
"things went wrong",
"caused by:",
" - 0: failed to do something difficult",
" - 1: there was an internal error",
""
]
);
}
}
Loading

0 comments on commit 2cf2c2f

Please sign in to comment.