Skip to content

Commit

Permalink
Merge pull request #62 from edgenai/chore/issue9
Browse files Browse the repository at this point in the history
[chore/issue9] tests adapted to latest changes in main
  • Loading branch information
toschoo authored Feb 14, 2024
2 parents a5afcb2 + 7270a03 commit eaac306
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions crates/edgen_core/src/whisper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,17 +331,17 @@ pub mod parse {

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

#[test]
fn parse_audio_succeeds() {
let sound = include_bytes!("../../edgen_server/resources/frost.wav");
assert!(parse_pcm(sound).is_ok(), "cannot parse audio file");
assert!(parse::pcm(sound).is_ok(), "cannot parse audio file");
}

#[test]
fn parse_audio_fails() {
let sound: Vec<u8> = vec![0, 1, 2, 3];
assert!(parse_pcm(&sound).is_err(), "can parse non-audio file");
assert!(parse::pcm(&sound).is_err(), "can parse non-audio file");
}
}
5 changes: 4 additions & 1 deletion crates/edgen_server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ async fn run_server(args: &cli::Serve) -> Result<bool, error::EdgenError> {
#[cfg(test)]
mod tests {
use super::*;
use crate::openai_shim::TranscriptionResponse;
use axum::routing::post;
use axum::Router;
use axum_test::multipart;
Expand Down Expand Up @@ -502,7 +503,7 @@ mod tests {
resp.assert_status_ok();

let expected_text = frost();
let actual_text = resp.text();
let actual_text = resp.json::<TranscriptionResponse>().text;

// Calculate Levenshtein distance
let distance = levenshtein::levenshtein(&expected_text, &actual_text);
Expand All @@ -512,6 +513,8 @@ mod tests {
100.0 - ((distance as f64 / expected_text.len() as f64) * 100.0);

// Assert that the similarity is at least 90%
println!("test : '{}'", actual_text);
println!("similarity: {}", similarity_percentage);
assert!(
similarity_percentage >= 90.0,
"Text similarity is less than 90%"
Expand Down
8 changes: 5 additions & 3 deletions crates/edgen_server/src/whisper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ mod tests {

#[tokio::test]
#[ignore] // this test hangs sometimes
async fn test_audio_transcriptions() {
async fn test_create_transcription() {
init_settings_for_test().await;
let model_name = "ggml-distil-small.en.bin".to_string();
let repo = "distil-whisper/distil-small.en".to_string();
Expand All @@ -94,12 +94,14 @@ mod tests {
assert!(model.preload().await.is_ok());

let sound = include_bytes!("../resources/frost.wav");
let response = create_transcription(sound, model, None, None, None).await;
let response = create_transcription(sound, model, None, None, None, true, None).await;

assert!(response.is_ok(), "cannot create transcription");

let expected_text = frost();
let actual_text = response.unwrap();
let (actual_text, session) = response.unwrap();

println!("{:?}", session);

// Calculate Levenshtein distance
let distance = levenshtein::levenshtein(&expected_text, &actual_text);
Expand Down

0 comments on commit eaac306

Please sign in to comment.