Advertisement
PoiSonSonic

Untitled

May 30th, 2020
1,794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1. """
  2. Actors are the stars of the show. They perform your actions, ask questions
  3. about the state of the application, and assert resolutions, all in the
  4. service of perfoming their roles. You can give a curtain call for a new
  5. actor like so:
  6.  
  7.    Perry = AnActor.named("Perry") TODO CHange me
  8. """
  9. from loguru import logger
  10. from screenpy.actor import Actor as OriginalActor
  11.  
  12. from random import choice
  13. from typing import Any, List, Text, Tuple
  14.  
  15. from hamcrest import assert_that
  16.  
  17. from screenpy.exceptions import UnableToPerform
  18. from screenpy.pacing import aside
  19.  
  20. # For type-hinting
  21. Ability = Any
  22. Action = Any
  23. Question = Any
  24. Resolution = Any
  25.  
  26.  
  27. class ModifiedActor(OriginalActor):
  28.     """
  29.    I AM A MODIFIED ACTOR
  30.    Represents an actor, holding their name and abilities. Actors are the
  31.    performers of your screenplay, they represent your users as they go
  32.    about their business on your product.
  33.  
  34.    An actor is meant to be instantiated using its static |Actor.named|
  35.    method. A typical invocation might look like:
  36.  
  37.        Perry = Actor.named("Perry")
  38.  
  39.    This will create the actor, ready to take on their first role.
  40.    """
  41.  
  42.     def should_see_either_or(self, *tests: Tuple[Question, Resolution]) -> None:
  43.         """
  44.        Ask a series of questions, asserting their expected answers.
  45.  
  46.        Args:
  47.            tests: tuples of a |Question| and a |Resolution|.
  48.  
  49.        Raises:
  50.            AssertionError: If the question's actual answer does not match
  51.                the expected answer from the |Resolution|.
  52.        """
  53.         tests_count = len(tests)
  54.         success_count = 0
  55.         failure_count = 0
  56.         for question, test in tests:
  57.             try:
  58.                 assert_that(question.answered_by(self), test)
  59.                 success_count += 1
  60.                 logger.trace(f"Test succeeded, and it's succession #{success_count} out of {tests_count}")
  61.             except AssertionError as e:
  62.                 failure_count += 1
  63.                 logger.warning(f"{e}, and it's failure #{failure_count} out of {tests_count}")
  64.         if success_count < 1:
  65.             logger.error(f"Every test out of {tests} has failed")
  66.             raise AssertionError("Every test has failed")
  67.  
  68.     should_see_that_either_or = should_see_either_or
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement