|
| 1 | +import pytest |
| 2 | +from unittest.mock import patch, MagicMock |
| 3 | +from struct_module.commands.generate import GenerateCommand |
| 4 | +from struct_module.commands.info import InfoCommand |
| 5 | +from struct_module.commands.validate import ValidateCommand |
| 6 | +from struct_module.commands.list import ListCommand |
| 7 | +import argparse |
| 8 | + |
| 9 | +@pytest.fixture |
| 10 | +def parser(): |
| 11 | + return argparse.ArgumentParser() |
| 12 | + |
| 13 | +def test_generate_command(parser): |
| 14 | + command = GenerateCommand(parser) |
| 15 | + args = parser.parse_args(['structure.yaml', 'base_path']) |
| 16 | + with patch.object(command, '_create_structure') as mock_create_structure: |
| 17 | + command.execute(args) |
| 18 | + mock_create_structure.assert_called_once() |
| 19 | + |
| 20 | +def test_info_command(parser): |
| 21 | + command = InfoCommand(parser) |
| 22 | + args = parser.parse_args(["github/workflows/pre-commit"]) |
| 23 | + with patch('builtins.print') as mock_print: |
| 24 | + command.execute(args) |
| 25 | + mock_print.assert_called() |
| 26 | + |
| 27 | +def test_list_command(parser): |
| 28 | + command = ListCommand(parser) |
| 29 | + args = parser.parse_args([]) |
| 30 | + with patch('os.walk', return_value=[('root', [], ['file.yaml'])]): |
| 31 | + with patch('builtins.print') as mock_print: |
| 32 | + command.execute(args) |
| 33 | + mock_print.assert_called() |
| 34 | + |
| 35 | +def test_validate_command(parser): |
| 36 | + command = ValidateCommand(parser) |
| 37 | + args = parser.parse_args(['config.yaml']) |
| 38 | + with patch.object(command, '_validate_structure_config') as mock_validate_structure, \ |
| 39 | + patch.object(command, '_validate_folders_config') as mock_validate_folders, \ |
| 40 | + patch.object(command, '_validate_variables_config') as mock_validate_variables, \ |
| 41 | + patch('builtins.open', new_callable=MagicMock) as mock_open, \ |
| 42 | + patch('yaml.safe_load', return_value={ |
| 43 | + 'structure': [], |
| 44 | + 'folders': [], |
| 45 | + 'variables': [] |
| 46 | + }): |
| 47 | + command.execute(args) |
| 48 | + mock_validate_structure.assert_called_once() |
| 49 | + mock_validate_folders.assert_called_once() |
| 50 | + mock_validate_variables.assert_called_once() |
0 commit comments