Source code for testoot.user_interactions

from testoot.base import TestootTestResult, UserInteraction


[docs]class ConsoleUserInteraction(UserInteraction): """Interactive console canonization asker."""
[docs] def ask_canonize(self, test_result: TestootTestResult) -> bool: """Prints diff and asks user to canonize diff. If get `y` returns True.""" diff = test_result.format_diff() self.show_diff(diff) answer = self._ask_user_canonize() return self.parse_input(answer)
[docs] @staticmethod def show_diff(diff: str): print(diff)
[docs] @staticmethod def parse_input(value: str) -> bool: return value.lower() in ('y',)
@staticmethod def _ask_user_canonize() -> str: return input("Canonize [yn]? ") # pragma: no cover
[docs]class ConstantUserInteraction(UserInteraction): """Have constant response to all canonize requests."""
[docs] def __init__(self, *, canonize): self.canonize = canonize
[docs] def ask_canonize(self, test_result: TestootTestResult) -> bool: """Returns stored `canonize` value.""" return self.canonize