Skip to content
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

Add-legacy-tests #1597

Merged
merged 14 commits into from
Aug 6, 2024
39 changes: 39 additions & 0 deletions tokenizers/src/pre_tokenizers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,43 @@ mod tests {
PreTokenizerWrapper::WhitespaceSplit(WhitespaceSplit {})
);
}

#[test]
fn pre_tokenizer_deserialization_no_type() {
let json = r#"{"replacement":"▁","add_prefix_space":true, "prepend_scheme":"always"}}"#;
let reconstructed = serde_json::from_str::<PreTokenizerWrapper>(json);
match reconstructed {
Err(err) => assert_eq!(
err.to_string(),
"data did not match any variant of untagged enum PreTokenizerWrapper"
),
_ => panic!("Expected an error here"),
}

let json = r#"{"type":"Metaspace", "replacement":"▁" }"#;
let reconstructed = serde_json::from_str::<PreTokenizerWrapper>(json);
match reconstructed {
Ok(processor) => assert!(matches!(processor, PreTokenizerWrapper::Metaspace(_))),
Err(err) => panic!("{:?}", err),
}
ArthurZucker marked this conversation as resolved.
Show resolved Hide resolved

let json = r#"{"type":"Metaspace", "add_prefix_space":true }"#;
let reconstructed = serde_json::from_str::<PreTokenizerWrapper>(json);
match reconstructed {
Err(err) => assert_eq!(
err.to_string(),
"data did not match any variant of untagged enum PreTokenizerWrapper"
),
_ => panic!("Expected an error here"),
}
ArthurZucker marked this conversation as resolved.
Show resolved Hide resolved
let json = r#"{"behavior":"default_split"}"#;
let reconstructed = serde_json::from_str::<PreTokenizerWrapper>(json);
match reconstructed {
Err(err) => assert_eq!(
err.to_string(),
"data did not match any variant of untagged enum PreTokenizerWrapper"
),
_ => panic!("Expected an error here"),
}
}
}
38 changes: 38 additions & 0 deletions tokenizers/src/processors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,42 @@ mod tests {
PostProcessorWrapper::Bert(bert)
);
}

#[test]
fn post_processor_deserialization_no_type() {
let json = r#"{"add_prefix_space": true, "trim_offsets": false, "use_regex": false}"#;
let reconstructed = serde_json::from_str::<PostProcessorWrapper>(json);
match reconstructed {
Err(err) => assert_eq!(
err.to_string(),
"data did not match any variant of untagged enum PostProcessorWrapper"
),
_ => panic!("Expected an error here"),
}

let json = r#"{"sep":["[SEP]",102],"cls":["[CLS]",101]}"#;
let reconstructed = serde_json::from_str::<PostProcessorWrapper>(json);
match reconstructed {
Ok(processor) => assert!(matches!(processor, PostProcessorWrapper::Bert(_))),
Err(err) => panic!("{:?}", err),
}

let json =
r#"{"sep":["</s>",2], "cls":["<s>",0], "trim_offsets":true, "add_prefix_space":true}"#;
let reconstructed = serde_json::from_str::<PostProcessorWrapper>(json);
match reconstructed {
Ok(processor) => assert!(matches!(processor, PostProcessorWrapper::Roberta(_))),
Err(err) => panic!("{:?}", err),
}

let json = r#"{"type":"RobertaProcessing", "sep":["</s>",2] }"#;
let reconstructed = serde_json::from_str::<PostProcessorWrapper>(json);
match reconstructed {
Err(err) => assert_eq!(
err.to_string(),
"data did not match any variant of untagged enum PostProcessorWrapper"
),
_ => panic!("Expected an error here"),
}
}
}
Loading