From 54ac0c980a4e7b3b23f676924238ef14c65f0323 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 25 Oct 2024 22:15:24 +0200 Subject: [PATCH] fix: regexp tests --- tests/test_option_regexp.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/test_option_regexp.py diff --git a/tests/test_option_regexp.py b/tests/test_option_regexp.py new file mode 100644 index 0000000..f6ce5bb --- /dev/null +++ b/tests/test_option_regexp.py @@ -0,0 +1,23 @@ +""" RegexpOption +""" +from .autopath import do_autopath +do_autopath() + +import pytest +from tiramisu import RegexpOption, OptionDescription, Config +import re + + +class ColorOption(RegexpOption): + __slots__ = tuple() + _type = 'Color' + _regexp = re.compile(r"^#(?:[0-9a-f]{3}){1,2}$") + + +def test_regexp_option(): + r = ColorOption('test', 'test') + od = OptionDescription('od', 'od', [r]) + cfg = Config(od) + cfg.option('test').value.set('#ff0000') + with pytest.raises(ValueError): + cfg.option('test').value.set('not a color')