Beispiel #1
0
def test_see_summary_for_fixture_returns_proper_string():
    expected = """================
Test Run Summary
================

Status: SUCCESSFUL

Test Data Stats
---------------
Successful Stories......1/1 (100.00%)
Failed Stories..........0/1 (0.00%)
Successful Scenarios....1/1 (100.00%)
Failed Scenarios........0/1 (0.00%)"""

    template_loader_mock = Mock()
    template_loader_mock.expects(once()) \
                        .load(eq("summary")) \
                        .will(return_value(summary_template))
    settings = Settings()
    fixture = Fixture()
    action = some_action()
    fixture.append_story(action.scenario.story)
    action.mark_as_successful()
    result = Result(fixture=fixture, template_loader=template_loader_mock)

    summary = result.summary_for(settings.default_culture)
    assert summary == expected
Beispiel #2
0
def test_see_summary_for_fixture_returns_proper_string_for_failed_tests():
    
    mocker = Mocker()
    
    expected = """================
Test Run Summary
================

Status: FAILED

Test Data Stats
---------------
Successful Stories......0/1 (0.00%)
Failed Stories..........1/1 (100.00%)
Successful Scenarios....0/1 (0.00%)
Failed Scenarios........1/1 (100.00%)"""

    template_loader_mock = mocker.mock()
    template_loader_mock.load("summary")
    mocker.result(summary_template)
    
    with mocker:
        settings = Settings()
        fixture = Fixture()
        action = some_action()
        fixture.append_story(action.scenario.story)
        action.mark_as_failed()
        result = Result(fixture=fixture, template_loader=template_loader_mock)
    
        summary = result.summary_for(settings.default_culture)
        assert summary == expected
Beispiel #3
0
def test_see_summary_for_fixture_returns_proper_string_for_failed_tests():

    mocker = Mocker()

    expected = """================
Test Run Summary
================

Status: FAILED

Test Data Stats
---------------
Successful Stories......0/1 (0.00%)
Failed Stories..........1/1 (100.00%)
Successful Scenarios....0/1 (0.00%)
Failed Scenarios........1/1 (100.00%)"""

    template_loader_mock = mocker.mock()
    template_loader_mock.load("summary")
    mocker.result(summary_template)

    with mocker:
        settings = Settings()
        fixture = Fixture()
        action = some_action()
        fixture.append_story(action.scenario.story)
        action.mark_as_failed()
        result = Result(fixture=fixture, template_loader=template_loader_mock)

        summary = result.summary_for(settings.default_culture)
        assert summary == expected
Beispiel #4
0
def test_see_summary_for_fixture_returns_proper_string_for_no_tests():

    mocker = Mocker()

    expected = """================
Test Run Summary
================

Status: UNKNOWN

Test Data Stats
---------------
Successful Stories......0/0 (0.00%)
Failed Stories..........0/0 (0.00%)
Successful Scenarios....0/0 (0.00%)
Failed Scenarios........0/0 (0.00%)"""

    template_loader_mock = mocker.mock()
    template_loader_mock.load("summary")
    mocker.result(summary_template)

    with mocker:
        settings = Settings()
        fixture = Fixture()
        result = Result(fixture=fixture, template_loader=template_loader_mock)

        summary = result.summary_for(settings.default_culture)
        assert summary == expected
Beispiel #5
0
def test_see_summary_for_fixture_returns_proper_string_for_no_tests():
    
    mocker = Mocker()
    
    expected = """================
Test Run Summary
================

Status: UNKNOWN

Test Data Stats
---------------
Successful Stories......0/0 (0.00%)
Failed Stories..........0/0 (0.00%)
Successful Scenarios....0/0 (0.00%)
Failed Scenarios........0/0 (0.00%)"""

    template_loader_mock = mocker.mock()
    template_loader_mock.load("summary")
    mocker.result(summary_template)
    
    with mocker:
        settings = Settings()
        fixture = Fixture()
        result = Result(fixture=fixture, template_loader=template_loader_mock)
    
        summary = result.summary_for(settings.default_culture)
        assert summary == expected
Beispiel #6
0
def test_see_summary_for_fixture():
    template_loader_mock = Mock()
    template_loader_mock.expects(once()) \
                        .load(eq("summary")) \
                        .will(return_value(summary_template))
    settings = Settings()
    fixture = Fixture()
    action = some_action()
    fixture.append_story(action.scenario.story)
    action.mark_as_successful()
    result = Result(fixture=fixture, template_loader=template_loader_mock)

    summary = result.summary_for(settings.default_culture)
    assert summary is not None
Beispiel #7
0
    def run_stories(self, settings, fixture, context=None):
        if len(fixture.stories) == 0:
            return

        self.fill_queue(fixture, settings)
        self.fill_context_queue(settings)

        fixture.start_run()

        try:
            self.start_processes()

            try:
                time.sleep(2)
                while self.test_queue.unfinished_tasks:
                    time.sleep(1)
            except KeyboardInterrupt:
                self.abort_run()

        finally:
            self.kill_context_queue()

        fixture.end_run()

        return Result(fixture=fixture)
Beispiel #8
0
def test_see_summary_for_fixture_returns_proper_failed_scenarios_string():

    mocker = Mocker()

    expected = """================
Test Run Summary
================

Status: FAILED

Test Data Stats
---------------
Successful Stories......0/1 (0.00%)
Failed Stories..........1/1 (100.00%)
Successful Scenarios....0/1 (0.00%)
Failed Scenarios........1/1 (100.00%)

Failed Stories / Scenarios
--------------------------
Story..........As a Someone I want to Do Something So that I'm Happy
Story file.....To be implemented.
Scenario.......1 - Something
    Given
        I did something - UNKNOWN
    When
        I do something - UNKNOWN
    Then
        Something happens - FAILED - Something very bad happened
"""

    template_loader_mock = mocker.mock()
    template_loader_mock.load("summary")
    mocker.result(summary_template + summary_template_failed_stories)

    with mocker:
        settings = Settings()
        fixture = Fixture()
        result = Result(fixture=fixture, template_loader=template_loader_mock)
        action = complete_scenario_with_then_action_returned()
        fixture.append_story(action.scenario.story)
        action.mark_as_failed("Something very bad happened")

        summary = result.summary_for(settings.default_culture)

        assert summary.strip() == expected.strip()
Beispiel #9
0
def test_see_summary_for_fixture_returns_proper_failed_scenarios_string():
    
    mocker = Mocker()
    
    expected = """================
Test Run Summary
================

Status: FAILED

Test Data Stats
---------------
Successful Stories......0/1 (0.00%)
Failed Stories..........1/1 (100.00%)
Successful Scenarios....0/1 (0.00%)
Failed Scenarios........1/1 (100.00%)

Failed Stories / Scenarios
--------------------------
Story..........As a Someone I want to Do Something So that I'm Happy
Story file.....To be implemented.
Scenario.......1 - Something
    Given
        I did something - UNKNOWN
    When
        I do something - UNKNOWN
    Then
        Something happens - FAILED - Something very bad happened
"""

    template_loader_mock = mocker.mock()
    template_loader_mock.load("summary")
    mocker.result(summary_template + summary_template_failed_stories)
    
    with mocker:
        settings = Settings()
        fixture = Fixture()
        result = Result(fixture=fixture, template_loader=template_loader_mock)
        action = complete_scenario_with_then_action_returned()
        fixture.append_story(action.scenario.story)
        action.mark_as_failed("Something very bad happened")
    
        summary = result.summary_for(settings.default_culture)
    
        assert summary.strip() == expected.strip()
Beispiel #10
0
def test_see_summary_for_fixture():
    
    mocker = Mocker()
    
    template_loader_mock = mocker.mock()
    template_loader_mock.load("summary")
    mocker.result(summary_template)
    
    with mocker:
        settings = Settings()
        fixture = Fixture()
        action = some_action()
        fixture.append_story(action.scenario.story)
        action.mark_as_successful()
        result = Result(fixture=fixture, template_loader=template_loader_mock)
    
        summary = result.summary_for(settings.default_culture)
        assert summary is not None
Beispiel #11
0
def test_see_summary_for_fixture():

    mocker = Mocker()

    template_loader_mock = mocker.mock()
    template_loader_mock.load("summary")
    mocker.result(summary_template)

    with mocker:
        settings = Settings()
        fixture = Fixture()
        action = some_action()
        fixture.append_story(action.scenario.story)
        action.mark_as_successful()
        result = Result(fixture=fixture, template_loader=template_loader_mock)

        summary = result.summary_for(settings.default_culture)
        assert summary is not None
Beispiel #12
0
def test_see_summary_for_fixture_returns_proper_failed_scenarios_string():
    expected = u"""================
Test Run Summary
================
Status: FAILED

Test Data Stats
---------------
Successful Stories......0 of 1 (0.00%)
Successful Scenarios....0 of 1 (0.00%)
Failed Stories..........1 of 1 (100.00%)
Failed Scenarios........1 of 1 (100.00%)

Total timing: 0.00 secs
Scenarios/Minute: 0 scenarios per minute


Failed Stories / Scenarios
--------------------------
Story..........As a Someone I want to Do Something So that I'm Happy
Story file.....some file
Scenario.......1 - Something
    Given
        I did something - UNKNOWN
    When
        I do something - UNKNOWN
    Then
        Something happens - FAILED - Something very bad happened
"""

    settings = Settings()
    fixture = Fixture()
    result = Result(fixture=fixture)
    action = complete_scenario_with_then_action_returned()
    fixture.append_story(action.scenario.story)
    action.mark_as_failed("Something very bad happened")

    summary = re.sub(r'[$][{][^}]+[}]', '', result.summary_for("en-us"))

    assert summary.strip() == expected.strip(), compare(
        summary.strip(), expected.strip())
Beispiel #13
0
def test_see_summary_for_fixture_returns_proper_failed_scenarios_string():
    expected = u"""================
Test Run Summary
================
Status: FAILED

Test Data Stats
---------------
Successful Stories......0 of 1 (0.00%)
Successful Scenarios....0 of 1 (0.00%)
Failed Stories..........1 of 1 (100.00%)
Failed Scenarios........1 of 1 (100.00%)

Total timing: 0.00 secs
Scenarios/Minute: 0 scenarios per minute


Failed Stories / Scenarios
--------------------------
Story..........As a Someone I want to Do Something So that I'm Happy
Story file.....some file
Scenario.......1 - Something
    Given
        I did something - UNKNOWN
    When
        I do something - UNKNOWN
    Then
        Something happens - FAILED - Something very bad happened
"""

    settings = Settings()
    fixture = Fixture()
    result = Result(fixture=fixture)
    action = complete_scenario_with_then_action_returned()
    fixture.append_story(action.scenario.story)
    action.mark_as_failed("Something very bad happened")

    summary = re.sub(r'[$][{][^}]+[}]', '', result.summary_for("en-us"))

    assert summary.strip() == expected.strip(), compare(summary.strip(), expected.strip())
Beispiel #14
0
def test_see_summary_for_fixture_returns_proper_string_for_no_tests():
    expected = """================
Test Run Summary
================

Status: UNKNOWN

Test Data Stats
---------------
Successful Stories......0/0 (0.00%)
Failed Stories..........0/0 (0.00%)
Successful Scenarios....0/0 (0.00%)
Failed Scenarios........0/0 (0.00%)"""

    template_loader_mock = Mock()
    template_loader_mock.expects(once()) \
                        .load(eq("summary")) \
                        .will(return_value(summary_template))
    settings = Settings()
    fixture = Fixture()
    result = Result(fixture=fixture, template_loader=template_loader_mock)

    summary = result.summary_for(settings.default_culture)
    assert summary == expected
Beispiel #15
0
def test_empty_result_returns_none_fixture():
    result = Result.empty()
    assert result.fixture is None
Beispiel #16
0
class PyccuracyCore(object):
    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

    def got_element(self, page, element_key, resolved_key):
        if page not in self.used_elements:
            self.used_elements[page] = []
        self.used_elements[page] = element_key

    def run_tests(self, context=None, fso=None, **kwargs):
        settings = Settings(kwargs)
        if not context:
            context = Context(settings)

        if not self.runner:
            self.runner = context.settings.worker_threads == 1 and StoryRunner() or ParallelStoryRunner(settings.worker_threads)

        for directory in context.settings.hooks_dir:
            self.import_extra_content(directory, fso=fso)
        
        for directory in context.settings.pages_dir:
            self.import_extra_content(directory, fso=fso)

        if context.settings.custom_actions_dir != context.settings.pages_dir:
            for directory in context.settings.custom_actions_dir:
                self.import_extra_content(directory, fso=fso)
        
        try:
            fixture = self.parser.get_stories(settings)
        except ActionNotFoundError, err:
            self.print_invalid_action(context.settings.default_culture, err)
            if settings.should_throw:
                raise TestFailedError("The test failed!")
            else:
                return None
        
        if fixture.no_story_header:
            self.print_no_story_header(fixture, context)
            if settings.should_throw:
                raise TestFailedError("The test failed!")
            else:
                return None

        if len(self.parser.used_actions) != len(ActionBase.all()):
            unused_actions = []
            for action in ActionBase.all():
                if hasattr(action, '__builtin__') and action.__builtin__:
                    continue
                if action not in self.parser.used_actions:
                    unused_actions.append(action.__name__)
            if unused_actions and not settings.suppress_warnings:
                self.print_unused_actions_warning(unused_actions)

        if not fixture.stories:
            results = Result(fixture)
            self.print_results(context.settings.default_culture, results)
            return results

        try:
            Page.subscribe_to_got_element(self.got_element)

            self.hooks.execute_before_tests()
            
            #running the tests
            results = self.runner.run_stories(settings=context.settings,
                                               fixture=fixture,
                                               context=context)

            if not settings.suppress_warnings:
                self.print_unused_elements_warning()

            self.print_results(context.settings.default_culture, results)

            if context.settings.write_report and results:
                try:
                    import lxml
                except ImportError:
                    self.print_lxml_import_error()
                else:
                    import report_parser as report
                    path = join(context.settings.report_file_dir, context.settings.report_file_name)
                    report.generate_report(path, results, context.language)

            self.hooks.execute_after_tests(results)
            
            if settings.should_throw and results and results.get_status() == Status.Failed:
                raise TestFailedError("The test failed!")
            
            return results
        except KeyboardInterrupt:
            results = Result(fixture)
            self.print_results(context.settings.default_culture, results)
            return results
Beispiel #17
0
def test_empty_result_returns_unknown_status():
    result = Result.empty()
    assert result.get_status() == Status.Unknown
Beispiel #18
0
def test_empty_result_returns_none_fixture():
    result = Result.empty()
    assert result.fixture is None
Beispiel #19
0
def test_empty_result_returns_result():
    result = Result.empty()
    assert result is not None
Beispiel #20
0
class StoryRunner(object):
    def run_stories(self, settings, fixture, context=None):
        if not context:
            context = self.create_context_for(settings)

        fixture.start_run()
        if settings.base_url:
            base_url = settings.base_url
        else:
            base_url = "http://localhost"

        try:
            context.browser_driver.start_test(base_url)
        except DriverError, err:
            ctrl = TerminalController()
            template_text = TemplateLoader(
                settings.default_culture).load("driver_error")
            template = Template(template_text)
            values = {"error": err, "browser_driver": context.browser_driver}
            print ctrl.render(template.merge(values))

            if settings.should_throw:
                raise TestFailedError("The test failed!")
            else:
                return None

        try:
            scenario_index = 0
            for story in fixture.stories:
                for scenario in story.scenarios:
                    if settings.on_scenario_started and callable(
                            settings.on_scenario_started):
                        settings.on_scenario_started(fixture, scenario,
                                                     scenario_index)
                    scenario_index += 1
                    if not context:
                        context = self.create_context_for(settings)

                    def execute_action(action):
                        try:
                            result = self.execute_action(context, action)
                            if not result:
                                return False
                        except ActionNotFoundError, error:
                            action.mark_as_failed(
                                ActionNotFoundError(error.line, scenario,
                                                    scenario.story.identity))
                            return False
                        return True

                    def on_section_started(section):
                        if settings.on_section_started and\
                        callable(settings.on_section_started):
                            settings.on_section_started(section)

                    failed = False
                    on_section_started(context.language.get('given'))
                    for action in scenario.givens:
                        if not execute_action(action):
                            failed = True
                            break

                    if not failed:
                        on_section_started(context.language.get('when'))
                        for action in scenario.whens:
                            if not execute_action(action):
                                failed = True
                                break

                    if not failed:
                        on_section_started(context.language.get('then'))
                        for action in scenario.thens:
                            if not execute_action(action):
                                failed = True
                                break

                    if settings.on_scenario_completed and callable(
                            settings.on_scenario_completed):
                        settings.on_scenario_completed(fixture, scenario,
                                                       scenario_index)

            fixture.end_run()
            return Result(fixture=fixture)
Beispiel #21
0
def test_empty_result_returns_unknown_status():
    result = Result.empty()
    assert result.get_status() == Status.Unknown
Beispiel #22
0
def test_empty_result_returns_result():
    result = Result.empty()
    assert result is not None