示例#1
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'},
    ])
示例#2
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"""

    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'status': u'failed', u'fullName': u'Context is this test also fails',
            u'failedExpectations': [{u'stack': stack2}]},
    ])

    formatter = Formatter(results, colors=False)

    assert formatter.format_failures() ==\
        "Context is this test fails\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" +\
        "Error: Expected 'Batman' to equal 'Superman'.\n" +\
        "        at http://localhost:8888/__spec__/global_spec.js:6\n"
示例#3
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"""

    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'status': u'failed', u'fullName': u'Context is this test also fails',
            u'failedExpectations': [{u'stack': stack2}]},
    ])

    formatter = Formatter(results, colors=False)

    assert formatter.format_failures() ==\
        "Context is this test fails\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" +\
        "Error: Expected 'Batman' to equal 'Superman'.\n" +\
        "        at http://localhost:8888/__spec__/global_spec.js:6\n"
示例#4
0
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'id': 0,
         u'description': u'refer to the most holy'}
    ])

    assert len(results) == 1
    assert results[0].status == 'failed'
    assert results[0].fullName == 'Globals refer to the most holy.'
    assert len(results[0].failedExpectations) == 1
    assert results[0].failedExpectations[0]['stack'] == "stack\n    stack\n    stack"
示例#5
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'},
    ])
示例#6
0
def test_pending_with_message():
    parser = Parser()

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

    formatter = Formatter(results, colors=False)
    assert formatter.format_pending() == "pending\n  Reason: the reason\n"
示例#7
0
def test_format_after_all_errors():
    parser = Parser()
    suite_results = parser.parse([{
        u'status': u'failed',
        u'failedExpectations': [{
            "message": "ahhh"
        }]
    }])

    formatter = Formatter([], suite_results=suite_results)
    assert "After All ahhh" in formatter.format_suite_failure()
示例#8
0
    def run(self, browser=None):
        try:
            test_server = TestServerThread()
            test_server.start()

            driver = browser if browser else os.environ.get('JASMINE_BROWSER', 'firefox')

            try:
                webdriver = __import__("selenium.webdriver.{0}.webdriver".format(driver), globals(), locals(), ['object'], 0)

                self.browser = webdriver.WebDriver()
            except ImportError as e:
                print("Browser {0} not found".format(driver))

            self.browser.get("http://localhost:{0}/".format(test_server.port))

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

            spec_results = []
            index = 0
            batch_size = 50

            parser = Parser()


            while True:
                results = self.browser.execute_script("return jsApiReporter.specResults({0}, {1})".format(index, batch_size))

                results = parser.parse(results)

                spec_results.extend(results)
                index += len(results)

                if not len(results) == batch_size:
                    break

            try:
                log = self.browser.get_log('browser')
            except WebDriverException:
                log = []

            formatter = Formatter(spec_results, browser_logs=log)

            sys.stdout.write(formatter.format())
            if len(list(formatter.results.failed())):
                sys.exit(1)
        finally:
            if hasattr(self, 'browser'):
                self.browser.close()
            if hasattr(self, 'test_server'):
                self.test_server.join()
示例#9
0
    def run(self, browser=None):
        try:
            test_server = TestServerThread()
            test_server.start()

            driver = browser if browser else os.environ.get('JASMINE_BROWSER', 'firefox')

            try:
                webdriver = __import__("selenium.webdriver.{0}.webdriver".format(driver), globals(), locals(), ['object'], 0)

                self.browser = webdriver.WebDriver()
            except ImportError as e:
                print("Browser {0} not found".format(driver))

            self.browser.get("http://localhost:{0}/".format(test_server.port))

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

            self.browser.execute_script("""
                for (k in jsApiReporter.results()) {
                    var result = jsApiReporter.results()[k];
                    var messages = result.messages;

                    for (var i = 0; i < messages.length; i++) {
                        if (result.result === 'failed') {
                            messages[i].stack = messages[i].trace.stack;
                        }
                    }
                }
            """)

            results = self.browser.execute_script("return window.jsApiReporter.results()")
            suites = self.browser.execute_script("return window.jsApiReporter.suites()")

            spec_results = self._process_results(suites, results)

            results = Parser().parse(spec_results)
            formatter = Formatter(results, browser_logs=self.browser.get_log('browser'))

            sys.stdout.write(formatter.format())
            if list(results.failed()):
                sys.exit(1)
        finally:
            if hasattr(self, 'browser'):
                self.browser.close()
            if hasattr(self, 'test_server'):
                self.test_server.join()
示例#10
0
文件: ci.py 项目: ftobia/jasmine-py
    def run(self, browser=None):
        try:
            test_server = TestServerThread()
            test_server.start()

            driver = browser if browser else os.environ.get('JASMINE_BROWSER', 'firefox')

            try:
                webdriver = __import__("selenium.webdriver.{0}.webdriver".format(driver), globals(), locals(), ['object'], 0)

                self.browser = webdriver.WebDriver()
            except ImportError as e:
                print("Browser {0} not found".format(driver))

            self.browser.get("http://localhost:{0}/".format(test_server.port))

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

            self.browser.execute_script("""
                for (k in jsApiReporter.results()) {
                    var result = jsApiReporter.results()[k];
                    var messages = result.messages;

                    for (var i = 0; i < messages.length; i++) {
                        if (result.result === 'failed') {
                            messages[i].stack = messages[i].trace.stack;
                        }
                    }
                }
            """)

            results = self.browser.execute_script("return window.jsApiReporter.results()")
            suites = self.browser.execute_script("return window.jsApiReporter.suites()")

            spec_results = self._process_results(suites, results)

            results = Parser().parse(spec_results)
            formatter = Formatter(results)

            sys.stdout.write(formatter.format())
            if list(results.failed()):
                sys.exit(1)
        finally:
            if hasattr(self, 'browser'):
                self.browser.close()
            if hasattr(self, 'test_server'):
                self.test_server.join()
示例#11
0
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'id': 0,
         u'description': u'refer to the most holy'}
    ])

    assert len(results) == 1
    assert results[0].status == 'failed'
    assert results[0].fullName == 'Globals refer to the most holy.'
    assert len(results[0].failedExpectations) == 1
    assert results[0].failedExpectations[0]['stack'] == "stack\n    stack\n    stack"