Compare commits
3 Commits
0d5ba8b921
...
6a4bbf1e60
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a4bbf1e60 | |||
| 12b6966c8a | |||
| 03c629545e |
@ -1,26 +0,0 @@
|
|||||||
"""
|
|
||||||
Module implementing message related functions and classes.
|
|
||||||
"""
|
|
||||||
from typing import Type, TypeVar
|
|
||||||
|
|
||||||
QuestionInst = TypeVar('QuestionInst', bound='Question')
|
|
||||||
|
|
||||||
|
|
||||||
class MessageError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class Question(str):
|
|
||||||
"""
|
|
||||||
A single question with a defined prefix.
|
|
||||||
"""
|
|
||||||
prefix = '=== QUESTION ==='
|
|
||||||
|
|
||||||
def __new__(cls: Type[QuestionInst], string: str) -> QuestionInst:
|
|
||||||
"""
|
|
||||||
Make sure the tag string does not contain the default separator.
|
|
||||||
"""
|
|
||||||
if cls.prefix in string:
|
|
||||||
raise MessageError(f"Question '{string}' contains the prefix '{cls.prefix}'")
|
|
||||||
instance = super().__new__(cls, string)
|
|
||||||
return instance
|
|
||||||
@ -25,7 +25,7 @@ class Tag(str):
|
|||||||
Make sure the tag string does not contain the default separator.
|
Make sure the tag string does not contain the default separator.
|
||||||
"""
|
"""
|
||||||
if cls.default_separator in string:
|
if cls.default_separator in string:
|
||||||
raise TagError(f"Tag '{string}' contains the separator char '{cls.default_separator}'")
|
raise TypeError(f"Tag '{string}' contains the separator char '{cls.default_separator}'")
|
||||||
instance = super().__new__(cls, string)
|
instance = super().__new__(cls, string)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|||||||
@ -240,7 +240,7 @@ class TestTag(CmmTestCase):
|
|||||||
self.assertEqual(tag, 'mytag')
|
self.assertEqual(tag, 'mytag')
|
||||||
|
|
||||||
def test_invalid_tag(self) -> None:
|
def test_invalid_tag(self) -> None:
|
||||||
with self.assertRaises(TagError):
|
with self.assertRaises(TypeError):
|
||||||
Tag('tag with space')
|
Tag('tag with space')
|
||||||
|
|
||||||
def test_default_separator(self) -> None:
|
def test_default_separator(self) -> None:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user