-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_init_command.py
More file actions
48 lines (36 loc) · 1.41 KB
/
Copy pathtest_init_command.py
File metadata and controls
48 lines (36 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import argparse
import os
from unittest.mock import patch
from struct_module.commands.init import InitCommand, BASIC_STRUCT_YAML
def test_init_creates_struct_yaml(tmp_path):
parser = argparse.ArgumentParser()
cmd = InitCommand(parser)
target_dir = tmp_path / "proj"
args = parser.parse_args([str(target_dir)])
with patch('builtins.print') as mock_print:
cmd.execute(args)
struct_file = target_dir / '.struct.yaml'
assert struct_file.exists()
content = struct_file.read_text()
# Basic checks for key sections
assert 'pre_hooks:' in content
assert 'post_hooks:' in content
assert 'files:' in content
assert 'README.md' in content
assert 'folders:' in content
assert 'github/workflows/run-struct' in content
def test_init_skips_if_exists(tmp_path):
parser = argparse.ArgumentParser()
cmd = InitCommand(parser)
target_dir = tmp_path / "proj"
target_dir.mkdir(parents=True)
existing = target_dir / '.struct.yaml'
existing.write_text('files: []\n')
args = parser.parse_args([str(target_dir)])
with patch('builtins.print') as mock_print:
cmd.execute(args)
# Should not overwrite existing file
assert existing.read_text() == 'files: []\n'
# Should print a message about skipping
printed = "\n".join(c.args[0] for c in mock_print.call_args_list)
assert '.struct.yaml already exists' in printed