Skip to content

Commit

Permalink
Update the tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Narsil committed Aug 2, 2024
1 parent 061d59a commit 040e1fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bindings/python/src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,6 @@ mod test {
])));

let output = crate::utils::serde_pyo3::to_string(&tokenizer).unwrap();
assert_eq!(output, "");
assert_eq!(output, "Tokenizer(version=\"1.0\", truncation=None, padding=None, added_tokens=[], normalizer=Sequence(normalizers=[NFKC(), Lowercase()]), pre_tokenizer=None, post_processor=None, decoder=None, model=BPE(dropout=None, unk_token=None, continuing_subword_prefix=None, end_of_word_suffix=None, fuse_unk=False, byte_fallback=False, ignore_merges=False, vocab={}, merges=[]))");
}
}
23 changes: 20 additions & 3 deletions bindings/python/src/utils/serde_pyo3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,13 @@ fn test_struct_tagged() {
}

let u = A { a: true, b: 1 };
let expected = r#"A(type="A", a=True, b=1)"#;
// let expected = r#"A(type="A", a=True, b=1)"#;
// No we skip all `type` manually inserted variants.
let expected = r#"A(a=True, b=1)"#;
assert_eq!(to_string(&u).unwrap(), expected);

let u = E::A(A { a: true, b: 1 });
let expected = r#"A(type="A", a=True, b=1)"#;
let expected = r#"A(a=True, b=1)"#;
assert_eq!(to_string(&u).unwrap(), expected);
}

Expand All @@ -626,6 +628,12 @@ fn test_flatten() {
d: usize,
}

#[derive(Serialize)]
#[serde(transparent)]
struct D {
e: A,
}

let u = B {
c: A { a: true, b: 1 },
d: 2,
Expand All @@ -637,6 +645,15 @@ fn test_flatten() {
c: A { a: true, b: 1 },
d: 2,
};
let expected = r#"C(a=True, b=1, d=2)"#;
// XXX This is unfortunate but true, flatten forces the serialization
// to use the serialize_map without any means for the Serializer to know about this
// flattening attempt
let expected = r#"{"a":True, "b":1, "d":2}"#;
assert_eq!(to_string(&u).unwrap(), expected);

let u = D {
e: A { a: true, b: 1 },
};
let expected = r#"A(a=True, b=1)"#;
assert_eq!(to_string(&u).unwrap(), expected);
}

0 comments on commit 040e1fd

Please sign in to comment.