Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions austin/format/compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ def main() -> None:

try:
with (
AustinFileReader(args.input) as fin,
open(args.input) as _fin,
open(args.output or args.input, "w") as fout,
):
compress(fin, fout, args.counts)
compress(AustinFileReader(_fin), fout, args.counts)
except FileNotFoundError:
print(f"No such input file: {args.input}")
exit(1)
Expand Down
33 changes: 33 additions & 0 deletions test/format/test_compress.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@

import io
from pathlib import Path
from unittest.mock import patch

import pytest

from austin.format.collapsed_stack import AustinFileReader
from austin.format.compress import compress
from austin.format.compress import main


def test_compress(datapath: Path):
Expand Down Expand Up @@ -58,3 +62,32 @@ def test_compress_counts(datapath: Path):
print(compressed.getvalue())
msg = "Expected sample not found in compressed output"
raise AssertionError(msg)


def test_compress_main(datapath: Path, tmp_path: Path):
output = tmp_path / "output.out"
with patch(
"sys.argv", ["austin-compress", str(datapath / "austin.out"), str(output)]
):
main()
assert output.exists()
assert output.stat().st_size > 0


def test_compress_main_counts(datapath: Path, tmp_path: Path):
output = tmp_path / "output_counts.out"
with patch(
"sys.argv",
["austin-compress", "--counts", str(datapath / "austin.out"), str(output)],
):
main()
assert output.exists()


def test_compress_main_missing_file(tmp_path: Path):
missing = tmp_path / "nonexistent.out"
output = tmp_path / "out.out"
with patch("sys.argv", ["austin-compress", str(missing), str(output)]):
with pytest.raises(SystemExit) as exc_info:
main()
assert exc_info.value.code == 1
23 changes: 23 additions & 0 deletions test/test_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import asyncio
import sys
from pathlib import Path
from unittest.mock import MagicMock

import pytest
from pytest import raises
Expand Down Expand Up @@ -159,3 +160,25 @@ async def test_async_bad_options():
await austin.start(
["-I", "1000", "python", "-c", "for i in range(1000000): print(i)"]
)


def test_async_terminate_not_running():
austin = TestAsyncAustin()
with raises(AustinError):
austin.terminate()


def test_async_terminate_process_already_gone():
austin = TestAsyncAustin()
mock_proc = MagicMock()
mock_proc.terminate.side_effect = ProcessLookupError
austin._proc = mock_proc
with raises(AustinError):
austin.terminate()


@pytest.mark.asyncio
async def test_async_wait_not_running():
austin = TestAsyncAustin()
with raises(AustinError):
await austin.wait()
39 changes: 39 additions & 0 deletions test/test_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from pytest import raises

from austin.base import AustinState
from austin.errors import AustinError
from austin.simple import SimpleAustin


class _SimpleAustin(SimpleAustin):
def on_sample(self, sample):
pass


def test_is_running_initially_false():
austin = _SimpleAustin()
assert not austin.is_running()


def test_get_arguments_initially_none():
austin = _SimpleAustin()
assert austin.get_arguments() is None


def test_state_initially_not_started():
austin = _SimpleAustin()
assert austin.state is AustinState.NOT_STARTED


def test_check_version_too_old():
austin = _SimpleAustin()
austin._meta["austin"] = "3.9.0"
with raises(AustinError, match="Incompatible Austin version"):
austin._check_version()


def test_check_version_none():
austin = _SimpleAustin()
# _meta has no "austin" key → version returns (0, 0, 0) < minimum
with raises(AustinError):
austin._check_version()
4 changes: 4 additions & 0 deletions test/test_semver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
)
def test_semver(version, semver):
assert _to_semver(version) == semver


def test_semver_none():
assert _to_semver(None) == (0, 0, 0)
12 changes: 12 additions & 0 deletions test/test_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ def assert_binary_path(path: Path):
assert Path(TestSimpleAustin().binary_path).resolve() == path.resolve()


def test_simple_terminate_not_running():
austin = TestSimpleAustin()
with raises(AustinError):
austin.terminate()


def test_simple_wait_not_running():
austin = TestSimpleAustin()
with raises(AustinError):
austin.wait()


def test_binary_path_cwd():
with tempfile.TemporaryDirectory() as tempdir:
old_cwd = Path.cwd()
Expand Down
Loading