forked from The-DevOps-Daily/devops-daily
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cli.py
More file actions
108 lines (91 loc) · 2.83 KB
/
test_cli.py
File metadata and controls
108 lines (91 loc) · 2.83 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
"""Basic tests for the CLI module."""
import os
import subprocess
import sys
def test_cli_help():
"""Test that the CLI shows help."""
result = subprocess.run(
[sys.executable, "cli.py", "--help"],
capture_output=True,
text=True,
cwd=os.path.dirname(__file__),
check=True,
)
assert result.returncode == 0
assert "101 Linux Commands CLI" in result.stdout
def test_hello_command():
"""Test the hello command."""
result = subprocess.run(
[sys.executable, "cli.py", "hello", "greet"],
capture_output=True,
text=True,
cwd=os.path.dirname(__file__),
check=True,
)
assert result.returncode == 0
assert "Hello, World!" in result.stdout
def test_hello_command_with_name():
"""Test the hello command with a custom name."""
result = subprocess.run(
[sys.executable, "cli.py", "hello", "greet", "--name", "Linux"],
capture_output=True,
text=True,
cwd=os.path.dirname(__file__),
check=True,
)
assert result.returncode == 0
assert "Hello, Linux!" in result.stdout
def test_hello_help():
"""Test the hello command help."""
result = subprocess.run(
[sys.executable, "cli.py", "hello", "--help"],
capture_output=True,
text=True,
cwd=os.path.dirname(__file__),
check=True,
)
assert result.returncode == 0
assert "Hello command group" in result.stdout
def test_list_command():
"""Test the list command."""
result = subprocess.run(
[sys.executable, "cli.py", "list"],
capture_output=True,
text=True,
cwd=os.path.dirname(__file__),
)
assert "ls - List directory contents." in result.stdout
assert "cd - Change directory." in result.stdout
assert "pwd - Print working directory." in result.stdout
assert "cat - Concatenate and display files." in result.stdout
def test_version_command():
"""Test the version command"""
result = subprocess.run(
[sys.executable, "cli.py", "version"],
capture_output=True,
text=True,
cwd=os.path.dirname(__file__),
)
assert result.returncode == 0
assert "101-linux v" in result.stdout
assert "0.1.0" in result.stdout
def test_version_show_command():
"""Test the version show subcommand."""
result = subprocess.run(
[sys.executable, "cli.py", "version", "show"],
capture_output=True,
text=True,
cwd=os.path.dirname(__file__),
)
assert result.returncode == 0
assert "101-linux v0.1.0" in result.stdout
if __name__ == "__main__":
test_cli_help()
test_hello_command()
test_hello_command_with_name()
test_hello_help()
test_list_command()
test_version_command()
test_version_show_command()
print("✅ All tests passed!")