68 lines
2.9 KiB
Python
68 lines
2.9 KiB
Python
# Copyright 2023 (c) Anna Schumaker.
|
|
"""Tests the `xfstestsdb rename` command."""
|
|
import errno
|
|
import io
|
|
import unittest
|
|
import unittest.mock
|
|
import xfstestsdb.rename
|
|
|
|
|
|
class TestRename(unittest.TestCase):
|
|
"""Tests the `xfstestsdb rename` command."""
|
|
|
|
def setUp(self):
|
|
"""Set up common variables."""
|
|
self.xfstestsdb = xfstestsdb.Command()
|
|
self.rename = self.xfstestsdb.commands["rename"]
|
|
|
|
def test_init(self):
|
|
"""Check that the rename command was set up properly."""
|
|
self.assertIsInstance(self.rename, xfstestsdb.commands.Command)
|
|
self.assertIsInstance(self.rename, xfstestsdb.rename.Command)
|
|
self.assertEqual(self.xfstestsdb.subparser.choices["rename"],
|
|
self.rename.parser)
|
|
|
|
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
|
def test_rename(self, mock_stdout: io.StringIO):
|
|
"""Test the `xfstestsdb rename` command with valid input."""
|
|
self.xfstestsdb.run(["new", "/dev/test"])
|
|
self.xfstestsdb.run(["rename", "1", "/dev/new/name"])
|
|
self.assertRegex(mock_stdout.getvalue(),
|
|
"renamed run #1 device '/dev/test' "
|
|
"to '/dev/new/name'")
|
|
|
|
cur = self.xfstestsdb.sql("SELECT device FROM xfstests_runs "
|
|
"WHERE rowid=1")
|
|
self.assertEqual(cur.fetchone()["device"], "/dev/new/name")
|
|
|
|
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
|
|
def test_rename_same(self, mock_stdout: io.StringIO):
|
|
"""Test the `xfstestsdb rename` command with the same name."""
|
|
self.xfstestsdb.run(["new", "/dev/test"])
|
|
self.xfstestsdb.run(["rename", "1", "/dev/test"])
|
|
self.assertNotRegex(mock_stdout.getvalue(),
|
|
"renamed run #1 device '/dev/test' to '/dev/test'")
|
|
|
|
@unittest.mock.patch("sys.stderr", new_callable=io.StringIO)
|
|
def test_rename_error(self, mock_stderr: io.StringIO):
|
|
"""Test the `xfstestsdb rename` command with invalid input."""
|
|
with self.assertRaises(SystemExit):
|
|
self.xfstestsdb.run(["rename"])
|
|
self.assertRegex(mock_stderr.getvalue(),
|
|
"error: the following arguments are required: runid")
|
|
|
|
with self.assertRaises(SystemExit):
|
|
self.xfstestsdb.run(["rename", "3"])
|
|
self.assertRegex(mock_stderr.getvalue(),
|
|
"error: the following arguments are required: name")
|
|
|
|
@unittest.mock.patch("sys.stderr", new_callable=io.StringIO)
|
|
def test_rename_enoent(self, mock_stderr: io.StringIO):
|
|
"""Test the `xfstestsdb rename` command with an invalid runid."""
|
|
with self.assertRaises(SystemExit) as sys_exit:
|
|
self.xfstestsdb.run(["rename", "2", "/dev/new/name"])
|
|
|
|
self.assertEqual(sys_exit.exception.code, errno.ENOENT)
|
|
self.assertRegex(mock_stderr.getvalue(),
|
|
"error: run #2 does not exist")
|