diff --git a/plugins/ufm_log_analyzer_plugin/src/loganalyze/log_analyzers/base_analyzer.py b/plugins/ufm_log_analyzer_plugin/src/loganalyze/log_analyzers/base_analyzer.py index a95ca640d..82ef67c82 100644 --- a/plugins/ufm_log_analyzer_plugin/src/loganalyze/log_analyzers/base_analyzer.py +++ b/plugins/ufm_log_analyzer_plugin/src/loganalyze/log_analyzers/base_analyzer.py @@ -185,7 +185,11 @@ def __init__( ): super().__init__(dest_image_path) dataframes = [pd.read_csv(ufm_log) for ufm_log in logs_csvs] - df = pd.concat(dataframes, ignore_index=True) + if dataframes: + df = pd.concat(dataframes, ignore_index=True) + else: + df = pd.DataFrame() # Return an empty DataFrame if dataframes is empty + if sort_timestamp: df[DataConstants.TIMESTAMP] = pd.to_datetime(df[DataConstants.TIMESTAMP]) max_timestamp = df[DataConstants.TIMESTAMP].max() diff --git a/plugins/ufm_log_analyzer_plugin/unit_tests/__init__.py b/plugins/ufm_log_analyzer_plugin/unit_tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/plugins/ufm_log_analyzer_plugin/unit_tests/test_ibdiagnet_log_analyzer.py b/plugins/ufm_log_analyzer_plugin/unit_tests/test_ibdiagnet_log_analyzer.py new file mode 100644 index 000000000..7054f7e40 --- /dev/null +++ b/plugins/ufm_log_analyzer_plugin/unit_tests/test_ibdiagnet_log_analyzer.py @@ -0,0 +1,30 @@ +import unittest +import sys +import os + +sys.path.append(os.getcwd()) +sys.path.append("/".join(os.getcwd().split("/")[:-1])) +sys.path.append("/".join(os.getcwd().split("/")[:-1]) + "/src") + +from loganalyze.log_analyzers.ibdiagnet_log_analyzer import IBDIAGNETLogAnalyzer + + +class TestIBDIAGNETLogAnalyzer(unittest.TestCase): + def setUp(self): + # Example initialization with dummy arguments + self.logs_csvs = [] + self.hours = 24 + self.dest_image_path = "/dummy/path" + self.analyzer = IBDIAGNETLogAnalyzer(self.logs_csvs, self.hours, self.dest_image_path) + + def test_get_fabric_size(self): + # Mock the _log_data_sorted attribute + expected_fabric_size = {"switch_count": 10, "link_count": 50} # Example data + self.analyzer._log_data_sorted = expected_fabric_size # pylint: disable=protected-access + + # Call the method and check the result + result = self.analyzer.get_fabric_size() + self.assertEqual(result, expected_fabric_size) + +if __name__ == "__main__": + unittest.main() diff --git a/plugins/ufm_log_analyzer_plugin/unit_tests/test_log_analyzer.py b/plugins/ufm_log_analyzer_plugin/unit_tests/test_log_analyzer.py deleted file mode 100644 index fd3fd1bbb..000000000 --- a/plugins/ufm_log_analyzer_plugin/unit_tests/test_log_analyzer.py +++ /dev/null @@ -1,5 +0,0 @@ -def test_succeed(): - assert 2 + 2 == 4 # This will pass - -def test_fail(): - assert 2 + 2 == 5 # This will fail diff --git a/plugins/ufm_log_analyzer_plugin/unit_tests/test_ufm_top_analyzer.py b/plugins/ufm_log_analyzer_plugin/unit_tests/test_ufm_top_analyzer.py new file mode 100644 index 000000000..a67e98dfc --- /dev/null +++ b/plugins/ufm_log_analyzer_plugin/unit_tests/test_ufm_top_analyzer.py @@ -0,0 +1,33 @@ +import unittest +import sys +import os + +sys.path.append(os.getcwd()) +sys.path.append("/".join(os.getcwd().split("/")[:-1])) +sys.path.append("/".join(os.getcwd().split("/")[:-1]) + "/src") + +from loganalyze.log_analyzers.ufm_top_analyzer import UFMTopAnalyzer + +class TestUFMTopAnalyzer(unittest.TestCase): + def setUp(self): + self.analyzer = UFMTopAnalyzer() + + def test_add_analyzer(self): + mock_analyzer_1 = "Analyzer1" + mock_analyzer_2 = "Analyzer2" + + # Initially, the list should be empty + self.assertEqual(len(self.analyzer._analyzers), 0) # pylint: disable=protected-access + + # Add first analyzer and check the length + self.analyzer.add_analyzer(mock_analyzer_1) + self.assertEqual(len(self.analyzer._analyzers), 1) # pylint: disable=protected-access + self.assertIn(mock_analyzer_1, self.analyzer._analyzers) # pylint: disable=protected-access + + # Add second analyzer and check the updated length + self.analyzer.add_analyzer(mock_analyzer_2) + self.assertEqual(len(self.analyzer._analyzers), 2) # pylint: disable=protected-access + self.assertIn(mock_analyzer_2, self.analyzer._analyzers) # pylint: disable=protected-access + +if __name__ == "__main__": + unittest.main()