示例#1
0
 def test_2():
     print("test_2")
     correct_id = "123"
     wrong_id = "666"
     yaml_content = ScenarioTest.yaml_content.replace(
         "%welcome_id%", correct_id).replace(
             "%expected_welcome_id%", wrong_id).replace(
                 "%logger%", "logger").replace(
                     "%timestamp%", "1234")
     thrown = False
     with scen.Scenario(yaml_content) as scenario:
         sys.stderr.write("\n" + str(scenario._data) + "\n")
         scenario.build()
         scenario.step()
         scenario.step()
         scenario.step()
         try:
             # make sure we move to the step receiving the message
             for i in range(50):
                 scenario.step()
             sys.stdout.write("No exception raised.\n")
         except Exception as received_exception:
             expected = ("Failure at index 2 in thread 'fake client'.",)
             thrown = (expected == received_exception.args)
             if (not thrown):
                 sys.stdout.write("Exception different from expectation.\n")
                 print("Received:", received_exception)
             else:
                 sys.stdout.write("Exception matched.\n")
     assert(thrown)
示例#2
0
 def test_1():
     print("test_1")
     correct_id = "123"
     yaml_content = ScenarioTest.yaml_content.replace(
         "%welcome_id%",
         correct_id).replace("%expected_welcome_id%", correct_id).replace(
             "%logger%", "logger").replace("%timestamp%", "1234")
     with scen.Scenario(yaml_content) as scenario:
         sys.stderr.write("\n" + str(scenario._data) + "\n")
         scenario.build()
         scenario.step_all()
示例#3
0
 def test_3():
     print("test_3")
     correct_id = "123"
     yaml_content = ScenarioTest.yaml_content.replace(
         "%welcome_id%",
         correct_id).replace("%expected_welcome_id%", correct_id).replace(
             "%logger%", "logger").replace("%timestamp%", "1234")
     yaml_content = "\n".join(yaml_content.split("\n")[:-2])
     scenario = scen.Scenario(yaml_content)
     try:
         scenario.build()
         thrown = False
     except Exception as expected_exception:
         thrown = (("Only {} value(s) found but 2 expected.".format(1),
                    ) == expected_exception.args)
         print(expected_exception)
     assert (thrown)
示例#4
0
def main(argv=sys.argv[1:]):
    parser = argparse.ArgumentParser(description='Scenario shooter.')
    parser.add_argument('scenario_file', help='YAML scenario file.')
    parser.add_argument('--delay',
                        '-d',
                        help='Delay between steps.',
                        default=0,
                        action="store",
                        metavar="DELAY",
                        type=int)
    parser.add_argument('--verbose',
                        '-v',
                        help='Verbose mode',
                        default=False,
                        action="store_true")
    arguments = parser.parse_args()
    log = logging.getLogger(__name__)
    handler = logging.StreamHandler()
    formatter = logging.Formatter(
        '%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
    handler.setFormatter(formatter)
    log.addHandler(handler)
    if arguments.verbose:
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)
    scen.configure_logging(arguments.verbose)
    scenario_file = arguments.scenario_file
    delay = arguments.delay
    log.debug('Open file "{}" as YAML scenario.'.format(scenario_file))
    log.debug('Time to wait between steps (-d): {}'.format(delay))
    with open(scenario_file, 'r') as yaml_scenario:
        yaml_content = yaml_scenario.read()
        with scen.Scenario(yaml_content) as scenario:
            scenario.build()
            while scenario.has_more_steps:
                log.debug("step")
                scenario.step()
                time.sleep(delay)