### based on "test_exemplars" in test_validate.py
### not sure all these are needed
import unittest
import pytest
import logging, os
from lxml.etree import RelaxNG, parse, DocumentInvalid

def test_autonym(ldml):
#    if iscldr(ldml):    # short circuit CLDR for now until they/we resolve the faults in their data
#        return
#   get main exemplar
    main = None
    for e in ldml.ldml.root.findall('.//characters/exemplarCharacters'):
        t = e.get('type', None)
        if t: continue
        main_display = e.text
        main = set(e.text[1:-1].split(' '))
        break
    if not main:
        return # or flag error that there's no main exemplar!
#   get language id
    langid = ldml.ldml.root.find("identity/language").get("type")
#   get name of this language
    names = ldml.ldml.root.find("localeDisplayNames/languages")
    if names is None:
        # error: no Display Names
        return
    autonym = names.findall('language[@type="{0}"]'.format(langid))
    if autonym is None: 
        # error: name of language missing
        return 
    autonym_text = autonym[0].text.lower()
    if len(autonym_text) < 1:
        # error: name of language missing
        return
    
#   assert every character in lower case version of autonym is in main exemplar
    assert set("".join(autonym_text.split(" "))) < main, langid + ": Name of language (" + autonym_text + ") contains characters not in main exemplar " + main_display

@@ -66,16 +66,24 @@
 l these 
+imports 
 are need
@@ -193,34 +193,326 @@
 lid%0A
-%0Adef test_autonym(ldml):%0A#
+import palaso.sldr.UnicodeSets as usets%0A%0Adef iscldr(ldml):%0A    i = ldml.ldml.find(%22.//identity/special/sil:identity%22)%0A    if i is not None and i.get('source', %22%22) == %22cldr%22:%0A        return True%0A    return False%0A%0Adef test_autonym(ldml):%0A    filename = os.path.basename(ldml.ldml.fname)    # get filename for reference%0A%0A
     
@@ -607,17 +607,16 @@
 ir data%0A
-#
         
@@ -622,16 +622,17 @@
  return%0A
+%0A
 #   get 
@@ -802,23 +802,20 @@
    main_
-display
+exem
  = e.tex
@@ -835,35 +835,36 @@
 n = 
+u
 set
-(e.text%5B1:-1%5D.split(' ')
+s.parse(main_exem, 'NFD'
 )%0A  
@@ -892,24 +892,25 @@
 t main:%0A
+#
         
 return #
@@ -905,147 +905,389 @@
     
-return # or flag error that there's no main exemplar!%0A#   get language id%0A    langid = ldml.ldml.root.find(%22identity/language%22).get(%22type%22)
+assert False, filename + %22 has no main exemplar%22 ### should be target of another test%0A        return%0A%0A#   get language id%0A    langid = ldml.ldml.root.find(%22identity/language%22).get(%22type%22)%0A    ### should be target of another test:%0A    ### could check that filename.split('_')%5B0%5D == langid%0A    #assert filename.split('_')%5B0%5D == langid, filename + %22 %22 + langid + %22 don't correspond%22 %0A
 %0A#  
@@ -1399,24 +1399,25 @@
 s None:%0A
+#
         
 # error:
@@ -1412,33 +1412,61 @@
     
-# error: no 
+assert False, filename + %22 has no locale
 Display
- 
 Names
+%22
 %0A   
@@ -1582,41 +1582,95 @@
     
-# error: name of language
+assert False, filename + %22 %22 + langid + %22: Name of language in this language is
  missing
 %0A   
@@ -1657,32 +1657,33 @@
 guage is missing
+%22
 %0A        return 
@@ -1768,41 +1768,94 @@
     
-# error: name of language missing
+assert False, filename + %22 %22 + langid + %22: Name of language in this language is empty%22
 %0A   
@@ -1870,23 +1870,29 @@
 urn%0A
+#
    
- %0A#   assert
+The real test: is
  eve
@@ -1937,19 +1937,16 @@
 autonym 
-is 
 in main 
@@ -1957,32 +1957,55 @@
 plar
+?
 %0A    
-as
+name
 se
-r
 t 
-set(%22
+= usets.parse(%22%5B%22 + %22 
 %22.join(
+set(
 auto
@@ -2016,29 +2016,69 @@
 text
-.split(%22 %22)))
+)) + %22%5D%22, 'NFD')%0A    assert nameset
  %3C
+=
  main,
+ filename + %22 %22 +
  lan
@@ -2180,12 +2180,9 @@
 ain_
-display
+exem
 %0A

change to use UnicodeSets