Test suite info generator using robot api

Changes:
     - Use newer method using TestSuiteBuilder & SuiteVisitor
       to print test name, tags, docs.
     - Add TestPrint class to print the test data.

Tested:
      - Ran from sandbox with
        Robot Framework 7.2.2 (Python 3.10.12 on linux)
        Robot Framework 7.1.1 (Python 3.12.9 on linux)
        Robot Framework 7.2.2 (Python 3.12.9 on linux)

Resolves openbmc/openbmc-test-automation/issues#2256

Change-Id: Ic2913f258a062c43d6668f95319494af1584444b
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
diff --git a/bin/generate_testsuite_info.py b/bin/generate_testsuite_info.py
index 1847308..ba11ae1 100755
--- a/bin/generate_testsuite_info.py
+++ b/bin/generate_testsuite_info.py
@@ -2,13 +2,13 @@
 
 r"""
 Use robot framework API to extract test data from test suites.
-Refer to https://robot-framework.readthedocs.io/en/3.0.1/autodoc/robot.parsing.html
+Refer to https://robot-framework.readthedocs.io/en/latest/autodoc/robot.running.html
 """
 
 import os
 import sys
 
-from robot.parsing.model import TestData
+from robot.api import SuiteVisitor, TestSuiteBuilder
 
 sys.path.append(os.path.join(os.path.dirname(__file__), "../lib"))
 
@@ -54,6 +54,27 @@
 stock_list = [("test_mode", 0), ("quiet", 0), ("debug", 0)]
 
 
+class TestPrint(SuiteVisitor):
+
+    def __init__(self, option):
+        self.option = option
+
+    def visit_test(self, test):
+        r"""
+        Print the test data from suite test object from option specified.
+        """
+        if self.option == "name":
+            print(test.name)
+        elif self.option == "tags":
+            print(test.tags)
+        elif self.option == "doc":
+            print(test.doc)
+        elif self.option == "all":
+            print(test.name)
+            print(test.tags)
+            print(test.doc)
+
+
 def exit_function(signal_number=0, frame=None):
     r"""
     Execute whenever the program ends normally or with the signals that we
@@ -119,7 +140,7 @@
         print(file_path)
         if "__init__.robot" in file_path:
             continue
-        test_suite_obj = TestData(parent=None, source=file_path)
+        test_suite_obj = TestSuiteBuilder().build(file_path)
         parse_test_file(test_suite_obj, option)
 
 
@@ -138,17 +159,7 @@
                       "tags" or "doc".
     """
 
-    for testcase in test_suite_obj.testcase_table:
-        if option == "name":
-            print(testcase.name)
-        elif option == "tags":
-            print(testcase.tags)
-        elif option == "doc":
-            print(testcase.doc)
-        elif option == "all":
-            print(testcase.name)
-            print(testcase.tags)
-            print(testcase.doc)
+    test_suite_obj.visit(TestPrint(option))
 
 
 def main():