pub struct ImageFixture {
pub path: String,
pub digest: String,
pub mime_type: Option<String>,
/* private fields */
}Expand description
An image an eval case shows the agent: a file named by its path, relative to the eval file’s directory, and pinned by its SHA-256.
§Example
use adk_eval::ImageFixture;
let dir = tempfile::tempdir().unwrap();
std::fs::write(dir.path().join("page.png"), b"not really a png").unwrap();
let mut image = ImageFixture::new("page.png", &format!("sha256:{}", "0".repeat(64)));
let err = image.load(dir.path()).unwrap_err();
assert!(err.to_string().contains("does not match"), "{err}");
let digest = ImageFixture::digest_of(b"not really a png");
let mut image = ImageFixture::new("page.png", &digest);
image.load(dir.path()).unwrap();
assert_eq!(image.bytes(), Some(&b"not really a png"[..]));
assert_eq!(image.mime_type(), "image/png");Fields§
§path: StringThe image file, relative to the eval file’s directory (or absolute).
digest: StringThe file’s SHA-256 as sha256:<64 hex digits>; the bare digits are accepted.
mime_type: Option<String>The MIME type; inferred from the extension when absent.
Implementations§
Source§impl ImageFixture
impl ImageFixture
Sourcepub fn new(path: impl Into<String>, digest: &str) -> Self
pub fn new(path: impl Into<String>, digest: &str) -> Self
A fixture for the file at path with this digest.
Sourcepub fn digest_of(bytes: &[u8]) -> String
pub fn digest_of(bytes: &[u8]) -> String
The digest of bytes in the form fixtures pin: sha256:<64 hex digits>.
Sourcepub fn load(&mut self, base_dir: &Path) -> Result<()>
pub fn load(&mut self, base_dir: &Path) -> Result<()>
Reads the file, resolving a relative path against base_dir, and checks it against
the digest.
§Errors
Returns EvalError::LoadError when the digest is malformed, or the file is
missing, unreadable, larger than adk_core::MAX_INLINE_DATA_SIZE, or has another
digest.
Sourcepub fn resolved_path(&self) -> Option<&Path>
pub fn resolved_path(&self) -> Option<&Path>
The resolved path, once loaded.
Trait Implementations§
Source§impl Clone for ImageFixture
impl Clone for ImageFixture
Source§impl Debug for ImageFixture
impl Debug for ImageFixture
Source§impl<'de> Deserialize<'de> for ImageFixture
impl<'de> Deserialize<'de> for ImageFixture
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Forget for ImageFixture
impl Freeze for ImageFixture
impl Move for ImageFixture
impl RefUnwindSafe for ImageFixture
impl Send for ImageFixture
impl Sync for ImageFixture
impl Unpin for ImageFixture
impl UnsafeUnpin for ImageFixturewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
*const ArcInner<[u8]> is !null: UnsafeUnpin,
PhantomData<ArcInner<[u8]>>: UnsafeUnpin,
impl UnwindSafe for ImageFixture
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more