From af4384e8d56e3cf9afa12a3826e9aed08b38f358 Mon Sep 17 00:00:00 2001 From: Emily Roth Date: Mon, 1 Apr 2024 15:02:10 -0400 Subject: [PATCH] new test called test_direction in test_validate for if rtl is indicated in layout/orientation/characterOrder for locales using rtl scripts --- tests/test_validate.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_validate.py b/tests/test_validate.py index 16d3ae006..d83f48cc8 100644 --- a/tests/test_validate.py +++ b/tests/test_validate.py @@ -5,6 +5,7 @@ import sldr.UnicodeSets as usets from unicodedata import normalize import re +from sldr.utils import find_parents @pytest.fixture(scope="session") def validator(request): @@ -159,6 +160,24 @@ def test_diacritics (ldml): print (c) assert c not in comb_diacritics, filename + " diacritics aren't composed" +def test_direction(ldml, langid): + """ Tests that a locale featuring an RTL language also has "right-to-left" listed under layout/orientation/characterOrder or else inherits it from a parent using the same script""" + filename = os.path.basename(ldml.ldml.fname) # get filename for reference + if iscldr(ldml): # short circuit CLDR for now until they/we resolve the faults in their data + return + if filename == "root.xml" or filename == "test.xml": + return + i = ldml.ldml.root.find(".//identity/special/sil:identity", {v:k for k,v in ldml.ldml.namespaces.items()}) + script = i.get("script") or ldml.ldml.root.find('.//identity/script') + rtlscripts = ["Arab", "Hebr", "Syrc", "Thaa", "Mand", "Samr", "Nkoo", "Gara", "Adlm", "Rohg", "Yezi", "Todr"] # only listing non-historic scripts atm + if script in rtlscripts: + direction = ldml.ldml.root.find('.//layout/orientation/characterOrder') + if direction == None: + noparent = find_parents(langid, False, True, True, False)[0] # if has a parent of the same script, will inherit order from parent. If parent has an error, that's the parent's fault and will be pinged when test runs on parent. + assert noparent == False, filename + "uses an rtl script but does not indicate rtl in layout/orientation/characterOrder" + else: + assert direction.text != "left-to-right", filename + " uses an rtl script but says ltr in layout/orientation/characterOrder" + def _duplicate_test(base, ldml, path=""): filename = os.path.basename(ldml.fname) # get filename for reference idents = set()