Anna Schumaker
84a7507998
This command prints out (key, value) pairs for each xunit property in the database. It has options to filter by runid, xunit name, property name, and value. Implements: #14 (`xfstestsdb xunit properties`) Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
186 lines
9.2 KiB
Python
186 lines
9.2 KiB
Python
# Copyright 2023 (c) Anna Schumaker.
|
|
"""Tests the `xfstestsdb xunit properties` command."""
|
|
import io
|
|
import unittest
|
|
import unittest.mock
|
|
import xfstestsdb.xunit.properties
|
|
import tests.xunit
|
|
|
|
|
|
class TestXunitProperties(unittest.TestCase):
|
|
"""Tests the `xfstestsdb xunit properties` command."""
|
|
|
|
def setUp(self):
|
|
"""Set up common variables."""
|
|
self.xfstestsdb = xfstestsdb.Command()
|
|
self.xunit = self.xfstestsdb.commands["xunit"]
|
|
self.properties = self.xunit.commands["properties"]
|
|
|
|
def setup_runs(self, mock_stdout: io.StringIO):
|
|
"""Set up runs in the database and clear stdout."""
|
|
self.xfstestsdb.run(["new", "/dev/vda1"])
|
|
self.xfstestsdb.run(["new", "/dev/vda2"])
|
|
|
|
self.xfstestsdb.run(["xunit", "read", "1", str(tests.xunit.XUNIT_1)])
|
|
self.xfstestsdb.run(["xunit", "read", "2", str(tests.xunit.XUNIT_1),
|
|
"--name", "test-2"])
|
|
|
|
mock_stdout.seek(0)
|
|
mock_stdout.truncate(0)
|
|
|
|
def test_init(self):
|
|
"""Check that the xunit properties command was set up properly."""
|
|
self.assertIsInstance(self.properties, xfstestsdb.commands.Command)
|
|
self.assertIsInstance(self.properties,
|
|
xfstestsdb.xunit.properties.Command)
|
|
self.assertEqual(self.xunit.subparser.choices["properties"],
|
|
self.properties.parser)
|
|
|
|
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
|
def test_list_empty(self, mock_stdout: io.StringIO):
|
|
"""Test printing out an empty property list."""
|
|
self.xfstestsdb.run(["xunit", "properties", "--color", "none"])
|
|
self.assertEqual(mock_stdout.getvalue(), "")
|
|
|
|
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
|
def test_list_properties(self, mock_stdout: io.StringIO):
|
|
"""Test listing properties with default options."""
|
|
self.setup_runs(mock_stdout)
|
|
print()
|
|
self.xfstestsdb.run(["xunit", "properties", "--color", "none"])
|
|
self.assertEqual(mock_stdout.getvalue(),
|
|
"""
|
|
+-----+--------+---------------+---------------------------------+
|
|
| run | xunit | property | value |
|
|
+-----+--------+---------------+---------------------------------+
|
|
| 1 | test-1 | CHECK_OPTIONS | -r -R xunit -g quick |
|
|
| 1 | test-1 | FSTYP | myfs |
|
|
| 1 | test-1 | HOST_OPTIONS | local.config |
|
|
| 1 | test-1 | LOAD_FACTOR | 1 |
|
|
| 1 | test-1 | MOUNT_OPTIONS | -o mountopt1,mountopt2 |
|
|
| 1 | test-1 | OVL_LOWER | ovl-lower |
|
|
| 1 | test-1 | OVL_UPPER | ovl-upper |
|
|
| 1 | test-1 | OVL_WORK | ovl-work |
|
|
| 1 | test-1 | PLATFORM | Linux/x86_64 myhost 6.1.8-arch1 |
|
|
| 1 | test-1 | SCRATCH_DEV | /dev/vdb2 |
|
|
| 1 | test-1 | SCRATCH_MNT | /mnt/scratch |
|
|
| 1 | test-1 | SECTION | -no-sections- |
|
|
| 1 | test-1 | TEST_DEV | /dev/vdb1 |
|
|
| 1 | test-1 | TEST_DIR | /mnt/test |
|
|
| 1 | test-1 | TIME_FACTOR | 1 |
|
|
| 2 | test-2 | CHECK_OPTIONS | -r -R xunit -g quick |
|
|
| 2 | test-2 | FSTYP | myfs |
|
|
| 2 | test-2 | HOST_OPTIONS | local.config |
|
|
| 2 | test-2 | LOAD_FACTOR | 1 |
|
|
| 2 | test-2 | MOUNT_OPTIONS | -o mountopt1,mountopt2 |
|
|
| 2 | test-2 | OVL_LOWER | ovl-lower |
|
|
| 2 | test-2 | OVL_UPPER | ovl-upper |
|
|
| 2 | test-2 | OVL_WORK | ovl-work |
|
|
| 2 | test-2 | PLATFORM | Linux/x86_64 myhost 6.1.8-arch1 |
|
|
| 2 | test-2 | SCRATCH_DEV | /dev/vdb2 |
|
|
| 2 | test-2 | SCRATCH_MNT | /mnt/scratch |
|
|
| 2 | test-2 | SECTION | -no-sections- |
|
|
| 2 | test-2 | TEST_DEV | /dev/vdb1 |
|
|
| 2 | test-2 | TEST_DIR | /mnt/test |
|
|
| 2 | test-2 | TIME_FACTOR | 1 |
|
|
+-----+--------+---------------+---------------------------------+
|
|
""")
|
|
|
|
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
|
def test_list_filter_run(self, mock_stdout: io.StringIO):
|
|
"""Test listing properties beloging to a specific run."""
|
|
self.setup_runs(mock_stdout)
|
|
print()
|
|
self.xfstestsdb.run(["xunit", "properties", "--runid", "1",
|
|
"--color", "none"])
|
|
self.assertEqual(mock_stdout.getvalue(),
|
|
"""
|
|
+-----+--------+---------------+---------------------------------+
|
|
| run | xunit | property | value |
|
|
+-----+--------+---------------+---------------------------------+
|
|
| 1 | test-1 | CHECK_OPTIONS | -r -R xunit -g quick |
|
|
| 1 | test-1 | FSTYP | myfs |
|
|
| 1 | test-1 | HOST_OPTIONS | local.config |
|
|
| 1 | test-1 | LOAD_FACTOR | 1 |
|
|
| 1 | test-1 | MOUNT_OPTIONS | -o mountopt1,mountopt2 |
|
|
| 1 | test-1 | OVL_LOWER | ovl-lower |
|
|
| 1 | test-1 | OVL_UPPER | ovl-upper |
|
|
| 1 | test-1 | OVL_WORK | ovl-work |
|
|
| 1 | test-1 | PLATFORM | Linux/x86_64 myhost 6.1.8-arch1 |
|
|
| 1 | test-1 | SCRATCH_DEV | /dev/vdb2 |
|
|
| 1 | test-1 | SCRATCH_MNT | /mnt/scratch |
|
|
| 1 | test-1 | SECTION | -no-sections- |
|
|
| 1 | test-1 | TEST_DEV | /dev/vdb1 |
|
|
| 1 | test-1 | TEST_DIR | /mnt/test |
|
|
| 1 | test-1 | TIME_FACTOR | 1 |
|
|
+-----+--------+---------------+---------------------------------+
|
|
""")
|
|
|
|
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
|
def test_list_filter_xunit(self, mock_stdout: io.StringIO):
|
|
"""Test listing properties matching an xunit pattern."""
|
|
self.setup_runs(mock_stdout)
|
|
print()
|
|
self.xfstestsdb.run(["xunit", "properties", "--xunit", "*-2",
|
|
"--color", "none"])
|
|
self.assertEqual(mock_stdout.getvalue(),
|
|
"""
|
|
+-----+--------+---------------+---------------------------------+
|
|
| run | xunit | property | value |
|
|
+-----+--------+---------------+---------------------------------+
|
|
| 2 | test-2 | CHECK_OPTIONS | -r -R xunit -g quick |
|
|
| 2 | test-2 | FSTYP | myfs |
|
|
| 2 | test-2 | HOST_OPTIONS | local.config |
|
|
| 2 | test-2 | LOAD_FACTOR | 1 |
|
|
| 2 | test-2 | MOUNT_OPTIONS | -o mountopt1,mountopt2 |
|
|
| 2 | test-2 | OVL_LOWER | ovl-lower |
|
|
| 2 | test-2 | OVL_UPPER | ovl-upper |
|
|
| 2 | test-2 | OVL_WORK | ovl-work |
|
|
| 2 | test-2 | PLATFORM | Linux/x86_64 myhost 6.1.8-arch1 |
|
|
| 2 | test-2 | SCRATCH_DEV | /dev/vdb2 |
|
|
| 2 | test-2 | SCRATCH_MNT | /mnt/scratch |
|
|
| 2 | test-2 | SECTION | -no-sections- |
|
|
| 2 | test-2 | TEST_DEV | /dev/vdb1 |
|
|
| 2 | test-2 | TEST_DIR | /mnt/test |
|
|
| 2 | test-2 | TIME_FACTOR | 1 |
|
|
+-----+--------+---------------+---------------------------------+
|
|
""")
|
|
|
|
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
|
def test_list_filter_properties(self, mock_stdout: io.StringIO):
|
|
"""Test listing properties matching a property key pattern."""
|
|
self.setup_runs(mock_stdout)
|
|
print()
|
|
self.xfstestsdb.run(["xunit", "properties", "--property", "TEST_*",
|
|
"--color", "none"])
|
|
self.assertEqual(mock_stdout.getvalue(),
|
|
"""
|
|
+-----+--------+----------+-----------+
|
|
| run | xunit | property | value |
|
|
+-----+--------+----------+-----------+
|
|
| 1 | test-1 | TEST_DEV | /dev/vdb1 |
|
|
| 1 | test-1 | TEST_DIR | /mnt/test |
|
|
| 2 | test-2 | TEST_DEV | /dev/vdb1 |
|
|
| 2 | test-2 | TEST_DIR | /mnt/test |
|
|
+-----+--------+----------+-----------+
|
|
""")
|
|
|
|
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
|
def test_list_filter_values(self, mock_stdout: io.StringIO):
|
|
"""Test listing properties matching a value pattern."""
|
|
self.setup_runs(mock_stdout)
|
|
print()
|
|
self.xfstestsdb.run(["xunit", "properties", "--value", "*vdb*",
|
|
"--color", "none"])
|
|
self.assertEqual(mock_stdout.getvalue(),
|
|
"""
|
|
+-----+--------+-------------+-----------+
|
|
| run | xunit | property | value |
|
|
+-----+--------+-------------+-----------+
|
|
| 1 | test-1 | SCRATCH_DEV | /dev/vdb2 |
|
|
| 1 | test-1 | TEST_DEV | /dev/vdb1 |
|
|
| 2 | test-2 | SCRATCH_DEV | /dev/vdb2 |
|
|
| 2 | test-2 | TEST_DEV | /dev/vdb1 |
|
|
+-----+--------+-------------+-----------+
|
|
""")
|