def replace_one(opstr: str, old: str, new: str) -> str:
    """Replace text ensuring that exactly one occurrence is replaced."""
    count = opstr.count(old)
    if count != 1:
        raise Exception(
            f'expected 1 string occurrence; found {count}. String = {old}')
    return opstr.replace(old, new)