2024-02-25 17:32:54 +01:00
|
|
|
import os
|
2024-02-25 22:13:35 +01:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2024-02-25 17:32:54 +01:00
|
|
|
from app.tasks.minetestcheck.translation import parse_tr
|
|
|
|
|
|
|
|
|
|
|
|
def test_parses_tr():
|
|
|
|
dirname = os.path.dirname(__file__)
|
2024-02-25 22:13:35 +01:00
|
|
|
filepath = os.path.join(dirname, "foo.bar.fr.tr")
|
|
|
|
out = parse_tr(filepath)
|
|
|
|
|
|
|
|
assert out.language == "fr"
|
|
|
|
assert out.textdomain == "foo.bar"
|
|
|
|
assert len(out.entries) == 5
|
|
|
|
assert out.entries["Hello, World!"] == "Bonjour, Monde!"
|
|
|
|
assert out.entries["Hello @1!"] == "@1, salut!"
|
|
|
|
assert out.entries["Cats = cool"] == "Chats = cool"
|
|
|
|
assert out.entries["A \n newline"] == "Une \nnouvelle ligne"
|
|
|
|
assert out.entries["Maybe @\n@=@"] == "Peut être @\n@=@"
|
|
|
|
|
|
|
|
|
2024-02-26 02:18:38 +01:00
|
|
|
def test_parses_tr_error_on_missing_textdomain():
|
2024-02-25 22:13:35 +01:00
|
|
|
dirname = os.path.dirname(__file__)
|
|
|
|
filepath = os.path.join(dirname, "no_textdomain_comment.fr.tr")
|
2024-02-25 17:32:54 +01:00
|
|
|
|
2024-02-26 02:18:38 +01:00
|
|
|
with pytest.raises(SyntaxError) as e:
|
|
|
|
parse_tr(filepath)
|
|
|
|
|
|
|
|
assert str(e.value) == "Missing `# textdomain: no_textdomain_comment` at the top of the file"
|
2024-02-25 22:13:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_parses_tr_error_on_textdomain_mismatch():
|
|
|
|
dirname = os.path.dirname(__file__)
|
|
|
|
filepath = os.path.join(dirname, "textdomain_mismatch.fr.tr")
|
|
|
|
|
|
|
|
with pytest.raises(SyntaxError) as e:
|
|
|
|
parse_tr(filepath)
|
|
|
|
|
|
|
|
assert str(e.value) == "Line 1: The filename's textdomain (textdomain_mismatch) should match the comment (foobar)"
|
|
|
|
|
|
|
|
|
|
|
|
def test_parses_tr_error_on_missing_eq():
|
|
|
|
dirname = os.path.dirname(__file__)
|
|
|
|
filepath = os.path.join(dirname, "err_missing_eq.fr.tr")
|
|
|
|
|
|
|
|
with pytest.raises(SyntaxError) as e:
|
|
|
|
parse_tr(filepath)
|
|
|
|
|
|
|
|
assert str(e.value) == "Line 4: Missing = in line"
|
|
|
|
|
|
|
|
|
|
|
|
def test_parses_tr_error_on_bad_escape():
|
|
|
|
dirname = os.path.dirname(__file__)
|
|
|
|
filepath = os.path.join(dirname, "bad_escape.fr.tr")
|
|
|
|
|
|
|
|
with pytest.raises(SyntaxError) as e:
|
|
|
|
parse_tr(filepath)
|
|
|
|
|
2024-02-26 02:18:38 +01:00
|
|
|
assert str(e.value) == "Line 2: Unknown escape character: x"
|
2024-02-26 01:41:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_parses_tr_error_on_bad_args():
|
|
|
|
dirname = os.path.dirname(__file__)
|
|
|
|
filepath = os.path.join(dirname, "bad_args.fr.tr")
|
|
|
|
|
|
|
|
with pytest.raises(SyntaxError) as e:
|
|
|
|
parse_tr(filepath)
|
|
|
|
|
2024-02-26 02:18:38 +01:00
|
|
|
assert "Line 2: Arguments out of order in source, found @5 and expected @2." in str(e.value)
|
2024-02-26 01:41:22 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_parses_tr_error_on_unknown_arg():
|
|
|
|
dirname = os.path.dirname(__file__)
|
|
|
|
filepath = os.path.join(dirname, "unknown_arg.fr.tr")
|
|
|
|
|
|
|
|
with pytest.raises(SyntaxError) as e:
|
|
|
|
parse_tr(filepath)
|
|
|
|
|
2024-02-26 02:18:38 +01:00
|
|
|
assert str(e.value) == "Line 2: Unknown argument @2 in translated string"
|