mirror of
https://github.com/onyx-and-iris/slobs-cli.git
synced 2026-04-18 15:03:45 +00:00
upd tests to check exit_code and err output instead of exceptions
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import anyio
|
||||
import asyncclick as click
|
||||
import pytest
|
||||
from asyncclick.testing import CliRunner
|
||||
|
||||
@@ -13,17 +12,14 @@ async def test_stream_start():
|
||||
assert result.exit_code == 0
|
||||
active = "Stream is currently active." in result.output
|
||||
|
||||
result = await runner.invoke(cli, ["stream", "start"])
|
||||
if not active:
|
||||
result = await runner.invoke(cli, ["stream", "start"])
|
||||
assert result.exit_code == 0
|
||||
assert "Stream started" in result.output
|
||||
await anyio.sleep(1) # Allow some time for the stream to start
|
||||
await anyio.sleep(0.2) # Allow some time for the stream to start
|
||||
else:
|
||||
with pytest.raises(ExceptionGroup) as exc_info:
|
||||
result = await runner.invoke(
|
||||
cli, ["stream", "start"], catch_exceptions=False
|
||||
)
|
||||
assert exc_info.group_contains(click.Abort, match="Stream is already active.")
|
||||
assert result.exit_code != 0
|
||||
assert "Stream is already active." in result.output
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@@ -33,14 +29,11 @@ async def test_stream_stop():
|
||||
assert result.exit_code == 0
|
||||
active = "Stream is currently active." in result.output
|
||||
|
||||
result = await runner.invoke(cli, ["stream", "stop"])
|
||||
if active:
|
||||
result = await runner.invoke(cli, ["stream", "stop"])
|
||||
assert result.exit_code == 0
|
||||
assert "Stream stopped" in result.output
|
||||
await anyio.sleep(1) # Allow some time for the stream to stop
|
||||
await anyio.sleep(0.2) # Allow some time for the stream to stop
|
||||
else:
|
||||
with pytest.raises(ExceptionGroup) as exc_info:
|
||||
result = await runner.invoke(
|
||||
cli, ["stream", "stop"], catch_exceptions=False
|
||||
)
|
||||
assert exc_info.group_contains(click.Abort, match="Stream is already inactive.")
|
||||
assert result.exit_code != 0
|
||||
assert "Stream is already inactive." in result.output
|
||||
|
||||
Reference in New Issue
Block a user