From dd5034ceaaa768c290375b0083d3f79c2385ef60 Mon Sep 17 00:00:00 2001 From: "Bradley A. Thornton" Date: Tue, 12 Sep 2023 13:57:14 -0700 Subject: [PATCH] Rename test --- src/pip4a/tree.py | 13 +++---------- tests/unit/test_tree.py | 9 +++++---- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/pip4a/tree.py b/src/pip4a/tree.py index 29d3737..d406eb9 100644 --- a/src/pip4a/tree.py +++ b/src/pip4a/tree.py @@ -80,19 +80,12 @@ def in_color(self: Tree, val: ScalarVal) -> str: "yellow", ) start = "" - if val == "four": - pass + val_str = str(val) for ansi in ansis: matches = getattr(self, ansi) - try: - index = matches.index(val) - except ValueError: - continue - - if isinstance(val, type(matches[index])): + if val_str in [str(match) for match in matches]: start += getattr(Ansi, ansi.upper()) - - return f"{start}{val}{Ansi.RESET}" + return f"{start}{val_str}{Ansi.RESET}" @staticmethod def is_scalar(obj: JSONVal) -> bool: diff --git a/tests/unit/test_tree.py b/tests/unit/test_tree.py index ecae83f..8a78f9e 100644 --- a/tests/unit/test_tree.py +++ b/tests/unit/test_tree.py @@ -14,7 +14,7 @@ from pip4a.tree import JSONVal -sample: JSONVal = { +sample_1: JSONVal = { "key_one": "one", "key_two": 42, "key_three": True, @@ -100,10 +100,11 @@ def test_tree_large(monkeypatch: pytest.MonkeyPatch) -> None: """Test the tree generator.""" monkeypatch.setenv("NO_COLOR", "true") - assert Tree(sample).render() == result + assert Tree(sample_1).render() == result -sample = { + +sample_2: JSONVal = { "key_one": True, "key_two": 42, "key_three": None, @@ -132,7 +133,7 @@ def test_tree_large(monkeypatch: pytest.MonkeyPatch) -> None: def test_tree_color() -> None: """Test the tree generator.""" - tree = Tree(sample) + tree = Tree(sample_2) tree.blue = ["key_one", "key_two", "key_three", "key_four"] tree.green = [True, 42, None, "four"] rendered = tree.render().splitlines()