Add test files
This commit is contained in:
109
tests/unit/test_cli.py
Normal file
109
tests/unit/test_cli.py
Normal file
@@ -0,0 +1,109 @@
|
||||
import pytest
|
||||
import tempfile
|
||||
import os
|
||||
from click.testing import CliRunner
|
||||
from unittest.mock import patch, MagicMock
|
||||
from pathlib import Path
|
||||
from src.cli.main import cli, analyze, visualize, complexity, deps, export
|
||||
from src.graph.builder import GraphBuilder, GraphType
|
||||
|
||||
|
||||
class TestCLI:
|
||||
def setup_method(self):
|
||||
self.runner = CliRunner()
|
||||
|
||||
def test_cli_help(self):
|
||||
result = self.runner.invoke(cli, ["--help"])
|
||||
assert result.exit_code == 0
|
||||
assert "Usage:" in result.output
|
||||
|
||||
@patch("src.cli.main._parse_files")
|
||||
@patch("src.cli.main._get_parser")
|
||||
def test_analyze_command(self, mock_get_parser, mock_parse_files):
|
||||
mock_parser = MagicMock()
|
||||
mock_get_parser.return_value = mock_parser
|
||||
|
||||
mock_result = MagicMock()
|
||||
mock_result.file_path = Path("/test.py")
|
||||
mock_result.entities = []
|
||||
mock_result.imports = []
|
||||
mock_parse_files.return_value = [mock_result]
|
||||
|
||||
mock_graph_builder = MagicMock()
|
||||
mock_graph_builder.get_nodes.return_value = []
|
||||
|
||||
with patch("src.cli.main.GraphBuilder") as MockGraphBuilder:
|
||||
MockGraphBuilder.return_value = mock_graph_builder
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
result = self.runner.invoke(cli, ["analyze", tmpdir])
|
||||
|
||||
assert result.exit_code == 0
|
||||
|
||||
@patch("src.cli.main._parse_files")
|
||||
@patch("src.cli.main._get_parser")
|
||||
def test_visualize_command(self, mock_get_parser, mock_parse_files):
|
||||
mock_parser = MagicMock()
|
||||
mock_get_parser.return_value = mock_parser
|
||||
|
||||
mock_result = MagicMock()
|
||||
mock_result.file_path = Path("/test.py")
|
||||
mock_result.entities = []
|
||||
mock_result.imports = []
|
||||
mock_parse_files.return_value = [mock_result]
|
||||
|
||||
mock_graph_builder = MagicMock()
|
||||
mock_graph_builder.get_nodes.return_value = []
|
||||
|
||||
with patch("src.cli.main.GraphBuilder") as MockGraphBuilder:
|
||||
MockGraphBuilder.return_value = mock_graph_builder
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
result = self.runner.invoke(visualize, [tmpdir])
|
||||
|
||||
assert result.exit_code == 0
|
||||
|
||||
@patch("src.cli.main._parse_files")
|
||||
@patch("src.cli.main._get_parser")
|
||||
def test_complexity_command(self, mock_get_parser, mock_parse_files):
|
||||
mock_parser = MagicMock()
|
||||
mock_get_parser.return_value = mock_parser
|
||||
|
||||
mock_result = MagicMock()
|
||||
mock_result.file_path = Path("/test.py")
|
||||
mock_result.entities = []
|
||||
mock_result.imports = []
|
||||
mock_parse_files.return_value = [mock_result]
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
result = self.runner.invoke(complexity, [tmpdir])
|
||||
|
||||
assert result.exit_code == 0
|
||||
|
||||
@patch("src.cli.main._parse_files")
|
||||
@patch("src.cli.main._get_parser")
|
||||
def test_deps_command(self, mock_get_parser, mock_parse_files):
|
||||
mock_parser = MagicMock()
|
||||
mock_get_parser.return_value = mock_parser
|
||||
|
||||
mock_result = MagicMock()
|
||||
mock_result.file_path = Path("/test.py")
|
||||
mock_result.entities = []
|
||||
mock_result.imports = []
|
||||
mock_parse_files.return_value = [mock_result]
|
||||
|
||||
mock_graph_builder = MagicMock()
|
||||
mock_graph_builder.get_nodes.return_value = []
|
||||
mock_graph_builder.edges = []
|
||||
|
||||
with patch("src.cli.main.GraphBuilder") as MockGraphBuilder:
|
||||
MockGraphBuilder.return_value = mock_graph_builder
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
result = self.runner.invoke(deps, [tmpdir])
|
||||
|
||||
assert result.exit_code == 0
|
||||
|
||||
def test_verbose_flag(self):
|
||||
result = self.runner.invoke(cli, ["--verbose", "--help"])
|
||||
assert result.exit_code == 0
|
||||
Reference in New Issue
Block a user