Debian Codegraph @

test/integration/targets/ansible-test-integration-targets/test.py

raw ◀ ▶
1 Debian patch touch this file
•1 #!/usr/bin/env python3
2 from __future__ import annotations
3
4 import subprocess
5 import unittest
6
7
8 class OptionsTest(unittest.TestCase):
9 options = (
10 'unsupported',
11 'disabled',
12 'unstable',
13 'destructive',
14 )
15
16 def test_options(self):
17 for option in self.options:
18 with self.subTest(option=option):
19 try:
20 command = ['ansible-test', 'integration', '--list-targets']
21
22 skip_all = subprocess.run([*command, f'{option}_a', f'{option}_b'], text=True, capture_output=True, check=True)
23 allow_all = subprocess.run([*command, f'--allow-{option}', f'{option}_a', f'{option}_b'], text=True, capture_output=True, check=True)
24 allow_first = subprocess.run([*command, f'{option}/{option}_a', f'{option}_b'], text=True, capture_output=True, check=True)
25 allow_last = subprocess.run([*command, f'{option}_a', f'{option}/{option}_b'], text=True, capture_output=True, check=True)
26
27 self.assertEqual(skip_all.stdout.splitlines(), [])
28 self.assertEqual(allow_all.stdout.splitlines(), [f'{option}_a', f'{option}_b'])
29 self.assertEqual(allow_first.stdout.splitlines(), [f'{option}_a'])
30 self.assertEqual(allow_last.stdout.splitlines(), [f'{option}_b'])
31 except subprocess.CalledProcessError as ex:
32 raise Exception(f'{ex}:\n>>> Standard Output:\n{ex.stdout}\n>>> Standard Error:\n{ex.stderr}') from ex
33
34
35 class PrefixesTest(unittest.TestCase):
36 def test_prefixes(self):
37 try:
38 command = ['ansible-test', 'integration', '--list-targets']
39
40 something = subprocess.run([*command, 'something/'], text=True, capture_output=True, check=True)
41
42 self.assertEqual(something.stdout.splitlines(), ['one-part_test', 'two_part_test'])
43 except subprocess.CalledProcessError as ex:
44 raise Exception(f'{ex}:\n>>> Standard Output:\n{ex.stdout}\n>>> Standard Error:\n{ex.stderr}') from ex
45
46
47 if __name__ == '__main__':
48 unittest.main()