Skip to content

Commit

Permalink
new test called test_direction in test_validate for if rtl is indicat…
Browse files Browse the repository at this point in the history
…ed in layout/orientation/characterOrder for locales using rtl scripts
  • Loading branch information
emily-roth committed Apr 1, 2024
1 parent 7960b68 commit af4384e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit af4384e

Please sign in to comment.