Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ mod rustfluent {
ftl_filenames: &'_ Bound<'_, PyList>,
strict: bool,
) -> PyResult<Self> {
let langid: LanguageIdentifier = language.parse().expect("Parsing failed");
let langid: LanguageIdentifier = match language.parse() {
Ok(langid) => langid,
Err(_) => {
return Err(PyValueError::new_err(format!(
"Invalid language: '{language}'"
)));
}
};
let mut bundle = FluentBundle::new_concurrent(vec![langid]);

for file_path in ftl_filenames.iter() {
Expand Down
7 changes: 7 additions & 0 deletions tests/test_python_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ def test_variables_of_different_types(description, identifier, variables, expect
assert result == expected


def test_invalid_language():
with pytest.raises(ValueError) as exc_info:
fluent.Bundle("$", [])

assert str(exc_info.value) == "Invalid language: '$'"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐼 Could do this using with pytest.raises(Value, match="..."):.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could, but I don't really like it because then I have to deal with regexes and escaping. This way it's an exact match.



@pytest.mark.parametrize(
"key",
(
Expand Down