import re


def test_or_task(text, rpa=False):
    """Replaces `{test}` in `text` with `test` or `task` depending on `rpa`."""
    def replace(match):
        test = match.group(1)
        if not rpa:
            return test
        upper = [c.isupper() for c in test]
        return ''.join(c.upper() if up else c for c, up in zip('task', upper))
    return re.sub('{(test)}', replace, text, flags=re.IGNORECASE)