forked from DeepL/deepl-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_util.py
More file actions
35 lines (25 loc) · 1.25 KB
/
Copy pathtest_util.py
File metadata and controls
35 lines (25 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Copyright 2022 DeepL SE (https://www.deepl.com)
# Use of this source code is governed by an MIT
# license that can be found in the LICENSE file.
import deepl
import pytest
def test_convert_tsv_to_dict():
result = deepl.convert_tsv_to_dict("Apple\tApfel\n\nBanana \t Banane ")
assert result == {"Apple": "Apfel", "Banana": "Banane"}
with pytest.raises(ValueError, match="does not contain separator"):
deepl.convert_tsv_to_dict("no separator")
with pytest.raises(ValueError, match="more than one term separator"):
deepl.convert_tsv_to_dict("too\tmany\tseparators")
with pytest.raises(ValueError, match="duplicates source term"):
deepl.convert_tsv_to_dict("source\ttarget1\nsource\ttarget2")
def test_convert_dict_to_tsv():
result = deepl.convert_dict_to_tsv(
{"Apple": "Apfel", "Banana ": " Banane "}
)
assert result == "Apple\tApfel\nBanana\tBanane"
with pytest.raises(ValueError, match="invalid character"):
deepl.convert_dict_to_tsv({"source\t1": "target"})
with pytest.raises(ValueError, match="not a valid string"):
deepl.convert_dict_to_tsv({"": "target"})
with pytest.raises(ValueError, match="not a valid string"):
deepl.convert_dict_to_tsv({"\t": "target"})