Skip to content

Commit 03c0e11

Browse files
committed
Corrección completa de tests y formateo
1 parent b06c2f7 commit 03c0e11

2 files changed

Lines changed: 32 additions & 45 deletions

File tree

.github/workflows/main.yml

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,24 @@
1-
name: CI
2-
on: [push]
3-
jobs:
4-
test:
5-
runs-on: ubuntu-latest
6-
steps:
7-
uses: actions/download-artifact@v4.2.1
8-
with:
9-
pattern: 'report-*.json'
10-
path: ./custom_reports/
11-
merge-multiple: true
12-
github-token: ${{ secrets.CI_CD_TOKEN }}
13-
repository: mechmind-dwv/-MechanicalMind-Dependency-AI-v2.0-
14-
run-id: ${{ github.event.workflow_run.id }}
15-
on:
16-
workflow_run:
17-
workflows: ["Dependency Analysis"]
18-
types:
19-
- completed
1+
name: CI Pipeline
202

21-
jobs:
22-
build:
23-
runs-on: ubuntu-latest
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
2412
steps:
2513
- uses: actions/checkout@v4
26-
27-
- name: Upload artifact
28-
uses: actions/upload-artifact@v3
14+
- name: Set up Python
15+
uses: actions/setup-python@v4
2916
with:
30-
name: dependency-report
31-
path: ./reports/
32-
env:
33-
GITHUB_TOKEN: ${{ secrets.GH_ARTIFACT_ACCESS_TOKEN }}
34-
- name: Process Artifacts
17+
python-version: '3.10'
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install -e .
22+
- name: Run tests
3523
run: |
36-
echo "Processing downloaded artifacts..."
37-
python ai_core/artifact_processor.py \
38-
--input "${{ runner.temp }}/artifacts" \
39-
--output ./reports/
40-
[![.github/workflows/main.yml](https://github.com/mechmind-dwv/-MechanicalMind-Dependency-AI-v2.0-/actions/workflows/main.yml/badge.svg)](https://github.com/mechmind-dwv/-MechanicalMind-Dependency-AI-v2.0-/actions/workflows/main.yml)
24+
python -m pytest

tests/unit_tests/test_knowledge_base.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44
"""
55

66
import json
7+
import time
78
from pathlib import Path
89
from typing import Dict, Any
910
import unittest
1011
from unittest.mock import patch, mock_open
1112
from ai_core.knowledge_base import load_error_knowledge
1213

14+
1315
class TestKnowledgeBase(unittest.TestCase):
1416
"""Caso de prueba para el módulo de base de conocimiento"""
1517

1618
@classmethod
1719
def setUpClass(cls) -> None:
1820
"""Configuración inicial de datos de prueba"""
19-
cls.test_data_dir = Path(__file__).parent / 'test_data'
21+
cls.test_data_dir = Path(__file__).parent / "test_data"
2022
cls.test_data_dir.mkdir(exist_ok=True)
2123

2224
# Archivo válido
@@ -27,26 +29,26 @@ def setUpClass(cls) -> None:
2729
"description": "Test error",
2830
"patterns": ["test pattern"],
2931
"solutions": ["test solution"],
30-
"severity": "low"
32+
"severity": "low",
3133
}
3234
}
3335
}
34-
with open(cls.valid_kb_path, 'w', encoding='utf-8') as f:
36+
with open(cls.valid_kb_path, "w", encoding="utf-8") as f:
3537
json.dump(cls.valid_data, f, indent=2)
3638

3739
# Archivo inválido
3840
cls.invalid_kb_path = cls.test_data_dir / "invalid_knowledge.json"
39-
with open(cls.invalid_kb_path, 'w', encoding='utf-8') as f:
41+
with open(cls.invalid_kb_path, "w", encoding="utf-8") as f:
4042
f.write('{"key": "value"') # JSON incompleto
4143

4244
def test_large_file_performance(self):
4345
"""Test de carga con archivo grande"""
4446
large_data = {"common_errors": {f"ERR{i}": {} for i in range(1000)}}
45-
with patch('builtins.open', mock_open(read_data=json.dumps(large_data))):
46-
start = time.time()
47-
result = load_error_knowledge()
48-
elapsed = time.time() - start
49-
self.assertLess(elapsed, 0.5) # Menos de 500ms
47+
with patch("builtins.open", mock_open(read_data=json.dumps(large_data))):
48+
start = time.time()
49+
result = load_error_knowledge()
50+
elapsed = time.time() - start
51+
self.assertLess(elapsed, 0.5) # Menos de 500ms
5052

5153
def test_load_valid_knowledge(self) -> None:
5254
"""Test Case KB-101: Carga exitosa de conocimiento válido"""
@@ -64,5 +66,6 @@ def test_file_not_found(self) -> None:
6466
with self.assertRaises(ImportError):
6567
load_error_knowledge("non_existent_file.json")
6668

67-
if __name__ == '__main__':
69+
70+
if __name__ == "__main__":
6871
unittest.main(verbosity=2)

0 commit comments

Comments
 (0)