Beispiel #1
0
def test_parsing_files_with_empty_content_returns_invalid_files_list():

    mocker = Mocker()

    settings = Settings()
    files = ["some path"]

    story_text = ""

    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs,
                        pattern=settings.file_pattern)
    mocker.result(files)
    filemock.read_file(files[0])
    mocker.result(story_text)

    language_mock = mocker.mock()
    language_mock.get("as_a")
    mocker.result("As a")
    language_mock.get("i_want_to")
    mocker.result("I want to")
    language_mock.get("so_that")
    mocker.result("So that")
    language_mock.get("no_header_failure")
    mocker.result("No header found")

    with mocker:
        parser = FileParser(language=language_mock, file_object=filemock)

        fixture = parser.get_stories(settings=settings)
        assert len(fixture.no_story_header) == 1
        file_path = fixture.no_story_header[0]
        assert file_path == "some path"
Beispiel #2
0
def test_parse_block_lines():
    parser = FileParser(None, None, None)

    line_index = 5
    line = "And I see table as:"
    scenario_lines = [
        'Line 1', 'Line 2', 'Line 3', 'Scenario bla', 'Given',
        '    And I see table as:', '        | Name | Age | Sex  |',
        '        | Paul | 28  | Male |', '        | John | 30  | Male |'
    ]
    offset, rows, parsed_rows = parser.parse_rows(line_index, line,
                                                  scenario_lines)

    assert offset == 3
    assert rows == [
        '        | Name | Age | Sex  |', '        | Paul | 28  | Male |',
        '        | John | 30  | Male |'
    ]
    assert parsed_rows == [{
        'Name': 'Paul',
        'Age': '28',
        'Sex': 'Male'
    }, {
        'Name': 'John',
        'Age': '30',
        'Sex': 'Male'
    }]
Beispiel #3
0
def test_parse_scenario_line():

    mocker = Mocker()

    story = Story(as_a="Someone",
                  i_want_to="Do Something",
                  so_that="I'm Happy",
                  identity="some file")

    settings_mock = mocker.mock()
    settings_mock.scenarios_to_run
    mocker.result([])

    language_mock = mocker.mock()
    language_mock.get("scenario")
    mocker.result("Scenario")

    with mocker:
        parser = FileParser(language=language_mock, file_object=None)
        scenario = parser.parse_scenario_line(story,
                                              "Scenario 1 - Doing something",
                                              settings_mock)

        assert scenario is not None
        assert scenario.index == "1", "Expected 1 actual %s" % scenario.index
        assert scenario.title == "Doing something"
Beispiel #4
0
def test_parsing_files_with_proper_header_returns_parsed_scenario():

    mocker = Mocker()

    settings = Settings()
    files = ["some path"]

    story_text = """As a someone
I want to do something
So that I'm happy"""

    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs,
                        pattern=settings.file_pattern)
    mocker.result(files)
    filemock.read_file(files[0])
    mocker.result(story_text)

    language_mock = mocker.mock()
    language_mock.get("as_a")
    mocker.result("As a")
    language_mock.get("i_want_to")
    mocker.result("I want to")
    language_mock.get("so_that")
    mocker.result("So that")

    with mocker:
        parser = FileParser(language=language_mock, file_object=filemock)

        fixture = parser.get_stories(settings=settings)
        assert len(fixture.stories) == 1
        assert fixture.stories[0].as_a == "someone"
        assert fixture.stories[0].i_want_to == "do something"
        assert fixture.stories[0].so_that == "I'm happy"
Beispiel #5
0
def test_parsing_files_with_many_scenarios_returns_parsed_scenarios():
    class DoSomethingAction(ActionBase):
        regex = r'I do something$'

        def execute(context, *args, **kwargs):
            pass

    class DoSomethingElseAction(ActionBase):
        regex = r'I do something else$'

        def execute(context, *args, **kwargs):
            pass

    class DoYetAnotherThingAction(ActionBase):
        regex = r'I do yet another thing$'

        def execute(context, *args, **kwargs):
            pass

    settings = Settings()
    settings.tests_dirs = [abspath(dirname(__file__))]
    settings.file_pattern = "some_test.acc"

    parser = FileParser()

    fixture = parser.get_stories(settings=settings)

    assert_no_invalid_stories(fixture)

    assert len(
        fixture.stories) == 1, "Expected 1, Actual: %d" % len(fixture.stories)
    assert len(fixture.stories[0].scenarios) == 2
    assert "#some custom comment" in fixture.stories[0].scenarios[1].whens[
        0].description
Beispiel #6
0
def test_can_create_file_parser_with_mocked_filesystem():

    mocker = Mocker()

    filemock = mocker.mock()
    parser = FileParser(file_object=filemock)

    assert parser.file_object == filemock
Beispiel #7
0
def test_parsing_folder_with_no_stories_returns_empty_list():
    settings = Settings()
    settings.tests_dirs = [
        abspath(join(dirname(__file__), "no_stories_folder"))
    ]
    parser = FileParser()

    fixture = parser.get_stories(settings=settings)
    assert len(fixture.stories) == 0
Beispiel #8
0
def test_is_not_keyword():

    mocker = Mocker()

    language_mock = mocker.mock()
    language_mock.get("keyword")
    mocker.result("kw")

    with mocker:
        parser = FileParser(language=language_mock, file_object=None)
        is_keyword = parser.is_keyword("other", "keyword")

        assert not is_keyword
Beispiel #9
0
def test_is_not_scenario_starter_line():

    mocker = Mocker()

    language_mock = mocker.mock()
    language_mock.get("scenario")
    mocker.result("Scenario")

    with mocker:
        parser = FileParser(language=language_mock, file_object=None)
        is_scenario_starter_line = parser.is_scenario_starter_line(
            "Cenario bla")

        assert not is_scenario_starter_line
Beispiel #10
0
def test_parsing_files_with_wrong_i_want_to_returns_no_story_header_list():
    settings = Settings()
    settings.tests_dirs = [
        abspath(join(dirname(__file__), "invalid_content_stories"))
    ]
    settings.file_pattern = "invalid_i_want_to.acc"

    parser = FileParser()

    fixture = parser.get_stories(settings=settings)

    assert len(fixture.no_story_header) == 1
    file_path = fixture.no_story_header[0]
    assert file_path.endswith("invalid_i_want_to.acc")
Beispiel #11
0
def test_parsing_stories_returns_list():

    mocker = Mocker()

    settings = Settings()
    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs,
                        pattern=settings.file_pattern)
    mocker.result([])

    with mocker:
        parser = FileParser(file_object=filemock)

        fixture = parser.get_stories(settings=settings)
        assert isinstance(fixture, Fixture)
Beispiel #12
0
def test_parsing_folder_with_no_stories_returns_empty_list():

    mocker = Mocker()

    settings = Settings()
    files = []
    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs,
                        pattern=settings.file_pattern)
    mocker.result(files)

    with mocker:
        parser = FileParser(file_object=filemock)

        fixture = parser.get_stories(settings=settings)
        assert len(fixture.stories) == 0
Beispiel #13
0
def test_parsing_files_with_many_scenarios_returns_parsed_scenarios():

    mocker = Mocker()

    class DoSomethingAction:
        def execute(context, *args, **kwargs):
            pass

    class DoSomethingElseAction:
        def execute(context, *args, **kwargs):
            pass

    class DoYetAnotherThingAction:
        def execute(context, *args, **kwargs):
            pass

    settings = Settings()
    files = ["some path"]

    story_text = """As a someone
I want to do something
So that I'm happy

Scenario 1 - Test Scenario
Given
    I do something
When
    I do something else
Then
    I do yet another thing

Scenario 2 - Test Scenario
Given
    I do something
When
    #some custom comment
Then
    I do yet another thing"""

    filemock = mocker.mock()
    filemock.list_files(directories=settings.tests_dirs,
                        pattern=settings.file_pattern)
    mocker.result(files)
    filemock.read_file(files[0])
    mocker.result(story_text)

    language_mock = mocker.mock()
    language_mock.get("as_a")
    mocker.result("As a")
    language_mock.get("i_want_to")
    mocker.result("I want to")
    language_mock.get("so_that")
    mocker.result("So that")
    language_mock.get("given")
    mocker.result("Given")
    mocker.count(min=1, max=None)
    language_mock.get("when")
    mocker.result("When")
    mocker.count(min=1, max=None)
    language_mock.get("then")
    mocker.result("Then")
    mocker.count(min=1, max=None)
    language_mock.get("scenario")
    mocker.result("Scenario")
    mocker.count(min=1, max=None)

    action_registry_mock = mocker.mock()
    action_registry_mock.suitable_for("I do something", 'en-us')
    mocker.result((DoSomethingAction, [], {}))
    mocker.count(min=1, max=None)
    action_registry_mock.suitable_for("I do something else", 'en-us')
    mocker.result((DoSomethingElseAction, [], {}))
    mocker.count(min=1, max=None)
    action_registry_mock.suitable_for("I do yet another thing", 'en-us')
    mocker.result((DoYetAnotherThingAction, [], {}))
    mocker.count(min=1, max=None)

    with mocker:
        parser = FileParser(language=language_mock,
                            file_object=filemock,
                            action_registry=action_registry_mock)

        fixture = parser.get_stories(settings=settings)

        assert_no_invalid_stories(fixture)

        assert len(fixture.stories) == 1, "Expected 1, Actual: %d" % len(
            fixture.stories)
        assert len(fixture.stories[0].scenarios) == 2
        assert fixture.stories[0].scenarios[1].whens[
            0].description == "#some custom comment"
Beispiel #14
0
def test_can_create_file_parser():
    parser = FileParser()

    assert isinstance(
        parser, FileParser
    ), "The created instance should be an instance of FileParser but was %s" % parser.__class__
Beispiel #15
0
 def __init__(self, parser=None, runner=None, hooks=None):
     self.parser = parser or FileParser()
     self.runner = runner
     sys.path.insert(0, os.getcwd())
     self.used_elements = {}
     self.hooks = hooks and hooks or Hooks