diff --git a/.github/workflows/ufm_log_analyzer_ci_workflow.yml b/.github/workflows/ufm_log_analyzer_ci_workflow.yml index dacf3bb1..d487d96b 100644 --- a/.github/workflows/ufm_log_analyzer_ci_workflow.yml +++ b/.github/workflows/ufm_log_analyzer_ci_workflow.yml @@ -76,6 +76,6 @@ jobs: cd $SCRIPT_DIR pip install -r src/loganalyze/requirements.txt - pip install pytest + pip install pytest==8.3.4 pytest unit_tests \ No newline at end of file diff --git a/plugins/ufm_log_analyzer_plugin/unit_tests/conftest.py b/plugins/ufm_log_analyzer_plugin/unit_tests/conftest.py new file mode 100644 index 00000000..cef7aee0 --- /dev/null +++ b/plugins/ufm_log_analyzer_plugin/unit_tests/conftest.py @@ -0,0 +1,19 @@ +# @copyright: +# Copyright © 2013-2024 NVIDIA CORPORATION & AFFILIATES. ALL RIGHTS RESERVED. + +# This software product is a proprietary product of Nvidia Corporation and its affiliates +# (the "Company") and all right, title, and interest in and to the +# software product, including all associated intellectual property rights, +# are and shall remain exclusively with the Company. + +# This software product is governed by the End User License Agreement +# provided with the software product. + +# @author: Miryam Schwartz +# @date: Dec 08, 2024 + +import sys +import os + +sys.path.append(os.getcwd() + "/src") # Add the src directory containing loganalyze +sys.path.append("/".join(os.getcwd().split("/")[:-2])) # Add the root project directory 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 index 4cef5cc9..42294404 100644 --- 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 @@ -12,34 +12,27 @@ # @author: Miryam Schwartz # @date: Dec 08, 2024 - - import pytest -from unittest.mock import MagicMock from loganalyze.log_analyzers.ibdiagnet_log_analyzer import IBDIAGNETLogAnalyzer - -@pytest.fixture -def analyzer(fabric_size_data): - # Mock the constructor of IBDIAGNETLogAnalyzer - mock_analyzer = MagicMock(spec=IBDIAGNETLogAnalyzer) - - # Mock the _log_data_sorted attribute - mock_analyzer._log_data_sorted = fabric_size_data - - # Mock the get_fabric_size method to return the _log_data_sorted attribute - mock_analyzer.get_fabric_size.return_value = fabric_size_data - - # Return the mocked analyzer instance - return mock_analyzer +# Define a test-specific subclass +class TestIBDIAGNETLogAnalyzer(IBDIAGNETLogAnalyzer): + def __init__(self, fabric_size_data): + # Do not call the parent constructor, set up only what's needed for the test + self._log_data_sorted = fabric_size_data @pytest.fixture def fabric_size_data(): # Shared mock data return {"switch_count": 10, "link_count": 50} +@pytest.fixture +def analyzer(fabric_size_data): + # Return an instance of the test-specific subclass + return TestIBDIAGNETLogAnalyzer(fabric_size_data) + def test_get_fabric_size(analyzer, fabric_size_data): # Call the method and check the result result = analyzer.get_fabric_size() - assert result == fabric_size_data, "get_fabric_size should return _log_data_sorted" \ No newline at end of file + assert result == fabric_size_data, "get_fabric_size should return _log_data_sorted"