Пример #1
0
def test_format_suite_errors():
    parser = Parser()
    suite_results = parser.parse([
        {
            u'status': u'failed',
            u'failedExpectations': [
                {"message": "ahhh", "stack": "stack1"},
                {"message": "oh no!", "stack": "stack2"}
            ]
        },
        {
            u'status': u'failed',
            u'failedExpectations': [
                {"message": "boom", "stack": "stack3"},
            ]
        }
    ])

    formatter = _create_console_formatter(suite_results=suite_results)
    assert formatter.format_suite_failure() == \
           "After All Failures:\n" \
           + "  ahhh\n" \
           + "  stack1\n" \
           + "  oh no!\n" \
           + "  stack2\n" \
           + "  boom\n" \
           + "  stack3\n"
Пример #2
0
def test_parser_returns_all_failed_expectations():
    parser = Parser()

    results = parser.parse([{
        u'failedExpectations': [
            {
                u'actual': u'Expectation1'
            },
            {
                u'actual': u'Expectation2'
            },
            {
                u'actual': u'Expectation3'
            },
            {
                u'actual': u'Expectation4'
            },
        ],
    }])

    assert len(results) == 1
    assert len(results[0].failed_expectations) == 4
    assert results[0].failed_expectations[0][u'actual'] == u'Expectation1'
    assert results[0].failed_expectations[1][u'actual'] == u'Expectation2'
    assert results[0].failed_expectations[2][u'actual'] == u'Expectation3'
    assert results[0].failed_expectations[3][u'actual'] == u'Expectation4'
Пример #3
0
def passing_results():
    parser = Parser()
    return parser.parse([
        {u'status': u'passed'},
        {u'status': u'passed'},
        {u'status': u'pending', u'fullName': u'Context is this test is pending'},
    ])
def test_format_suite_errors():
    parser = Parser()
    suite_results = parser.parse([
        {
            u'status': u'failed',
            u'failedExpectations': [
                {"message": "ahhh", "stack": "stack1"},
                {"message": "oh no!", "stack": "stack2"}
            ]
        },
        {
            u'status': u'failed',
            u'failedExpectations': [
                {"message": "boom", "stack": "stack3"},
            ]
        },
        {
            u'status': u'failed',
            u'failedExpectations': [
                {"message": "nope"},
            ]
        }
    ])

    formatter = _create_console_formatter(suite_results=suite_results)
    assert formatter.format_suite_failure() == \
           "Suite Failures:\n" \
           + "  ahhh\n" \
           + "  stack1\n" \
           + "  oh no!\n" \
           + "  stack2\n" \
           + "  boom\n" \
           + "  stack3\n" \
           + "  nope\n"
def passing_results():
    parser = Parser()
    return parser.parse([
        {u'status': u'passed'},
        {u'status': u'passed'},
        {u'status': u'pending', u'fullName': u'Context is this test is pending'},
    ])
def test_format_failures():
    parser = Parser()

    stack1 = u"""Error: Expected 'Batman' to equal 'PANTS'.
        at stack (http://localhost:8888/__jasmine__/jasmine.js:1110)
        at http://localhost:8888/__spec__/global_spec.js:3"""

    stack2 = u"""Error: Expected 'Batman' to equal 'Superman'.
        at stack (http://localhost:8888/__jasmine__/jasmine.js:1110)
        at http://localhost:8888/__spec__/global_spec.js:6"""

    stack3 = u"""Error: Expected 'Justice' to equal 'Served'.
        at stack (http://localhost:8888/__jasmine__/jasmine.js:1110)
        at http://localhost:8888/__spec__/global_spec.js:9"""

    results = parser.parse([
        {
            u'status': u'passed',
            u'fullName': u'Context is this test passes'
        },
        {
            u'status': u'failed',
            u'fullName': u'Context is this test fails',
            u'failedExpectations': [{
                u'stack': stack1,
                u'message': 'Message1'
            }]
        },
        {
            u'status':
            u'failed',
            u'fullName':
            u'Context is this test also fails',
            u'failedExpectations': [{
                u'stack': stack2,
                u'message': 'Message2'
            }, {
                u'stack': stack3,
                u'message': 'Message3'
            }]
        },
    ])

    formatter = _create_console_formatter(spec_results=results, colors=False)

    assert formatter.format_spec_failures() == \
           "Context is this test fails\n" + \
           "  Message1\n" + \
           "  Error: Expected 'Batman' to equal 'PANTS'.\n" + \
           "        at http://localhost:8888/__spec__/global_spec.js:3\n" + \
           "Context is this test also fails\n" + \
           "  Message2\n" + \
           "  Error: Expected 'Batman' to equal 'Superman'.\n" + \
           "        at http://localhost:8888/__spec__/global_spec.js:6\n" + \
           "  Message3\n" + \
           "  Error: Expected 'Justice' to equal 'Served'.\n" + \
           "        at http://localhost:8888/__spec__/global_spec.js:9\n"
def test_pending_with_message():
    parser = Parser()

    results = parser.parse([{
        u'status': u'pending',
        u'fullName': u'pending',
        u'pendingReason': 'the reason'
    }])

    formatter = _create_console_formatter(spec_results=results, colors=False)
    assert formatter.format_pending() == "pending\n  Reason: the reason\n"
def test_parser_should_return_a_correct_results_list():
    parser = Parser()

    results = parser.parse([
        {
            u'status': u'failed',
            u'fullName': u'Globals refer to the most holy.',
            u'failedExpectations': [
                {
                    u'actual': u'Batman',
                    u'matcherName': u'toEqual',
                    u'passed': False,
                    u'expected': u'PANTS',
                    u'message': u"Expected 'Batman' to equal 'PANTS'.",
                    u'stack': u"stack\n    stack\n    stack"
                }
            ],

            u'passedExpectations': [
                {
                    u'matcherName': u'toBeTruthy',
                    u'expected': [],
                    u'actual': True,
                    u'message': u'Passed.',
                    u'stack': u'',
                    u'passed': True
                }
            ],
            u'deprecationWarnings': [
                {
                    u'message': u'old and busted',
                    u'stack': u'snacky stack'
                }
            ],
            u'id': 0,
            u'description': u'refer to the most holy',
            u'pendingReason': u'pending reason'
        }
    ])

    assert len(results) == 1
    assert results[0].status == 'failed'
    assert results[0].full_name == 'Globals refer to the most holy.'
    assert len(results[0].failed_expectations) == 1
    assert results[0].failed_expectations[0]['stack'] == "stack\n    stack\n    stack"
    assert results[0].failed_expectations[0]['message'] == "Expected 'Batman' to equal 'PANTS'."
    assert results[0].pending_reason == u'pending reason'
    assert len(results[0].deprecation_warnings) == 1
    assert results[0].deprecation_warnings[0]['message'] == "old and busted"
    assert results[0].deprecation_warnings[0]['stack'] == "snacky stack"
Пример #9
0
def test_pending_with_message():
    parser = Parser()

    results = parser.parse(
        [
            {
                u'status': u'pending',
                u'fullName': u'pending',
                u'pendingReason': 'the reason'
            }
        ]
    )

    formatter = _create_console_formatter(spec_results=results, colors=False)
    assert formatter.format_pending() == "pending\n  Reason: the reason\n"
Пример #10
0
    def run(self, browser=None, show_logs=False, app=None, seed=None):
        try:
            test_server = self._start_test_server(app, browser)

            url_builder = JasmineUrlBuilder(jasmine_config=self.jasmine_config)
            jasmine_url = url_builder.build_url(test_server.port, seed)
            self.browser.get(jasmine_url)

            WebDriverWait(self.browser,
                          100).until(lambda driver: driver.execute_script(
                              "return jsApiReporter.finished;"))

            parser = Parser()
            spec_results = self._get_spec_results(parser)
            top_suite_results = self._get_top_suite_results(parser)
            suite_results = self._get_suite_results(parser) + top_suite_results
            show_logs = self._get_browser_logs(show_logs=show_logs)
            actual_seed = self._get_seed()

            formatter = ConsoleFormatter(spec_results=spec_results,
                                         suite_results=suite_results,
                                         browser_logs=show_logs,
                                         seed=actual_seed)
            sys.stdout.write(formatter.format())
            if len(spec_results.failed()) or len(suite_results.failed()):
                sys.exit(1)
        finally:
            if hasattr(self, 'browser'):
                self.browser.close()
            if hasattr(self, 'test_server'):
                self.test_server.join()
def test_deprecation_warning():
    parser = Parser()

    specs = parser.parse(
        [
            {
                u'status': u'passed',
                u'fullName': u'Speccy',
                u'deprecationWarnings': [
                    {
                        u'message': u'spec deprecated',
                        u'stack': None
                    }
                ]
            }
        ]
    )

    suites = parser.parse(
        [
            {
                u'status': u'passed',
                u'fullName': u'Sweet',
                u'deprecationWarnings': [
                    {
                        u'message': u'suite deprecated',
                        u'stack': None
                    }
                ]
            }
        ]
    )

    formatter = _create_console_formatter(spec_results=specs, suite_results=suites, colors=False)
    assert formatter.format_deprecations() == \
            "Deprecations:\n" + \
            "Speccy\n" + \
            "  spec deprecated\n" + \
            "  \n" + \
            "Sweet\n" + \
            "  suite deprecated\n" +\
            "  \n"
Пример #12
0
def test_parser_returns_all_failed_expectations():
    parser = Parser()

    results = parser.parse([
        {
            u'failedExpectations': [
                {u'actual': u'Expectation1'},
                {u'actual': u'Expectation2'},
                {u'actual': u'Expectation3'},
                {u'actual': u'Expectation4'},
            ],
        }
    ])

    assert len(results) == 1
    assert len(results[0].failed_expectations) == 4
    assert results[0].failed_expectations[0][u'actual'] == u'Expectation1'
    assert results[0].failed_expectations[1][u'actual'] == u'Expectation2'
    assert results[0].failed_expectations[2][u'actual'] == u'Expectation3'
    assert results[0].failed_expectations[3][u'actual'] == u'Expectation4'
Пример #13
0
def test_format_failures():
    parser = Parser()

    stack1 = u"""Error: Expected 'Batman' to equal 'PANTS'.
        at stack (http://localhost:8888/__jasmine__/jasmine.js:1110)
        at http://localhost:8888/__spec__/global_spec.js:3"""

    stack2 = u"""Error: Expected 'Batman' to equal 'Superman'.
        at stack (http://localhost:8888/__jasmine__/jasmine.js:1110)
        at http://localhost:8888/__spec__/global_spec.js:6"""

    stack3 = u"""Error: Expected 'Justice' to equal 'Served'.
        at stack (http://localhost:8888/__jasmine__/jasmine.js:1110)
        at http://localhost:8888/__spec__/global_spec.js:9"""

    results = parser.parse([
        {u'status': u'passed', u'fullName': u'Context is this test passes'},
        {u'status': u'failed', u'fullName': u'Context is this test fails',
         u'failedExpectations': [{u'stack': stack1, u'message': 'Message1'}]},
        {u'status': u'failed', u'fullName': u'Context is this test also fails',
         u'failedExpectations': [{u'stack': stack2, u'message': 'Message2'},
                                 {u'stack': stack3, u'message': 'Message3'}]},
    ])

    formatter = _create_console_formatter(spec_results=results, colors=False)

    assert formatter.format_spec_failures() == \
           "Context is this test fails\n" + \
           "  Message1\n" + \
           "  Error: Expected 'Batman' to equal 'PANTS'.\n" + \
           "        at http://localhost:8888/__spec__/global_spec.js:3\n" + \
           "Context is this test also fails\n" + \
           "  Message2\n" + \
           "  Error: Expected 'Batman' to equal 'Superman'.\n" + \
           "        at http://localhost:8888/__spec__/global_spec.js:6\n" + \
           "  Message3\n" + \
           "  Error: Expected 'Justice' to equal 'Served'.\n" + \
           "        at http://localhost:8888/__spec__/global_spec.js:9\n"
Пример #14
0
    def run(self, browser=None, show_logs=False, app=None, seed=None):
        try:
            port = self._find_unused_port()
            self.test_server = self._start_test_server(app, browser, port)

            url_builder = JasmineUrlBuilder(jasmine_config=self.jasmine_config)
            jasmine_url = url_builder.build_url(port, seed)
            self.browser.get(jasmine_url)

            WebDriverWait(self.browser, 100).until(
                lambda driver:
                driver.execute_script("return jsApiReporter.finished;")
            )

            parser = Parser()
            spec_results = self._get_spec_results(parser)
            top_suite_results = self._get_top_suite_results(parser)
            suite_results = self._get_suite_results(parser) + top_suite_results
            show_logs = self._get_browser_logs(show_logs=show_logs)
            actual_seed = self._get_seed()

            formatter = ConsoleFormatter(
                spec_results=spec_results,
                suite_results=suite_results,
                browser_logs=show_logs,
                seed=actual_seed
            )
            str_output = formatter.format()
            if sys.version_info[0] < 3:
                sys.stdout.write(str_output.encode('UTF8'))
            else:
                sys.stdout.write(str_output)

            overall_status = self._get_overall_status()

            if overall_status == 'incomplete':
                sys.stdout.write('Incomplete: %s\n' % self._get_incomplete_reason())

            if overall_status != 'passed':
                sys.exit(1)
        finally:
            if hasattr(self, 'browser'):
                self.browser.close()
            if hasattr(self, 'test_server'):
                self.test_server.join()
Пример #15
0
def test_parser_returns_an_empty_results_list_with_no_runnables():
    parser = Parser()
    results = parser.parse([])

    assert len(results) == 0
Пример #16
0
def test_parser_returns_an_empty_results_list_with_no_runnables():
    parser = Parser()
    results = parser.parse([])

    assert len(results) == 0