Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Miryam-Schwartz committed Dec 8, 2024
1 parent 14aeb94 commit 07d3343
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -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()

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 07d3343

Please sign in to comment.