aboutsummaryrefslogtreecommitdiff
path: root/app/tests/test_backends_common.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/tests/test_backends_common.py')
-rw-r--r--app/tests/test_backends_common.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/app/tests/test_backends_common.py b/app/tests/test_backends_common.py
index 3b4e7f9..5bc967a 100644
--- a/app/tests/test_backends_common.py
+++ b/app/tests/test_backends_common.py
@@ -73,5 +73,46 @@ class GitCloneTests(unittest.TestCase):
self.assertEqual(run.call_args[1]["emit"], emit)
+class ParseRequestOptionsTests(unittest.TestCase):
+ """parse_request_options: the shared --option / TUI-field parser."""
+
+ def test_single_item(self):
+ self.assertEqual(common.parse_request_options("speed=1.1"),
+ {"speed": "1.1"})
+
+ def test_comma_and_whitespace_separators_mix(self):
+ self.assertEqual(
+ common.parse_request_options("emotion=neutral, speed=1.1"),
+ {"emotion": "neutral", "speed": "1.1"})
+ self.assertEqual(
+ common.parse_request_options("a=1 b=2\tc=3"),
+ {"a": "1", "b": "2", "c": "3"})
+
+ def test_keys_are_stripped_and_blank_text_is_empty(self):
+ self.assertEqual(common.parse_request_options(" "), {})
+ self.assertEqual(common.parse_request_options(""), {})
+ # Tokens cannot contain whitespace (items split on it), so a lone
+ # "=" with a blank key is the malformed case, caught below.
+ self.assertEqual(common.parse_request_options("speed=1"),
+ {"speed": "1"})
+
+ def test_value_is_kept_verbatim(self):
+ self.assertEqual(
+ common.parse_request_options("url=http://x:8080/path?a=1"),
+ {"url": "http://x:8080/path?a=1"})
+
+ def test_later_duplicates_override_earlier_ones(self):
+ self.assertEqual(common.parse_request_options("a=1,a=2"),
+ {"a": "2"})
+
+ def test_item_without_equals_is_rejected(self):
+ with self.assertRaises(ValueError):
+ common.parse_request_options("emotion=neutral nonsense")
+
+ def test_item_with_a_blank_key_is_rejected(self):
+ with self.assertRaises(ValueError):
+ common.parse_request_options("=value")
+
+
if __name__ == "__main__":
unittest.main()