Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue: 4197123: Add Pytest to the workflow of the LogAnalyzer + issue: 4197133: Add Pytest #287

Merged
merged 14 commits into from
Dec 12, 2024
30 changes: 28 additions & 2 deletions .github/workflows/ufm_log_analyzer_ci_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
pylint:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- name: Checkout code
Expand All @@ -34,7 +34,7 @@ jobs:
pylint --rcfile=src/loganalyze/.pylintrc src/loganalyze

ruff:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04

steps:
- name: Checkout code
Expand All @@ -53,3 +53,29 @@ jobs:
pip install ruff==0.7.3

ruff format --diff --check src/loganalyze

pytest:
runs-on: ubuntu-22.04

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9

- name: Run Pytest
run: |
SCRIPT_DIR="plugins/ufm_log_analyzer_plugin"
# Set PYTHONPATH to include src directory and two levels up for utils
PYTHONPATH="$(realpath $SCRIPT_DIR/src):$(realpath $SCRIPT_DIR/../../)"
export PYTHONPATH

cd $SCRIPT_DIR

pip install -r src/loganalyze/requirements.txt
pip install pytest

pytest unit_tests
5 changes: 4 additions & 1 deletion plugins/ufm_log_analyzer_plugin/src/loganalyze/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ disable=missing-function-docstring,

[DESIGN]
max-locals=20
max-args=8
max-args=8

[unit_tests/*]
disable=protected-access
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,41 @@
# @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 pytest
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")
drorlevy marked this conversation as resolved.
Show resolved Hide resolved

from loganalyze.log_analyzers.ibdiagnet_log_analyzer import IBDIAGNETLogAnalyzer


@pytest.fixture
def analyzer():
# Fixture to initialize the analyzer object
logs_csvs = []
hours = 24
dest_image_path = "/dummy/path"
return IBDIAGNETLogAnalyzer(logs_csvs, hours, dest_image_path)
Miryam-Schwartz marked this conversation as resolved.
Show resolved Hide resolved

def test_get_fabric_size(analyzer):
# Mock the _log_data_sorted attribute
expected_fabric_size = {"switch_count": 10, "link_count": 50} # Example data
analyzer._log_data_sorted = expected_fabric_size

# Call the method and check the result
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the benefit in having this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

result = analyzer.get_fabric_size()
assert result == expected_fabric_size, "get_fabric_size should return _log_data_sorted"
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# @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 pytest
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

@pytest.fixture
def analyzer():
# Fixture to initialize the analyzer object
return UFMTopAnalyzer()

def test_add_analyzer(analyzer):
mock_analyzer_1 = "Analyzer1"
mock_analyzer_2 = "Analyzer2"

# Initially, the list should be empty
assert len(analyzer._analyzers) == 0

# Add first analyzer and check the length
analyzer.add_analyzer(mock_analyzer_1)
assert len(analyzer._analyzers) == 1
assert mock_analyzer_1 in analyzer._analyzers

# Add second analyzer and check the updated length
analyzer.add_analyzer(mock_analyzer_2)
assert len(analyzer._analyzers) == 2
assert mock_analyzer_2 in analyzer._analyzers