From 8a84b0480413a2e43cc08fd58329c6b123eb7663 Mon Sep 17 00:00:00 2001 From: "A. Sean Pue" Date: Sun, 15 Oct 2023 21:18:01 -0400 Subject: [PATCH] minor formatting --- docs/conf.py | 4 +--- pyproject.toml | 1 - tests/test_ambiguity.py | 17 ++++------------ tests/test_cli.py | 32 ++++++++----------------------- tests/test_compression.py | 8 ++------ tests/test_graphtransliterator.py | 27 ++++++-------------------- tests/test_transliterators.py | 10 ++-------- 7 files changed, 23 insertions(+), 76 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index e8369715..ead31c33 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -21,9 +21,7 @@ import os import sys -sys.path.insert( - 0, os.path.abspath("..") -) # necessary to import graphtransilterator here +sys.path.insert(0, os.path.abspath("..")) # necessary to import graphtransilterator here package_path = os.path.abspath("..") # this may work for jupyter-sphinx? os.environ["PYTHONPATH"] = ":".join((package_path, os.environ.get("PYTHONPATH", ""))) diff --git a/pyproject.toml b/pyproject.toml index b6f1e5c1..e82a1c1a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -99,4 +99,3 @@ skip_empty = true [tool.coverage.run] branch = true source = ["graphtransliterator"] - diff --git a/tests/test_ambiguity.py b/tests/test_ambiguity.py index 5b7fbc86..be54d54f 100644 --- a/tests/test_ambiguity.py +++ b/tests/test_ambiguity.py @@ -59,24 +59,15 @@ def test_GraphParser_check_ambiguity(): def test_GraphTransliterator_easy_reading(): assert ( - _easyreading_rule( - TransliterationRule("", ["class_a"], [], ["a"], [], ["class_a"], 0) - ) + _easyreading_rule(TransliterationRule("", ["class_a"], [], ["a"], [], ["class_a"], 0)) == " a " ) assert ( - _easyreading_rule( - TransliterationRule("", ["class_a"], [], ["a"], [], ["class_a"], 0) - ) + _easyreading_rule(TransliterationRule("", ["class_a"], [], ["a"], [], ["class_a"], 0)) == " a " ) + assert _easyreading_rule(TransliterationRule("", [], ["b"], ["a"], ["b"], [], 0)) == "(b) a (b)" assert ( - _easyreading_rule(TransliterationRule("", [], ["b"], ["a"], ["b"], [], 0)) - == "(b) a (b)" - ) - assert ( - _easyreading_rule( - TransliterationRule("", ["class_a"], ["b"], ["a"], ["b"], ["class_a"], 0) - ) + _easyreading_rule(TransliterationRule("", ["class_a"], ["b"], ["a"], ["b"], ["class_a"], 0)) == "( b) a (b )" ) diff --git a/tests/test_cli.py b/tests/test_cli.py index bbec620b..be4cb6e6 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -49,16 +49,12 @@ def test_cli_transliterate_tests(tmpdir): runner = CliRunner() # test bundled - bundled_result = runner.invoke( - cli.main, ["transliterate", "--from", "bundled", "Example", "a"] - ) + bundled_result = runner.invoke(cli.main, ["transliterate", "--from", "bundled", "Example", "a"]) assert bundled_result.exit_code == 0 assert bundled_result.output.strip() == "A" # test multiple inputs with python output - bundled_multiple_result = runner.invoke( - cli.main, ["transliterate", "--from", "bundled", "Example", "a", "a"] - ) + bundled_multiple_result = runner.invoke(cli.main, ["transliterate", "--from", "bundled", "Example", "a", "a"]) assert bundled_multiple_result.exit_code == 0 assert bundled_multiple_result.output.strip() == str(["A", "A"]) @@ -72,27 +68,21 @@ def test_cli_transliterate_tests(tmpdir): # test transliterate from JSON json_ = transliterator.dumps() - json_result = runner.invoke( - cli.main, ["transliterate", "--from", "json", json_, "a"] - ) + json_result = runner.invoke(cli.main, ["transliterate", "--from", "json", json_, "a"]) assert json_result.exit_code == 0 assert json_result.output.strip() == "A" # test transliterate from json file json_file = tmpdir.mkdir("sub").join("test.json") json_file.write(json_) - json_file_result = runner.invoke( - cli.main, ["transliterate", "--from", "json_file", json_file.strpath, "a"] - ) + json_file_result = runner.invoke(cli.main, ["transliterate", "--from", "json_file", json_file.strpath, "a"]) assert json_file_result.exit_code == 0 assert json_file_result.output.strip() == "A" # test transliterate from yaml file yaml_file = tmpdir.join("test.yaml") yaml_file.write(test_yaml) - yaml_file_result = runner.invoke( - cli.main, ["transliterate", "--from", "yaml_file", yaml_file.strpath, "a"] - ) + yaml_file_result = runner.invoke(cli.main, ["transliterate", "--from", "yaml_file", yaml_file.strpath, "a"]) assert yaml_file_result.exit_code == 0 assert yaml_file_result.output.strip() == "A" @@ -100,9 +90,7 @@ def test_cli_transliterate_tests(tmpdir): def test_cli_generate_tests(): """Test tests command.""" runner = CliRunner() - gen_tests_result = runner.invoke( - cli.main, ["generate-tests", "--from", "bundled", "Example"] - ) + gen_tests_result = runner.invoke(cli.main, ["generate-tests", "--from", "bundled", "Example"]) assert gen_tests_result.exit_code == 0 yaml_ = yaml.safe_load(StringIO(gen_tests_result.output)) assert len(yaml_) == 5 and type(yaml_) == dict @@ -163,13 +151,9 @@ def test_dump_tests(): runner = CliRunner() test_result = runner.invoke(cli.main, ["dump-tests", "Example"]) # yaml assert "a: A" in test_result.output - test_result = runner.invoke( - cli.main, ["dump-tests", "--to", "json", "Example"] - ) # json + test_result = runner.invoke(cli.main, ["dump-tests", "--to", "json", "Example"]) # json assert '"a": "A"' in test_result.output, test_result.output - test_result = runner.invoke( - cli.main, ["dump-tests", "--to", "yaml", "Example"] - ) # json + test_result = runner.invoke(cli.main, ["dump-tests", "--to", "yaml", "Example"]) # json assert "a: A" in test_result.output diff --git a/tests/test_compression.py b/tests/test_compression.py index 96244b46..2802b3f4 100644 --- a/tests/test_compression.py +++ b/tests/test_compression.py @@ -51,16 +51,12 @@ def test_compression(): decompressed_config = compression.decompress_config(compressed_config) gt_from_decompressed = GraphTransliterator.load(decompressed_config) # Compare JSON dumps with sorted keys. - assert json.dumps(gt.dump(), sort_keys=True) == json.dumps( - gt_from_decompressed.dump(), sort_keys=True - ) + assert json.dumps(gt.dump(), sort_keys=True) == json.dumps(gt_from_decompressed.dump(), sort_keys=True) # Test bad compression level with pytest.raises(ValueError): gt.dump(compression_level=graphtransliterator.HIGHEST_COMPRESSION_LEVEL + 1) # Test compression at level 0 (should likely not be called) - assert "compressed_settings" not in compression.compress_config( - gt.dump(), compression_level=0 - ) + assert "compressed_settings" not in compression.compress_config(gt.dump(), compression_level=0) # Test compression levels assert '"tokens": ' in gt.dumps(compression_level=0) assert '"compressed_settings"' in gt.dumps(compression_level=1) diff --git a/tests/test_graphtransliterator.py b/tests/test_graphtransliterator.py index 85b4bc18..281da046 100644 --- a/tests/test_graphtransliterator.py +++ b/tests/test_graphtransliterator.py @@ -200,14 +200,8 @@ def test_graphtransliterator_process(): assert process._process_rules({"a": "A"})[0]["tokens"] == ["a"] assert process._process_rules({"a": "A"})[0]["production"] == "A" - assert ( - process._process_onmatch_rules(data["onmatch_rules"])[0]["prev_classes"][0] - == "class1" - ) - assert ( - process._process_onmatch_rules(data["onmatch_rules"])[0]["next_classes"][0] - == "class2" - ) + assert process._process_onmatch_rules(data["onmatch_rules"])[0]["prev_classes"][0] == "class1" + assert process._process_onmatch_rules(data["onmatch_rules"])[0]["next_classes"][0] == "class2" def test_graphtransliterator_models(): @@ -403,9 +397,7 @@ def test_serialization(): settings = gt.dump() for _ in to_drop: settings.pop(_) - if settings.get("onmatch_rules_lookup") and not settings.get( - "onmatch_rules" - ): + if settings.get("onmatch_rules_lookup") and not settings.get("onmatch_rules"): with pytest.raises(ValidationError): assert GraphTransliterator.load(settings) else: @@ -493,9 +485,7 @@ def test_GraphTransliterator(tmpdir): assert len(set(GraphTransliterator.from_easyreading_dict(input_dict).tokens)) == 4 assert GraphTransliterator.from_yaml(yaml_str).transliterate("ab") == "A,B" - assert ( - GraphTransliterator.from_yaml_file(yaml_filename).transliterate("ab") == "A,B" - ) + assert GraphTransliterator.from_yaml_file(yaml_filename).transliterate("ab") == "A,B" assert ( GraphTransliterator.from_easyreading_dict( { @@ -530,10 +520,7 @@ def test_GraphTransliterator_ignore_errors(): token_class: wb """ # check that ignore_errors works - assert ( - GraphTransliterator.from_yaml(yaml_str, ignore_errors=True).transliterate("a") - == "" - ) + assert GraphTransliterator.from_yaml(yaml_str, ignore_errors=True).transliterate("a") == "" with pytest.raises(NoMatchingTransliterationRuleException): gt = GraphTransliterator.from_yaml(yaml_str, ignore_errors=False) @@ -597,9 +584,7 @@ def test_GraphTransliterator_productions(): whitespace = {"default": " ", "token_class": "wb", "consolidate": True} rules = {"ab": "AB", " ": "_"} settings = {"tokens": tokens, "rules": rules, "whitespace": whitespace} - assert set(GraphTransliterator.from_easyreading_dict(settings).productions) == set( - ["AB", "_"] - ) + assert set(GraphTransliterator.from_easyreading_dict(settings).productions) == set(["AB", "_"]) def test_GraphTransliterator_pruned_of(): diff --git a/tests/test_transliterators.py b/tests/test_transliterators.py index a138ab70..3f03ce1e 100644 --- a/tests/test_transliterators.py +++ b/tests/test_transliterators.py @@ -15,9 +15,7 @@ def init_test_class(self, method=method, coverage=True): self._module_name = transliterator._module_name self._init_from(method, check_ambiguity=True, coverage=True) - class_name = "Test{}From{}".format( - type(transliterator).__name__, method.upper() - ) + class_name = "Test{}From{}".format(type(transliterator).__name__, method.upper()) SuperClass = transliterator.__class__ TestClass = type(class_name, (SuperClass,), {"__init__": init_test_class}) # Confirm it is a subclass of super class @@ -57,11 +55,7 @@ def test_iter_names(): def test_iter_transliterators(): """Test transliterators.iter_transliterators().""" - example = [ - _ - for _ in transliterators.iter_transliterators() - if type(_).__name__ == "Example" - ].pop() + example = [_ for _ in transliterators.iter_transliterators() if type(_).__name__ == "Example"].pop() assert example.transliterate("a") == "A"