Repository: webscopeio/license.sh

Issue:
Filter_dep_tree not working
Filter_dep_tree function only checks for attribute presence and not its value, this makes this function not working on current version of the code and the attributes are always there

Discussion:

Patch:
diff --git a/license_sh/helpers.py b/license_sh/helpers.py
index 061bde3..3389ef7 100644
--- a/license_sh/helpers.py
+++ b/license_sh/helpers.py
@@ -271,9 +271,9 @@ def filter_dep_tree(tree: AnyNode) -> AnyNode:
     treeCopy = DictImporter().import_(DictExporter().export(tree))
     for node in LevelOrderIter(treeCopy):
         node.children = filter(
-            lambda subnode: hasattr(subnode, "subtree_problem")
-            or hasattr(subnode, "license_problem")
-            or hasattr(subnode, "analyze_problem"),
+            lambda subnode: getattr(subnode, "subtree_problem", False)
+            or getattr(subnode, "license_problem", False)
+            or getattr(subnode, "analyze_problem", False),
             node.children,
         )
 
diff --git a/license_sh/reporters/ConsoleReporter.py b/license_sh/reporters/ConsoleReporter.py
index 5590c6d..3c990a1 100644
--- a/license_sh/reporters/ConsoleReporter.py
+++ b/license_sh/reporters/ConsoleReporter.py
@@ -13,8 +13,8 @@ class ConsoleReporter:
             else:
                 color = (
                     RED
-                    if hasattr(node, "license_problem")
-                    or hasattr(node, "analyze_problem")
+                    if getattr(node, "license_problem", False)
+                    or getattr(node, "analyze_problem", False)
                     else GREEN
                 )
                 normalized_info = (


Test patch:
diff --git a/tests/test_helpers.py b/tests/test_helpers.py
index 67d2e23..4b32f9c 100644
--- a/tests/test_helpers.py
+++ b/tests/test_helpers.py
@@ -8,6 +8,7 @@ from license_sh.helpers import (
     annotate_dep_tree,
     is_license_ok,
     is_analyze_ok,
+    filter_dep_tree,
     parse_license,
     extract_npm_license,
     get_npm_license_from_licenses_array,
@@ -574,6 +575,22 @@ class NpmRunnerTestCase(unittest.TestCase):
         )
         self.assertEqual(is_analyze_ok(node), False)
 
+    def test_filter_dep_tree_simple(self):
+        tree = AnyNode(children=[AnyNode(subtree_problem=False, license_problem=False)])
+        filtered_tree = filter_dep_tree(tree)
+        self.assertEqual(len(filtered_tree.children), 0)
+
+    def test_filter_dep_tree_multiple(self):
+        tree = AnyNode(
+            children=[
+                AnyNode(id="good", subtree_problem=False, license_problem=False),
+                AnyNode(id="node", subtree_problem=False, license_problem=True),
+            ]
+        )
+        filtered_tree = filter_dep_tree(tree)
+        self.assertEqual(len(filtered_tree.children), 1)
+        self.assertEqual(filtered_tree.children[0].id, "node")
+
 
 if __name__ == "__main__":
     unittest.main()