def test__when_a_describe_block_is_focused__it_runs_descendant_tests(): reset() describe_block = DescribeBlock(None, "some describe", None, has_focused_descendants=True) inner_describe = DescribeBlock(describe_block, "some inner description", None, focused=True) other_inner_describe = DescribeBlock(describe_block, "some other inner description", None) describe_block.describe_blocks = [inner_describe, other_inner_describe] def it1(self): pass inner_describe.it_blocks = [ ItBlock(describe_block, "some test", it1), ItBlock(describe_block, "some test", it1) ] other_inner_describe.it_blocks = [ ItBlock(describe_block, "some other test", it1), ItBlock(describe_block, "some third test", it1) ] reporter = StatTrackingReporter() run_tests(describe_block, reporter) expect(reporter.stats.test_count).to_be(2)
def test__report_end_result__test_is_pending__reports_stats(): with StubPrint(): reporter = PyneStatSummaryReporter() passing_it_block = ItBlock(None, None, None) pending_it_block = ItBlock(None, None, None, pending=True) reporter.report_success(passing_it_block, 1000) reporter.report_pending(pending_it_block) printed_text.clear() reporter.report_end_result() expect( printed_text[0]).to_contain("1 passed, 1 pending in 1.00 seconds")
def test__report_pending__prints_test_description(): with StubPrint(): it_block = ItBlock(None, "Some it block description", None) reporter = PyneTreeReporter() reporter.report_pending(it_block) expect(printed_text[0]).to_contain("Some it block description")
def test__report_failure__sets_overall_failure(): reporter = PyneStatSummaryReporter() it_block = ItBlock(None, None, None) reporter.report_failure(it_block, it_block, Exception("some exception"), 0) expect(reporter.stats.is_failure).to_be(True)
def test__report_success__prints_test_description(): with StubPrint(): it_block = ItBlock(None, "Some it block description", None) reporter = PyneTreeReporter() printed_text.clear() reporter.report_success(it_block, 0) expect(printed_text[0]).to_contain("Some it block description")
def test__report_pending__increases_the_test_run_count(): reporter = PyneStatSummaryReporter() it_block = ItBlock(None, None, None) reporter.report_pending(it_block) reporter.report_pending(it_block) expect(reporter.stats.test_count).to_be(2)
def test__report_failure__increases_the_failure_count(): reporter = PyneStatSummaryReporter() it_block = ItBlock(None, None, None) reporter.report_failure(it_block, it_block, Exception("some exception"), 0) reporter.report_failure(it_block, it_block, Exception("some exception"), 0) expect(reporter.stats.failure_count).to_be(2)
def test__report_success__increases_the_passes_count(): reporter = PyneStatSummaryReporter() it_block = ItBlock(None, None, None) reporter.report_success(it_block, 0) reporter.report_success(it_block, 0) expect(reporter.stats.pass_count).to_be(2)
def test__report_failure__prints_an_x(): with StubPrint(): reporter = PyneDotReporter() it_block = ItBlock(None, None, None) printed_text.clear() reporter.report_failure(it_block, it_block, Exception("some exception"), 1000) expect(printed_text[0]).to_be("x")
def test__report_success__increases_the_total_timing(): reporter = PyneStatSummaryReporter() it_block = ItBlock(None, None, None) reporter.report_success(it_block, 10) reporter.report_success(it_block, 300) expect(reporter.stats.total_timing_millis).to_be(310)
def test__report_pending__prints_a_dash(): with StubPrint(): reporter = PyneDotReporter() it_block = ItBlock(None, None, None) printed_text.clear() reporter.report_pending(it_block) expect(printed_text[0]).to_be("-")
def test__report_failure__increases_the_total_timing(): reporter = PyneStatSummaryReporter() it_block = ItBlock(None, None, None) reporter.report_failure(it_block, it_block, Exception("some exception"), 1000) reporter.report_failure(it_block, it_block, Exception("some exception"), 20) expect(reporter.stats.total_timing_millis).to_be(1020)
def test__report_failure__prints_test_description(): with StubPrint(): it_block = ItBlock(None, "Some it block description", None) reporter = PyneTreeReporter() printed_text.clear() reporter.report_failure(it_block, it_block, Exception("some exception"), 0) expect(printed_text[0]).to_contain("Some it block description")
def test__report_success__prints_a_dot(): with StubPrint(): reporter = PyneDotReporter() it_block = ItBlock(None, None, None) printed_text.clear() reporter.report_success(it_block, 0) expect(printed_text[0]).to_be(".")
def test__report_end_result__when_all_tests_passed__it_prints_stats(): with StubPrint(): reporter = PyneStatSummaryReporter() it_block = ItBlock(None, None, None) reporter.report_success(it_block, 1000) reporter.report_success(it_block, 500) printed_text.clear() reporter.report_end_result() expect(printed_text[0]).to_contain("2 passed in 1.50 seconds")
def test__report_end_result__when_test_had_assertion_error__includes_the_file_location( ): reporter = PyneFailureSummaryReporter() with StubPrint(): exception = Exception() try: raise exception except Exception as e: block = ItBlock(None, None, None) reporter.report_failure(block, block, e, 0) reporter.report_end_result() expect(printed_text).to_contain( contains("reporters/pyne_failure_summary_reporter_test.py"))
def xit(method_or_description): if isinstance(method_or_description, str): description = method_or_description def named_xit(method): test_collection.current_describe.it_blocks.append( ItBlock(test_collection.current_describe, description, method, pending=True)) return named_xit else: method = method_or_description test_collection.current_describe.it_blocks.append( ItBlock(test_collection.current_describe, method.__name__, method, pending=True)) return method_or_description
def test__report_end_result__when_a_test_has_failed__it_prints_stats(): with StubPrint(): reporter = PyneStatSummaryReporter() it_block = ItBlock(None, None, None) reporter.report_failure(it_block, it_block, Exception("some exception"), 1000) reporter.report_success(it_block, 500) reporter.report_success(it_block, 500) printed_text.clear() reporter.report_end_result() expect( printed_text[0]).to_contain("1 failed, 2 passed in 2.00 seconds")
def fit(method_or_description): flag_ancestors_of_focus(test_collection.current_describe) if isinstance(method_or_description, str): description = method_or_description def named_focused_it(method): test_collection.current_describe.it_blocks.append( ItBlock(test_collection.current_describe, description, method, focused=True)) return named_focused_it else: method = method_or_description test_collection.current_describe.it_blocks.append( ItBlock(test_collection.current_describe, method.__name__, method, focused=True)) return method_or_description
def test__when_a_describe_block_is_pended__it_reports_the_contained_tests_as_pending( ): reset() describe_block = DescribeBlock(None, "some describe", None, pending=True) def it1(self): pass describe_block.it_blocks = [ItBlock(describe_block, "some test", it1)] reporter = StatTrackingReporter() run_tests(describe_block, reporter) expect(reporter.stats.test_count).to_be(1) expect(reporter.stats.pending_count).to_be(1)
def test__report_pending__indents_based_on_tree_depth(): with StubPrint(): describe_block = DescribeBlock(None, "Some context description", None) it_block = ItBlock(None, "Some it block description", None) reporter = PyneTreeReporter() reporter.report_enter_context(describe_block) reporter.report_pending(it_block) reporter.report_enter_context(describe_block) reporter.report_pending(it_block) reporter.report_enter_context(describe_block) reporter.report_pending(it_block) first_index = printed_text[1].find("Some it") expect(printed_text[3].find("Some it")).to_be(first_index + 2) expect(printed_text[5].find("Some it")).to_be(first_index + 4)
def test__when_a_test_is_pended__it_does_not_run_the_test(): reset() context = test_collection.current_describe.context context.calls = [] def it1(self): self.calls.append("it1") test_collection.current_describe.it_blocks = [ ItBlock(test_collection.current_describe, "some test", it1, pending=True) ] run_tests(test_collection.current_describe, StatTrackingReporter()) expect(context.calls).to_have_length(0)
def test__when_a_test_is_pended__it_reports_the_test_as_pending(): reset() context = test_collection.current_describe.context context.calls = [] def it1(self): self.calls.append("it1") test_collection.current_describe.it_blocks = [ ItBlock(test_collection.current_describe, "some test", it1, pending=True) ] reporter = StatTrackingReporter() run_tests(test_collection.current_describe, reporter) expect(reporter.stats.test_count).to_be(1) expect(reporter.stats.pending_count).to_be(1)
def test__reset__sets_stats_to_0(): describe_block = DescribeBlock(None, None, None) it_block = ItBlock(None, None, None) reporter = PyneStatSummaryReporter() reporter.report_enter_context(describe_block) reporter.report_enter_context(describe_block) reporter.report_success(it_block, 1000) reporter.report_failure(it_block, it_block, Exception("some exception"), 1000) reporter.report_failure(it_block, it_block, Exception("some exception"), 1000) reporter.reset() expect(reporter.stats.pass_count).to_be(0) expect(reporter.stats.is_failure).to_be(False) expect(reporter.stats.total_timing_millis).to_be(0) expect(reporter.stats.failure_count).to_be(0) expect(reporter.stats.test_count).to_be(0) expect(reporter.depth).to_be(0)
def named_focused_it(method): test_collection.current_describe.it_blocks.append( ItBlock(test_collection.current_describe, description, method, focused=True))
def named_xit(method): test_collection.current_describe.it_blocks.append( ItBlock(test_collection.current_describe, description, method, pending=True))