# Path: website/macro.py
# class Macro:
#     def __init__(self, key_pattern=None, replace_value=None):
#         self.key_pattern = key_pattern
#         self.replace_value = replace_value
# 
#     def replace_text(self, text):
#         return text.replace(self.key_pattern, self.replace_value)
# 
# class DateMacro(Macro):
#     def replace_text(self, text):
#         pattern = r"<DATEID(-)?(\d+)?>"
#         while re.search(pattern, text) is not None:
#             re_comp = re.search(pattern, text)
#             if re_comp.groups()[1] is None:
#                 days_delta = 0
#             else:
#                 days_delta = int(re_comp.groups()[1])
#             if re_comp.groups()[0] is not None:
#                 days_delta = -1 * days_delta
#             d = timedelta(days=days_delta)
#             date_replace = str(date.today() + d)
#             text = re.sub(re_comp.group(), date_replace, text)
#         return text


from unittest import TestCase
from datetime import date, timedelta
from website.macro import Macro, DateMacro  # , TableMacro


class TestMacro(TestCase):
    def test_replace(self):
        text = "Sample Text ABC"
        macro = Macro('ABC', '123')
        new_text = macro.replace_text(text)
        self.assertEqual(
            new_text,
            "Sample Text 123")

    def test_date(self):
        text = "Sample Text <DATEID> <DATEID-1>"

# Path: website/macro.py
# class Macro:
#     def __init__(self, key_pattern=None, replace_value=None):
#         self.key_pattern = key_pattern
#         self.replace_value = replace_value
# 
#     def replace_text(self, text):
#         return text.replace(self.key_pattern, self.replace_value)
# 
# class DateMacro(Macro):
#     def replace_text(self, text):
#         pattern = r"<DATEID(-)?(\d+)?>"
#         while re.search(pattern, text) is not None:
#             re_comp = re.search(pattern, text)
#             if re_comp.groups()[1] is None:
#                 days_delta = 0
#             else:
#                 days_delta = int(re_comp.groups()[1])
#             if re_comp.groups()[0] is not None:
#                 days_delta = -1 * days_delta
#             d = timedelta(days=days_delta)
#             date_replace = str(date.today() + d)
#             text = re.sub(re_comp.group(), date_replace, text)
#         return text


# Path: tests/unit/test_macro.py
from unittest import TestCase
from datetime import date, timedelta
from website.macro import Macro, DateMacro  # , TableMacro



class TestMacro(TestCase):
    def test_replace(self):
        text = "Sample Text ABC"
        macro = Macro('ABC', '123')
        new_text = macro.replace_text(text)
        self.assertEqual(
            new_text,
            "Sample Text 123")

    def test_date(self):
        text = "Sample Text <DATEID> <DATEID-1>"

        macro = DateMacro()