-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·35 lines (26 loc) · 1.3 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import unittest
from dcsm import DCSMTemplate
class TestDCSMTemplate(unittest.TestCase):
def test_braced_pattern(self) -> None:
template = DCSMTemplate("Value: $DCSM{var}")
self.assertEqual(template.substitute(var="123"), "Value: 123")
def test_named_pattern(self) -> None:
template = DCSMTemplate("Name: $DCSM_NAME")
self.assertEqual(template.substitute(NAME="John"), "Name: John")
def test_escaped_braced(self) -> None:
template = DCSMTemplate("Escaped: $$DCSM{VAR}")
self.assertEqual(template.substitute(), "Escaped: $DCSM{VAR}")
def test_notpattern(self) -> None:
template = DCSMTemplate("Not a pattern: $DCSMVAR")
self.assertEqual(template.substitute(), "Not a pattern: $DCSMVAR")
def test_escaped_named(self) -> None:
template = DCSMTemplate("Escaped: $$DCSM_VAR")
self.assertEqual(template.substitute(), "Escaped: $DCSM_VAR")
def test_invalid_braced(self) -> None:
template = DCSMTemplate("Invalid: $DCSM{}")
self.assertEqual(template.safe_substitute(), "Invalid: $DCSM{}")
def test_invalid_named(self) -> None:
template = DCSMTemplate("Invalid: $DCSM_name")
self.assertEqual(template.safe_substitute(), "Invalid: $DCSM_name")
if __name__ == "__main__":
unittest.main()