File: util.py

package info (click to toggle)
tina 0.1.14-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 920 kB
  • sloc: ansic: 1,653; sh: 1,415; python: 1,189; makefile: 42
file content (37 lines) | stat: -rw-r--r-- 1,011 bytes parent folder | download
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
# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
# SPDX-License-Identifier: GPL-2.0-or-later
"""Helper functions for the `tina-convert` unit tests."""

from __future__ import annotations

import subprocess  # noqa: S404
import typing

import pytest

from unit import util as t_util


if typing.TYPE_CHECKING:
    import pathlib


def list_formats(prog: pathlib.Path) -> list[str]:
    """Run `tina-convert list formats`, validate some of the output."""
    match subprocess.check_output(  # noqa: S603
        [prog, "list", "formats"],
        encoding="UTF-8",
        env=t_util.get_utf8_env(),
    ).splitlines():
        case [single]:
            match single.split(" "):
                case ["Formats:", *formats]:
                    assert "tina" in formats
                    assert all(word for word in formats)
                    return sorted(formats)

                case other:
                    pytest.fail(repr(other))

        case other:
            pytest.fail(repr(other))