예제 #1
0
def complete_scenario_with_then_action_returned():
    story = Story(as_a="Someone", i_want_to="Do Something", so_that="I'm Happy", identity="Some file")
    scenario = story.append_scenario("1", "Something")
    given = scenario.add_given(action_description="I did something", execute_function=lambda: None, args=["s"], kwargs={"a":"b"})
    when = scenario.add_when(action_description="I do something", execute_function=lambda: None, args=["s"], kwargs={"a":"b"})
    then = scenario.add_then(action_description="Something happens", execute_function=lambda: None, args=["s"], kwargs={"a":"b"})
    return then
예제 #2
0
def some_action():
    story = Story(as_a="Someone", i_want_to="Do Something", so_that="I'm Happy", identity="some file")
    scenario = story.append_scenario("1", "Something")
    return scenario.add_given(action_description="Some Action", \
                              execute_function=lambda context, *args, **kwargs: None, \
                              args=["s"], \
                              kwargs={"a":"b"})
예제 #3
0
def test_append_then_adds_to_thens_in_scenario():
    story = Story(as_a="Someone",
                  i_want_to="do something",
                  so_that="something",
                  identity="Some File")
    scenario = Scenario(index="1", title="Something", story=story)
    args = ["a"]
    kwargs = {"extra_args": "something"}
    scenario.add_then("some action", lambda: None, args, kwargs)
    assert len(
        scenario.thens
    ) == 1, "There should be one then in the scenario but there was %d" % len(
        scenario.thens)
예제 #4
0
def test_append_then_adds_right_class_to_thens_in_scenario():
    story = Story(as_a="Someone",
                  i_want_to="do something",
                  so_that="something",
                  identity="Some File")
    scenario = Scenario(index="1", title="Something", story=story)
    args = ["a"]
    kwargs = {"extra_args": "something"}
    scenario.add_then("some action", lambda: None, args, kwargs)
    assert isinstance(
        scenario.thens[0], Action
    ), "There should be one then of type Action in the scenario but there was %s" % scenario.thens[
        0].__class__
def test_story_ellapsed_returns_seconds():
    story = Story(as_a="Someone", i_want_to="Do Something", so_that="I'm Happy", identity="Some File")
    story.start_run()
    time.sleep(0.1)
    story.end_run()

    expected = "0.1"
    ellapsed = "%.1f" % story.ellapsed()
    assert ellapsed == expected, "The ellapsed time should be %s but was %s" % (expected, ellapsed)
예제 #6
0
def test_creating_a_story_starts_with_empty_scenarios():
    story = Story(as_a=None, i_want_to=None, so_that=None, identity="Some File")
    assert story.scenarios == [], "Story should start with no scenarios but was %s" % story.scenarios
예제 #7
0
def test_creating_a_story_starts_with_empty_times():
    story = Story(as_a=None, i_want_to=None, so_that=None, identity="Some File")
    assert story.start_time == None, "Story should start with no start time but was %s" % story.start_time
    assert story.end_time == None, "Story should start with no end time but was %s" % story.end_time
예제 #8
0
def test_creating_a_story_keeps_an_identity():
    expected = "identity"
    story = Story(as_a=None, i_want_to=None, so_that=None, identity=expected)
    assert story.identity == expected, "identity should be %s but was %s" % (expected, story.identity)
예제 #9
0
def test_story_end_run_marks_time():
    story = Story(as_a="Someone", i_want_to="Do Something", so_that="I'm Happy", identity="Some File")
    story.end_run()
    assert story.end_time is not None, "There should be some end time after end_run"
예제 #10
0
def test_mark_story_as_successful():
    story = Story(as_a="Someone", i_want_to="Do Something", so_that="I'm Happy", identity="Some File")
    story.mark_as_successful()
    assert story.status == Status.Successful, "The status should be %s but was %s" % (Status.Successful, story.status)
예제 #11
0
def test_creating_a_story_returns_a_story():
    story = Story(as_a=None, i_want_to=None, so_that=None, identity="Some File")
    assert isinstance(story, Story)
예제 #12
0
def test_append_scenario_adds_right_index_to_scenarios_in_story():
    story = Story(as_a="Someone", i_want_to="Do Something", so_that="I'm Happy", identity="Some File")
    story.append_scenario(index="1", title="Test")
    assert story.scenarios[0].index == "1", "There should be a scenario in the story with index 1 but there was %s" % story.scenarios[0].index
예제 #13
0
def test_append_scenario_adds_right_class_to_scenarios_in_story():
    story = Story(as_a="Someone", i_want_to="Do Something", so_that="I'm Happy", identity="Some File")
    story.append_scenario(index="1", title="Test")
    assert isinstance(story.scenarios[0], Scenario), "There should be an item of class Scenario in the story but there was %s" % story.scenarios[0].__class__
예제 #14
0
def test_append_scenario_adds_to_scenarios_in_story():
    story = Story(as_a="Someone", i_want_to="Do Something", so_that="I'm Happy", identity="Some File")
    story.append_scenario(index="1", title="Test")
    assert len(story.scenarios) == 1, "There should be one scenario in the story but there was %d" % len(story.scenarios)
예제 #15
0
def test_creating_a_story_starts_with_unknown_status():
    story = Story(as_a=None, i_want_to=None, so_that=None, identity="Some File")
    assert story.status == Status.Unknown, "Story should start with Unknown status but was %s" % story.status
예제 #16
0
def test_story_returns_right_repr():
    story = Story(as_a="Someone", i_want_to="Do Something", so_that="I'm Happy", identity="Some File")
    expected = u"Story - As a Someone I want to Do Something So that I'm Happy (0 scenarios) - UNKNOWN"
    assert unicode(story) == expected, "Unicode Expected: %s Actual: %s" % (expected, unicode(story))
    assert str(story) == expected, "Str Expected: %s Actual: %s" % (expected, str(story))
예제 #17
0
def test_story_is_a_status_item():
    story = Story(as_a=None, i_want_to=None, so_that=None, identity="Some File")
    assert isinstance(story, StatusItem)
예제 #18
0
def test_mark_story_as_successful_after_failed_has_no_effect():
    story = Story(as_a="Someone", i_want_to="Do Something", so_that="I'm Happy", identity="Some File")
    story.mark_as_failed()
    story.mark_as_successful()
    assert story.status == Status.Failed, "The status should be %s but was %s" % (Status.Failed, story.status)
예제 #19
0
def test_creating_a_story_keeps_as_a():
    expected = "someone"
    story = Story(as_a=expected, i_want_to=None, so_that=None, identity="Some File")
    assert story.as_a == expected, "As_a should be %s but was %s" % (expected, story.as_a)
예제 #20
0
def test_story_ellapsed_returns_zero_for_non_started_stories():
    story = Story(as_a="Someone", i_want_to="Do Something", so_that="I'm Happy", identity="Some File")

    expected = 0
    ellapsed = int(story.ellapsed())
    assert ellapsed == expected, "The ellapsed time should be %d but was %d" % (expected, ellapsed)
예제 #21
0
def test_creating_a_story_keeps_i_want_to():
    expected = "do"
    story = Story(as_a=None, i_want_to=expected, so_that=None, identity="Some File")
    assert story.i_want_to == expected, "i_want_to should be %s but was %s" % (expected, story.i_want_to)
예제 #22
0
def test_creating_a_story_keeps_so_that():
    expected = "so that"
    story = Story(as_a=None, i_want_to=None, so_that=expected, identity="Some File")
    assert story.so_that == expected, "so_that should be %s but was %s" % (expected, story.so_that)
예제 #23
0
    def parse_story_file(self, story_file_path, settings):
        story_text = self.file_object.read_file(story_file_path)
        story_lines = [line for line in story_text.splitlines() if line.strip() != ""]

        headers = self.assert_header(story_lines, settings.default_culture)
        if not headers:
            return (False, self.language.get('no_header_failure'), None)

        as_a = headers[0]
        i_want_to = headers[1]
        so_that = headers[2]

        current_story = Story(as_a=as_a, i_want_to=i_want_to, so_that=so_that, identity=story_file_path)

        scenario_lines = story_lines[3:]

        current_scenario = None
        offset = 0
        for line_index, line in enumerate(scenario_lines):
            if offset > 0:
                offset -= 1
                continue
            offset = 0
            if self.is_scenario_starter_line(line):
                current_scenario = self.parse_scenario_line(current_story, line, settings)
                current_area = None
                continue

            if self.is_keyword(line, "given"):
                current_area = "given"
                continue
            if self.is_keyword(line, "when"):
                current_area = "when"
                continue
            if self.is_keyword(line, "then"):
                current_area = "then"
                continue

            if current_scenario is None:
                if settings.scenarios_to_run:
                    continue
                else:
                    raise InvalidScenarioError("NoScenario")

            if not current_area:
                raise InvalidScenarioError("NoGivenWhenThen")

            add_method = getattr(current_scenario, "add_%s" % current_area)

            if line.strip().startswith("#"):
                add_method(line, lambda context, *args, **kwargs: None, [], {})
                continue

            action, args, kwargs = self.action_registry.suitable_for(line.strip(), settings.default_culture)
            
            rows = []
            parsed_rows = []
            if line.strip().endswith(':'):
                if line_index >= len(scenario_lines):
                    self.raise_action_not_found_for_line(line, current_scenario, story_file_path)
                
                offset, rows, parsed_rows = self.parse_rows(line_index, 
                                                            line, 
                                                            scenario_lines)
                args=[]

            if not action:
                self.raise_action_not_found_for_line(line, current_scenario, story_file_path)
            
            if not action in self.used_actions:
                self.used_actions.append(action)

            instance = action()
            if kwargs:
                args = []
            instance.number_of_rows = 1
            
            parsed_line = line
            if parsed_rows:
                kwargs['table'] = parsed_rows
                
                for row in rows:
                    parsed_line = parsed_line + "\n%s%s" % ("  " * \
                                (self.get_line_identation(line) + 4),\
                                row)

            add_method(parsed_line, instance.execute, args, kwargs)

        return (True, None, current_story)