From 9e703b9345cffd90d723e0ce5c180a385c75c62e Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Mon, 20 Mar 2023 11:27:50 -0700 Subject: shell: Allow timeouts to have units Related-Change: Ibbe7e5aa8aa8e54935da76109c2ea13fb83bc7ab Change-Id: Ifeaaea790d1dadc84b157a7cf2be7590949c70f0 --- test/unit/test_shell.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test') diff --git a/test/unit/test_shell.py b/test/unit/test_shell.py index 98d73e9..f103246 100644 --- a/test/unit/test_shell.py +++ b/test/unit/test_shell.py @@ -2424,6 +2424,27 @@ class TestDebugAndInfoOptions(unittest.TestCase): % (mock_logging.call_args_list, argv)) +@mock.patch.dict(os.environ, mocked_os_environ) +class TestTimeoutOption(unittest.TestCase): + @mock.patch('swiftclient.service.Connection') + def test_timeout_parsing(self, connection): + for timeout, expected in ( + ("12", 12), + ("12.3", 12.3), + ("5s", 5), + ("25.6s", 25.6), + ("2m", 120), + ("2.5min", 150), + ("1h", 3600), + (".5hr", 1800), + ): + connection.reset_mock() + with self.subTest(timeout=timeout): + swiftclient.shell.main(["", "stat", "--timeout", timeout]) + self.assertEqual(connection.mock_calls[0].kwargs['timeout'], + expected) + + class TestBase(unittest.TestCase): """ Provide some common methods to subclasses -- cgit v1.2.1