chore: import upstream snapshot with attribution
CI: cua-driver distro-compat matrix / debian:12 (glibc 2.36) (push) Has been cancelled
CI: SPDX Headers / Check SPDX headers (warn-only) (push) Has been cancelled
CD: Docs MCP Server / build (linux/amd64) (push) Has been cancelled
CD: Docs MCP Server / build (linux/arm64) (push) Has been cancelled
CD: Docs MCP Server / merge (push) Has been cancelled
CI: cua-driver distro-compat matrix / Resolve release version (push) Has been cancelled
CI: cua-driver distro-compat matrix / fedora:41 (glibc 2.40) (push) Has been cancelled
CI: cua-driver distro-compat matrix / rockylinux:9 (glibc 2.34) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:22.04 (glibc 2.35) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:24.04 (glibc 2.39) (push) Has been cancelled
CI: cua-driver distro-compat matrix / Distro compat summary (push) Has been cancelled
CI: Rust Linux unit / Rust Linux unit and compile (push) Has been cancelled
CI: Rust Windows unit / Rust Windows unit and compile (push) Has been cancelled
CI: Nix Linux Rust source / Nix / compositor build (push) Has been cancelled
CI: Nix Linux Rust source / Nix / driver package (push) Has been cancelled
CI: Nix Linux Rust source / Nix / Rust unit tests (push) Has been cancelled
CI: cua-driver distro-compat matrix / debian:12 (glibc 2.36) (push) Has been cancelled
CI: SPDX Headers / Check SPDX headers (warn-only) (push) Has been cancelled
CD: Docs MCP Server / build (linux/amd64) (push) Has been cancelled
CD: Docs MCP Server / build (linux/arm64) (push) Has been cancelled
CD: Docs MCP Server / merge (push) Has been cancelled
CI: cua-driver distro-compat matrix / Resolve release version (push) Has been cancelled
CI: cua-driver distro-compat matrix / fedora:41 (glibc 2.40) (push) Has been cancelled
CI: cua-driver distro-compat matrix / rockylinux:9 (glibc 2.34) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:22.04 (glibc 2.35) (push) Has been cancelled
CI: cua-driver distro-compat matrix / ubuntu:24.04 (glibc 2.39) (push) Has been cancelled
CI: cua-driver distro-compat matrix / Distro compat summary (push) Has been cancelled
CI: Rust Linux unit / Rust Linux unit and compile (push) Has been cancelled
CI: Rust Windows unit / Rust Windows unit and compile (push) Has been cancelled
CI: Nix Linux Rust source / Nix / compositor build (push) Has been cancelled
CI: Nix Linux Rust source / Nix / driver package (push) Has been cancelled
CI: Nix Linux Rust source / Nix / Rust unit tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1 @@
|
||||
"""Utils module tests."""
|
||||
@@ -0,0 +1,95 @@
|
||||
"""Tests for async utilities."""
|
||||
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
from cua_cli.utils.async_utils import run_async
|
||||
|
||||
|
||||
class TestRunAsync:
|
||||
"""Tests for run_async function."""
|
||||
|
||||
def test_runs_coroutine(self):
|
||||
"""Test that coroutine is executed."""
|
||||
|
||||
async def sample_coro():
|
||||
return "result"
|
||||
|
||||
result = run_async(sample_coro())
|
||||
|
||||
assert result == "result"
|
||||
|
||||
def test_returns_correct_value(self):
|
||||
"""Test that return value is correct."""
|
||||
|
||||
async def add(a, b):
|
||||
return a + b
|
||||
|
||||
result = run_async(add(2, 3))
|
||||
|
||||
assert result == 5
|
||||
|
||||
def test_propagates_exception(self):
|
||||
"""Test that exceptions are propagated."""
|
||||
|
||||
async def failing_coro():
|
||||
raise ValueError("Test error")
|
||||
|
||||
with pytest.raises(ValueError) as exc_info:
|
||||
run_async(failing_coro())
|
||||
|
||||
assert "Test error" in str(exc_info.value)
|
||||
|
||||
def test_handles_async_sleep(self):
|
||||
"""Test that async sleep works correctly."""
|
||||
|
||||
async def with_sleep():
|
||||
await asyncio.sleep(0.01)
|
||||
return "done"
|
||||
|
||||
result = run_async(with_sleep())
|
||||
|
||||
assert result == "done"
|
||||
|
||||
def test_handles_nested_coroutines(self):
|
||||
"""Test that nested coroutines work."""
|
||||
|
||||
async def inner():
|
||||
return 42
|
||||
|
||||
async def outer():
|
||||
return await inner()
|
||||
|
||||
result = run_async(outer())
|
||||
|
||||
assert result == 42
|
||||
|
||||
def test_handles_none_result(self):
|
||||
"""Test that None result is handled."""
|
||||
|
||||
async def returns_none():
|
||||
pass
|
||||
|
||||
result = run_async(returns_none())
|
||||
|
||||
assert result is None
|
||||
|
||||
def test_handles_list_result(self):
|
||||
"""Test that list result is handled."""
|
||||
|
||||
async def returns_list():
|
||||
return [1, 2, 3]
|
||||
|
||||
result = run_async(returns_list())
|
||||
|
||||
assert result == [1, 2, 3]
|
||||
|
||||
def test_handles_dict_result(self):
|
||||
"""Test that dict result is handled."""
|
||||
|
||||
async def returns_dict():
|
||||
return {"key": "value"}
|
||||
|
||||
result = run_async(returns_dict())
|
||||
|
||||
assert result == {"key": "value"}
|
||||
@@ -0,0 +1,163 @@
|
||||
"""Tests for output utilities."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from cua_cli.utils.output import (
|
||||
print_error,
|
||||
print_info,
|
||||
print_json,
|
||||
print_success,
|
||||
print_table,
|
||||
print_warning,
|
||||
)
|
||||
|
||||
|
||||
class TestPrintTable:
|
||||
"""Tests for print_table function."""
|
||||
|
||||
def test_prints_table_with_data(self):
|
||||
"""Test printing a table with data."""
|
||||
data = [
|
||||
{"name": "test1", "status": "running"},
|
||||
{"name": "test2", "status": "stopped"},
|
||||
]
|
||||
columns = [("name", "NAME"), ("status", "STATUS")]
|
||||
|
||||
with patch("cua_cli.utils.output.console") as mock_console:
|
||||
print_table(data, columns)
|
||||
|
||||
mock_console.print.assert_called_once()
|
||||
|
||||
def test_handles_empty_data(self):
|
||||
"""Test handling empty data list."""
|
||||
data = []
|
||||
|
||||
with patch("cua_cli.utils.output.console") as mock_console:
|
||||
print_table(data)
|
||||
|
||||
mock_console.print.assert_called_once()
|
||||
# Should print "No data" message
|
||||
call_args = mock_console.print.call_args[0][0]
|
||||
assert "No data" in call_args
|
||||
|
||||
def test_auto_generates_columns(self):
|
||||
"""Test that columns are auto-generated from data keys."""
|
||||
data = [{"foo": "bar", "baz": "qux"}]
|
||||
|
||||
with patch("cua_cli.utils.output.console") as mock_console:
|
||||
print_table(data)
|
||||
|
||||
mock_console.print.assert_called_once()
|
||||
|
||||
def test_handles_missing_keys(self):
|
||||
"""Test handling data items with missing keys."""
|
||||
data = [
|
||||
{"name": "test1", "status": "running"},
|
||||
{"name": "test2"}, # Missing status
|
||||
]
|
||||
columns = [("name", "NAME"), ("status", "STATUS")]
|
||||
|
||||
with patch("cua_cli.utils.output.console") as mock_console:
|
||||
print_table(data, columns)
|
||||
|
||||
mock_console.print.assert_called_once()
|
||||
|
||||
def test_with_title(self):
|
||||
"""Test table with title."""
|
||||
data = [{"name": "test"}]
|
||||
|
||||
with patch("cua_cli.utils.output.console") as mock_console:
|
||||
print_table(data, title="Test Table")
|
||||
|
||||
mock_console.print.assert_called_once()
|
||||
|
||||
|
||||
class TestPrintJson:
|
||||
"""Tests for print_json function."""
|
||||
|
||||
def test_prints_dict(self):
|
||||
"""Test printing a dictionary as JSON."""
|
||||
data = {"key": "value", "number": 42}
|
||||
|
||||
with patch("cua_cli.utils.output.console") as mock_console:
|
||||
print_json(data)
|
||||
|
||||
mock_console.print_json.assert_called_once()
|
||||
|
||||
def test_prints_list(self):
|
||||
"""Test printing a list as JSON."""
|
||||
data = [{"name": "test1"}, {"name": "test2"}]
|
||||
|
||||
with patch("cua_cli.utils.output.console") as mock_console:
|
||||
print_json(data)
|
||||
|
||||
mock_console.print_json.assert_called_once()
|
||||
|
||||
def test_handles_nested_data(self):
|
||||
"""Test printing nested data structures."""
|
||||
data = {
|
||||
"level1": {
|
||||
"level2": {
|
||||
"value": 123,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
with patch("cua_cli.utils.output.console") as mock_console:
|
||||
print_json(data)
|
||||
|
||||
mock_console.print_json.assert_called_once()
|
||||
|
||||
|
||||
class TestPrintError:
|
||||
"""Tests for print_error function."""
|
||||
|
||||
def test_prints_to_stderr(self):
|
||||
"""Test that error is printed to stderr."""
|
||||
with patch("cua_cli.utils.output.error_console") as mock_console:
|
||||
print_error("Test error message")
|
||||
|
||||
mock_console.print.assert_called_once()
|
||||
call_args = mock_console.print.call_args[0][0]
|
||||
assert "Error:" in call_args
|
||||
assert "Test error message" in call_args
|
||||
|
||||
|
||||
class TestPrintSuccess:
|
||||
"""Tests for print_success function."""
|
||||
|
||||
def test_prints_success_message(self):
|
||||
"""Test printing success message."""
|
||||
with patch("cua_cli.utils.output.console") as mock_console:
|
||||
print_success("Operation successful")
|
||||
|
||||
mock_console.print.assert_called_once()
|
||||
call_args = mock_console.print.call_args[0][0]
|
||||
assert "Operation successful" in call_args
|
||||
|
||||
|
||||
class TestPrintWarning:
|
||||
"""Tests for print_warning function."""
|
||||
|
||||
def test_prints_warning_message(self):
|
||||
"""Test printing warning message."""
|
||||
with patch("cua_cli.utils.output.console") as mock_console:
|
||||
print_warning("This is a warning")
|
||||
|
||||
mock_console.print.assert_called_once()
|
||||
call_args = mock_console.print.call_args[0][0]
|
||||
assert "Warning:" in call_args
|
||||
assert "This is a warning" in call_args
|
||||
|
||||
|
||||
class TestPrintInfo:
|
||||
"""Tests for print_info function."""
|
||||
|
||||
def test_prints_info_message(self):
|
||||
"""Test printing info message."""
|
||||
with patch("cua_cli.utils.output.console") as mock_console:
|
||||
print_info("Information message")
|
||||
|
||||
mock_console.print.assert_called_once()
|
||||
call_args = mock_console.print.call_args[0][0]
|
||||
assert "Information message" in call_args
|
||||
Reference in New Issue
Block a user