-
Notifications
You must be signed in to change notification settings - Fork 0
π§ͺ Add error path test for extract_text in PDF extraction
#41
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| --- rust/crates/tools/src/pdf_extract.rs | ||
| +++ rust/crates/tools/src/pdf_extract.rs | ||
| @@ -404,4 +404,12 @@ | ||
| // cleanup | ||
| let _ = std::fs::remove_dir_all(&dir); | ||
| } | ||
| + | ||
| + #[test] | ||
| + fn extract_text_returns_error_for_nonexistent_file() { | ||
| + let path = Path::new("/this/path/does/not/exist.pdf"); | ||
| + let result = extract_text(path); | ||
| + assert!(result.is_err()); | ||
| + assert!(result.unwrap_err().starts_with("failed to read PDF:")); | ||
| + } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -545,4 +545,12 @@ mod tests { | |||||||||||||||||||||||||||||
| // cleanup | ||||||||||||||||||||||||||||||
| let _ = std::fs::remove_dir_all(&dir); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||
| fn extract_text_returns_error_for_nonexistent_file() { | ||||||||||||||||||||||||||||||
| let path = Path::new("/this/path/does/not/exist.pdf"); | ||||||||||||||||||||||||||||||
|
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.
This test assumes Useful? React with πΒ / π.
Owner
Author
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. @copilot, make changes based on the above suggestion. |
||||||||||||||||||||||||||||||
| let result = extract_text(path); | ||||||||||||||||||||||||||||||
|
Comment on lines
+551
to
+552
|
||||||||||||||||||||||||||||||
| let path = Path::new("/this/path/does/not/exist.pdf"); | |
| let result = extract_text(path); | |
| let unique = format!( | |
| "clawd-pdf-extract-missing-{}-{}.pdf", | |
| std::process::id(), | |
| std::time::SystemTime::now() | |
| .duration_since(std::time::UNIX_EPOCH) | |
| .unwrap() | |
| .as_nanos() | |
| ); | |
| let path = std::env::temp_dir().join(unique); | |
| let _ = std::fs::remove_file(&path); | |
| let result = extract_text(path.as_path()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
patch.difflooks like a generated patch artifact and is not referenced by the build/tests. Committing it adds noise and can confuse future changes; please remove it from the PR (or place it under a docs/fixtures location if itβs intentionally needed, with a reference).