From 91dd11960112a59a8fb0d9818b8bcc3d0814524a Mon Sep 17 00:00:00 2001 From: femshima <49227365+femshima@users.noreply.github.com> Date: Thu, 22 Feb 2024 10:24:46 +0900 Subject: [PATCH] split test using rstest_reuse --- Cargo.lock | 13 ++++++++++ Cargo.toml | 1 + crates/voicevox_core/Cargo.toml | 1 + .../src/engine/full_context_label.rs | 25 +++++++++++++++++-- crates/voicevox_core/src/lib.rs | 2 ++ 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1546a3e68..e1fcceb24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3213,6 +3213,18 @@ dependencies = [ "syn 1.0.102", ] +[[package]] +name = "rstest_reuse" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88530b681abe67924d42cca181d070e3ac20e0740569441a9e35a7cedd2b34a4" +dependencies = [ + "quote", + "rand 0.8.5", + "rustc_version 0.4.0", + "syn 2.0.48", +] + [[package]] name = "rustc-demangle" version = "0.1.21" @@ -4366,6 +4378,7 @@ dependencies = [ "rayon", "regex", "rstest", + "rstest_reuse", "serde", "serde_json", "smallvec", diff --git a/Cargo.toml b/Cargo.toml index 29150b48f..feb383c90 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,6 +62,7 @@ rayon = "1.6.1" regex = "1.10.0" reqwest = { version = "0.11.13", default-features = false } rstest = "0.15.0" +rstest_reuse = "0.6.0" serde = "1.0.145" serde_json = "1.0.85" serde_with = "3.3.0" diff --git a/crates/voicevox_core/Cargo.toml b/crates/voicevox_core/Cargo.toml index f8cf6d767..ea6d972d3 100644 --- a/crates/voicevox_core/Cargo.toml +++ b/crates/voicevox_core/Cargo.toml @@ -47,6 +47,7 @@ zip.workspace = true heck.workspace = true pretty_assertions.workspace = true rstest.workspace = true +rstest_reuse.workspace = true test_util.workspace = true tokio = { workspace = true, features = ["rt", "macros"] } diff --git a/crates/voicevox_core/src/engine/full_context_label.rs b/crates/voicevox_core/src/engine/full_context_label.rs index 564d2bf65..971be47a5 100644 --- a/crates/voicevox_core/src/engine/full_context_label.rs +++ b/crates/voicevox_core/src/engine/full_context_label.rs @@ -281,6 +281,8 @@ mod chunk_by { #[cfg(test)] mod tests { + use rstest_reuse::*; + use ::test_util::OPEN_JTALK_DIC_DIR; use rstest::rstest; @@ -296,6 +298,7 @@ mod tests { }; use jlabel::Label; + #[template] #[rstest] #[case( "いぇ", @@ -699,17 +702,24 @@ mod tests { ), ] )] - #[tokio::test] - async fn parse_labels( + fn label_cases( #[case] text: &str, #[case] labels: &[&str], #[case] accent_phrase: &[AccentPhraseModel], ) { + } + + #[apply(label_cases)] + #[tokio::test] + async fn openjtalk(text: &str, labels: &[&str], _accent_phrase: &[AccentPhraseModel]) { let openjtalk = crate::tokio::OpenJtalk::new(OPEN_JTALK_DIC_DIR) .await .unwrap(); assert_eq!(&openjtalk.extract_fullcontext(text).unwrap(), labels); + } + #[apply(label_cases)] + fn parse_labels(_text: &str, labels: &[&str], accent_phrase: &[AccentPhraseModel]) { let parsed_labels = labels .into_iter() .map(|s| Label::from_str(s).unwrap()) @@ -719,7 +729,18 @@ mod tests { &generate_accent_phrases(&parsed_labels).unwrap(), accent_phrase ); + } + #[apply(label_cases)] + #[tokio::test] + async fn extract_fullcontext( + text: &str, + _labels: &[&str], + accent_phrase: &[AccentPhraseModel], + ) { + let openjtalk = crate::tokio::OpenJtalk::new(OPEN_JTALK_DIC_DIR) + .await + .unwrap(); assert_eq!( &extract_full_context_label(&openjtalk, text).unwrap(), accent_phrase diff --git a/crates/voicevox_core/src/lib.rs b/crates/voicevox_core/src/lib.rs index f0a948354..64edce202 100644 --- a/crates/voicevox_core/src/lib.rs +++ b/crates/voicevox_core/src/lib.rs @@ -23,6 +23,8 @@ pub mod tokio; #[cfg(test)] mod test_util; +#[cfg(test)] +use rstest_reuse; pub use self::{ devices::SupportedDevices,