def test__when_there_are_before_each_blocks_for_another_describe__it_doesnt_run_them( ): reset() context = test_collection.current_describe.context context.calls = [] @describe def when_context_1(): @describe def when_context_2(): @before_each def do(self): self.calls.append("before1") @describe def when_context_3(): @it def do_something_1(self): self.calls.append("it1") outer_describe = test_collection.current_describe.describe_blocks[0] test_collection.collect_describe(outer_describe) run_tests(test_collection.top_level_describe, ExceptionReporter()) expect(context.calls).to_be(["it1"])
def test__when_there_are_nested_describes__it_runs_them(): reset() context = test_collection.current_describe.context context.calls = [] @describe def when_context_1(): @it def do_first_thing(self): self.calls.append("it1") @describe def when_context_2(): @describe def when_context_3(): @it def do_second_thing(self): self.calls.append("it2") @describe def when_context_4(): @it def do_third_thing(self): self.calls.append("it3") @it def do_fourth_thing(self): self.calls.append("it4") outer_describe = test_collection.current_describe.describe_blocks[0] test_collection.collect_describe(outer_describe) run_tests(test_collection.top_level_describe, ExceptionReporter()) expect(context.calls).to_be(["it1", "it2", "it3", "it4"])
def test__when_a_before_block_fails__it_runs_it_blocks_in_the_next_describe(): reset() context = test_collection.current_describe.context context.calls = [] @describe def outer_describe(): @describe def some_describe(): @before_each def some_before_each_that_raises(self): raise Exception("Some Setup exception") @it def some_test(): pass @describe def some_second_describe(): @it def some_second_test(self): self.calls.append("some-it") outer_describe = test_collection.current_describe.describe_blocks[0] test_collection.collect_describe(outer_describe) try: run_tests(test_collection.top_level_describe, ExceptionReporter()) except Exception: pass finally: expect(context.calls).to_be(["some-it"])
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_reports_failures(): error = None try: @pyne def some_test_suite(): @describe("some scenario") def _(): @it def some_test(self): pass @describe def some_other_scenario(): @it def some_failing_test(self): raise Exception("some failing test") @it def some_passing_test(self): pass except Exception as e: error = e finally: expect(error.args[0]).to_contain("failed")
def test__to_raise_error_of_type__can_pass(): class SomeException(Exception): pass def error_method(): raise SomeException() expect(error_method).to_raise_error_of_type(SomeException)
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_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_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_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__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__when_a_test_fails__raises_an_error(): reset() @it def failing_test(self): expect(1).to_be(2) expect(lambda: run_tests(test_collection.current_describe, ExceptionReporter())) \ .to_raise_error_with_message(anything())
def test__report_end_result__when_no_tests_run__reports_stats(): with StubPrint(): reporter = PyneStatSummaryReporter() printed_text.clear() reporter.report_end_result() expect(printed_text[0]).to_contain("Ran 0 tests")
def test__fit__flags_the_it_block_as_focused(): current_describe = DescribeBlock(None, None, None) test_collection.current_describe = current_describe def some_method(): pass fit(some_method) expect(current_describe.it_blocks[0].focused).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_enter_context__prints_context_description(): with StubPrint(): describe_block = DescribeBlock(None, "Some context description", None) reporter = PyneTreeReporter() printed_text.clear() reporter.report_enter_context(describe_block) expect(printed_text[0]).to_contain("Some context description")
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_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_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__was_called_with__can_pass(): some_instance = SomeClass() stub(some_instance, some_instance.some_method) some_instance.some_method("some-positional-argument", ["some-array-content"]) expect(some_instance.some_method).was_called_with( "some-positional-argument", ["some-array-content"])
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_enter_context__increases_depth(): reporter = PyneStatSummaryReporter() describe_block = DescribeBlock(None, None, None) reporter.report_enter_context(describe_block) expect(reporter.depth).to_be(1) reporter.report_enter_context(describe_block) expect(reporter.depth).to_be(2)
def test__when_there_is_a_tests_directory_with_a_test_file__runs_the_test(): runner = CliRunner() with runner.isolated_filesystem(): copy_to_working_directory(path.join(cli_test_fixture_path, 'tests')) copy_to_working_directory(pyne_path) result = runner.invoke(cli.main) expect(result.output).to_contain("some_single_test") expect(result.output).to_contain("1 passed")
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__when_there_are_focused_tests__runs_only_those_tests(): runner = CliRunner() with runner.isolated_filesystem(): copy_to_working_directory( path.join(cli_focused_test_fixture_path, 'tests')) copy_to_working_directory(pyne_path) result = runner.invoke(cli.main) expect(result.output).to_contain("can be focused") expect(result.output).to_contain("4 passed")
def test__fdescribe__adds_a_describe_block_to_current_describe(): current_describe = DescribeBlock(None, None, None) test_collection.current_describe = current_describe def some_method(): pass fdescribe("some context")(some_method) expect(current_describe.describe_blocks).to_have_length(1) expect(current_describe.describe_blocks[0].method).to_be(some_method)
def test__it__adds_it_block_to_current_describe(): current_describe = DescribeBlock(None, None, None) test_collection.current_describe = current_describe def some_method(): pass it(some_method) expect(current_describe.it_blocks).to_have_length(1) expect(current_describe.it_blocks[0].method).to_be(some_method)
def test__it__when_using_string_description__adds_it_block_to_describe(): current_describe = DescribeBlock(None, None, None) test_collection.current_describe = current_describe def some_method(): pass it("some it name")(some_method) expect(current_describe.it_blocks).to_have_length(1) expect(current_describe.it_blocks[0].method).to_be(some_method)
def test__it__when_using_string_description__sets_the_description(): current_describe = DescribeBlock(None, None, None) test_collection.current_describe = current_describe def some_method(): pass it("some cool thing happens")(some_method) expect(current_describe.it_blocks[0].description).to_be( "some cool thing happens")