-
Notifications
You must be signed in to change notification settings - Fork 498
rust: Add identify_reader_sync/async for Read + Seek types #1313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -127,6 +127,35 @@ mod tests { | |
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn identify_by_reader_reference() { | ||
| #[derive(Debug, Deserialize)] | ||
| #[serde(deny_unknown_fields)] | ||
| struct Test { | ||
| prediction_mode: String, | ||
| content_base64: String, | ||
| status: String, | ||
| prediction: Option<Prediction>, | ||
| } | ||
| let path = format!( | ||
| "../../tests_data/reference/{MODEL_NAME}-inference_examples_by_content.json.gz" | ||
| ); | ||
| let mut tests = String::new(); | ||
| GzDecoder::new(File::open(path).unwrap()).read_to_string(&mut tests).unwrap(); | ||
| let tests: Vec<Test> = serde_json::from_str(&tests).unwrap(); | ||
| let mut session = Session::new().unwrap(); | ||
| for test in tests { | ||
| if test.prediction_mode != "high-confidence" { | ||
| continue; | ||
| } | ||
| assert_eq!(test.status, "ok"); | ||
| let expected = test.prediction.unwrap(); | ||
| let content = BASE64.decode(test.content_base64.as_bytes()).unwrap(); | ||
| let actual = session.identify_reader_sync(std::io::Cursor::new(content)).unwrap(); | ||
| assert_prediction(actual, expected, &test.content_base64); | ||
| } | ||
| } | ||
|
Comment on lines
+131
to
+157
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is significant code duplication between this new test To improve maintainability, you could refactor the common parts. For example, define the |
||
|
|
||
| #[test] | ||
| fn identify_by_content_reference() { | ||
| #[derive(Debug, Deserialize)] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.