From ee8fef930ac4b923ccd59f3f05dee069d88bb666 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Fri, 28 Nov 2025 22:09:13 +0100 Subject: [PATCH] test: Fix correct cli option value casting Since we can set the type of the relevant option in the OPTIONS dict, we should also let the cli correctly cast them on parsing, just as the env options do. --- test/test_configuration.py | 32 ++++++++++++++++++++++++++++++++ topen.py | 1 + 2 files changed, 33 insertions(+) create mode 100644 test/test_configuration.py diff --git a/test/test_configuration.py b/test/test_configuration.py new file mode 100644 index 0000000..b40223f --- /dev/null +++ b/test/test_configuration.py @@ -0,0 +1,32 @@ +from pathlib import Path + +import pytest + +from topen import OPTIONS, parse_cli, parse_env, parse_rc + + +class TestCli: + def test_cli_minimum_id(self, monkeypatch): + monkeypatch.setattr("sys.argv", ["topen", "42"]) + assert parse_cli() == {"task_id": "42"} + + def test_cli_options(self, monkeypatch): + monkeypatch.setattr( + "sys.argv", + [ + "topen", + "123", + "--extension", + "txt", + "--editor", + "vim", + "--quiet", + "True", + ], + ) + assert parse_cli() == { + "task_id": "123", + "notes_ext": "txt", + "notes_editor": "vim", + "notes_quiet": True, + } diff --git a/topen.py b/topen.py index b829745..90f99e6 100755 --- a/topen.py +++ b/topen.py @@ -295,6 +295,7 @@ you view the task. dest=key, metavar=opt.metavar, help=opt.help_text, + type=opt.cast or str, default=None, ) args = parser.parse_args()