Files
scaffoldforge/tests/test_integration.py
7000pctAUTO 3b688684c2
Some checks failed
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
fix: resolve CI linting and type checking errors
2026-02-04 06:04:20 +00:00

114 lines
4.0 KiB
Python

"""End-to-end integration tests for cmdparse CLI."""
from click.testing import CliRunner
from cmdparse.cli import main
class TestCLI:
def test_parse_table_to_json(self):
runner = CliRunner()
input_text = """NAME IMAGE STATUS
nginx nginx:1 running
redis redis:3 stopped"""
result = runner.invoke(main, ["-o", "json", "-q"], input=input_text)
assert result.exit_code == 0
assert "nginx" in result.output
def test_parse_key_value_to_yaml(self):
runner = CliRunner()
input_text = """name: John
age: 30
city: NYC"""
result = runner.invoke(main, ["-o", "yaml", "-q"], input=input_text)
assert result.exit_code == 0
assert "John" in result.output
assert "name" in result.output
def test_parse_csv_to_csv(self):
runner = CliRunner()
input_text = """name,age,city
John,30,NYC"""
result = runner.invoke(main, ["-o", "csv", "-q"], input=input_text)
assert result.exit_code == 0
assert "John" in result.output
def test_field_extraction(self):
runner = CliRunner()
input_text = """NAME IMAGE STATUS
nginx nginx:1 running
redis redis:3 stopped"""
result = runner.invoke(
main, ["-o", "json", "-q", "-e", "NAME", "-e", "STATUS"], input=input_text
)
assert result.exit_code == 0
output = result.output
assert "nginx" in output
assert "running" in output
def test_no_input_error(self):
runner = CliRunner()
result = runner.invoke(main, ["-q"], input="")
assert result.exit_code == 1
assert "error" in result.output.lower() or "input" in result.output.lower()
def test_auto_format_detection(self):
runner = CliRunner()
input_text = """name: John
age: 30"""
result = runner.invoke(main, ["-f", "auto", "-o", "json", "-q"], input=input_text)
assert result.exit_code == 0
assert "John" in result.output
def test_help_option(self):
runner = CliRunner()
result = runner.invoke(main, ["--help"])
assert result.exit_code == 0
assert "--output" in result.output
assert "--field" in result.output
assert "--config" in result.output
def test_parse_raw_text(self):
runner = CliRunner()
input_text = """Some random text line 1
Another line here
Third line"""
result = runner.invoke(main, ["-o", "json", "-q"], input=input_text)
assert result.exit_code == 0
assert "line" in result.output.lower() or "1" in result.output
def test_parse_delimited_semicolon(self):
runner = CliRunner()
input_text = """name;age;city
John;30;NYC"""
result = runner.invoke(main, ["-o", "json", "-q"], input=input_text)
assert result.exit_code == 0
assert "John" in result.output
class TestIntegrationScenarios:
def test_docker_ps_style_output(self):
runner = CliRunner()
input_text = """CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
abc123 nginx:1 "nginx" 1h ago Up 80/tcp nginx"""
result = runner.invoke(main, ["-o", "json", "-q"], input=input_text)
assert result.exit_code == 0
assert "nginx" in result.output
def test_df_style_output(self):
runner = CliRunner()
input_text = """Filesystem Size Used Avail Use% Mounted on
/dev/sda1 100G 50G 50G 50% /"""
result = runner.invoke(main, ["-o", "json", "-q"], input=input_text)
assert result.exit_code == 0
assert "/dev/sda1" in result.output
def test_key_value_with_special_chars(self):
runner = CliRunner()
input_text = """DATABASE_URL=postgresql://user:pass@localhost:5432/db
API_KEY=abc123xyz
DEBUG=true"""
result = runner.invoke(main, ["-o", "yaml", "-q"], input=input_text)
assert result.exit_code == 0
assert "DATABASE_URL" in result.output