File: test_podman_compose_parse_error.py

package info (click to toggle)
podman-compose 1.5.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,004 kB
  • sloc: python: 10,946; sh: 107; javascript: 48; makefile: 13
file content (66 lines) | stat: -rw-r--r-- 2,135 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# SPDX-License-Identifier: GPL-2.0

import os
import unittest

from tests.integration.test_utils import RunSubprocessMixin
from tests.integration.test_utils import podman_compose_path
from tests.integration.test_utils import test_path


def bad_compose_yaml_path() -> str:
    base_path = os.path.join(test_path(), "parse-error")
    return os.path.join(base_path, "docker-compose-error.yml")


def good_compose_yaml_path() -> str:
    base_path = os.path.join(test_path(), "parse-error")
    return os.path.join(base_path, "docker-compose.yml")


class TestComposeBuildParseError(unittest.TestCase, RunSubprocessMixin):
    def test_no_error(self) -> None:
        try:
            _, err = self.run_subprocess_assert_returncode(
                [podman_compose_path(), "-f", good_compose_yaml_path(), "config"], 0
            )
            self.assertEqual(b"", err)

        finally:
            self.run_subprocess([
                podman_compose_path(),
                "-f",
                bad_compose_yaml_path(),
                "down",
            ])

    def test_simple_parse_error(self) -> None:
        try:
            _, err = self.run_subprocess_assert_returncode(
                [podman_compose_path(), "-f", bad_compose_yaml_path(), "config"], 1
            )
            self.assertIn(b"could not find expected ':'", err)
            self.assertNotIn(b"\nTraceback (most recent call last):\n", err)

        finally:
            self.run_subprocess([
                podman_compose_path(),
                "-f",
                bad_compose_yaml_path(),
                "down",
            ])

    def test_verbose_parse_error_contains_stack_trace(self) -> None:
        try:
            _, err = self.run_subprocess_assert_returncode(
                [podman_compose_path(), "--verbose", "-f", bad_compose_yaml_path(), "config"], 1
            )
            self.assertIn(b"\nTraceback (most recent call last):\n", err)

        finally:
            self.run_subprocess([
                podman_compose_path(),
                "-f",
                bad_compose_yaml_path(),
                "down",
            ])