def test_script_name(): assert unicodedata.script_name("Latn") == "Latin" assert unicodedata.script_name("Zyyy") == "Common" assert unicodedata.script_name("Zzzz") == "Unknown" # underscores in long names are replaced by spaces assert unicodedata.script_name("Egyp") == "Egyptian Hieroglyphs" with pytest.raises(KeyError): unicodedata.script_name("QQQQ") assert unicodedata.script_name("QQQQ", default="Unknown")
value, name, category = line.split(";") value = int(value, 16) if openValue is not None: closeValue = value if openValue not in _openToClose: _openToClose[openValue] = closeValue if closeValue not in _closeToOpen: _closeToOpen[closeValue] = openValue openValue = None else: openValue = value # ordered sets orderedScripts = [] for value in unicodedata.Scripts.VALUES: value = unicodedata.script_name(value) if value == "Unknown": continue if value not in orderedScripts: orderedScripts.append(value) orderedScripts.append("Unknown") orderedBlocks = [] for value in unicodedata.Blocks.VALUES: if value == "No_Block": continue if value not in orderedBlocks: orderedBlocks.append(value) orderedCategories = """Lu Ll
def script(value): char = chr(value) return unicodedata.script_name(unicodedata.script(char), default="Unknown")
cps_to_value = dict[range, str]() for line in path.read_text().splitlines(): if not (content := line.partition("#")[0].strip()): continue field_0, value = [i.strip() for i in content.split(";")] start, _, stop = field_0.partition("..") cps_to_value[range(int(start, 16), int(stop or start, 16) + 1)] = value script_to_value_to_cps = dict[str, dict[str, list[int]]]() for cp, value in sorted( (i, v) for k, v in cps_to_value.items() for i in k): value_to_cps = script_to_value_to_cps.setdefault( unicodedata.script_name(unicodedata.script(chr(cp))), {}) value_to_cps.setdefault(value, list()).append(cp) # yaml.add_representer( # int, # lambda dumper, data: dumper.represent_scalar("tag:yaml.org,2002:int", f"0x{data:04X}"), # ) path = directory / "tests" / (property_name + ".yaml") with path.open("w") as f: yaml.dump( { k: { value: [{ i: unicodedata.name(chr(i)) } for i in cps] for value, cps in v.items()