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""" 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"
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"
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"
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_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"
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()
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()
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"