File: test.py

package info (click to toggle)
ansible-core 2.19.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,944 kB
  • sloc: python: 181,408; cs: 4,929; sh: 4,661; xml: 34; makefile: 21
file content (48 lines) | stat: -rwxr-xr-x 2,133 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python3
from __future__ import annotations

import subprocess
import unittest


class OptionsTest(unittest.TestCase):
    options = (
        'unsupported',
        'disabled',
        'unstable',
        'destructive',
    )

    def test_options(self):
        for option in self.options:
            with self.subTest(option=option):
                try:
                    command = ['ansible-test', 'integration', '--list-targets']

                    skip_all = subprocess.run([*command, f'{option}_a', f'{option}_b'], text=True, capture_output=True, check=True)
                    allow_all = subprocess.run([*command, f'--allow-{option}', f'{option}_a', f'{option}_b'], text=True, capture_output=True, check=True)
                    allow_first = subprocess.run([*command, f'{option}/{option}_a', f'{option}_b'], text=True, capture_output=True, check=True)
                    allow_last = subprocess.run([*command, f'{option}_a', f'{option}/{option}_b'], text=True, capture_output=True, check=True)

                    self.assertEqual(skip_all.stdout.splitlines(), [])
                    self.assertEqual(allow_all.stdout.splitlines(), [f'{option}_a', f'{option}_b'])
                    self.assertEqual(allow_first.stdout.splitlines(), [f'{option}_a'])
                    self.assertEqual(allow_last.stdout.splitlines(), [f'{option}_b'])
                except subprocess.CalledProcessError as ex:
                    raise Exception(f'{ex}:\n>>> Standard Output:\n{ex.stdout}\n>>> Standard Error:\n{ex.stderr}') from ex


class PrefixesTest(unittest.TestCase):
    def test_prefixes(self):
        try:
            command = ['ansible-test', 'integration', '--list-targets']

            something = subprocess.run([*command, 'something/'], text=True, capture_output=True, check=True)

            self.assertEqual(something.stdout.splitlines(), ['one-part_test', 'two_part_test'])
        except subprocess.CalledProcessError as ex:
            raise Exception(f'{ex}:\n>>> Standard Output:\n{ex.stdout}\n>>> Standard Error:\n{ex.stderr}') from ex


if __name__ == '__main__':
    unittest.main()