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__fit__flags_ancestors_as_having_focused_descendant(): grandparent_describe = DescribeBlock(None, None, None) parent_describe = DescribeBlock(grandparent_describe, None, None) current_describe = DescribeBlock(parent_describe, None, None) test_collection.current_describe = current_describe def some_method(): pass fit(some_method) expect(current_describe.has_focused_descendants).to_be(True) expect(parent_describe.has_focused_descendants).to_be(True) expect(grandparent_describe.has_focused_descendants).to_be(True)
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 pyne(tests_method): if config.report_between_suites: reporter.reset() describe_block = DescribeBlock(None, tests_method.__name__, tests_method) test_collection.collect_describe(describe_block) if config.report_between_suites: run_tests(describe_block, reporter) return tests_method
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_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_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__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")
def test__describe__when_using_string_description__sets_description(): current_describe = DescribeBlock(None, None, None) test_collection.current_describe = current_describe def some_method(): pass describe("some awesome description")(some_method) expect(current_describe.describe_blocks[0].description).to_be( "some awesome description")
def test__after_each__adds_after_each_block_to_current_describe(): current_describe = DescribeBlock(None, None, None) test_collection.current_describe = current_describe def some_method(): pass after_each(some_method) expect(current_describe.after_each_blocks).to_have_length(1) expect(current_describe.after_each_blocks[0].method).to_be(some_method) expect( current_describe.after_each_blocks[0].description).to_be("@after_each")
def test__report_enter_context__indents_based_on_tree_depth(): with StubPrint(): describe_block = DescribeBlock(None, "Some context description", None) reporter = PyneTreeReporter() printed_text.clear() reporter.report_enter_context(describe_block) reporter.report_enter_context(describe_block) reporter.report_enter_context(describe_block) first_indent = printed_text[0].find("Some context") expect(printed_text[1].find("Some context")).to_be(first_indent + 2) expect(printed_text[2].find("Some context")).to_be(first_indent + 4)
def describe(method_or_description): if isinstance(method_or_description, str): description = method_or_description def named_describe(method): test_collection.current_describe.describe_blocks.append( DescribeBlock(test_collection.current_describe, description, method)) return named_describe else: method = method_or_description test_collection.current_describe.describe_blocks.append( DescribeBlock(test_collection.current_describe, method.__name__, method)) return method_or_description
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__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 test__collect_describe__adds_children_to_the_describe(): def describe_block_method(): @describe def when_something_happens(): pass @it def does_something(): pass @before_each def do(): pass describe_block = DescribeBlock(None, None, describe_block_method) test_collection.collect_describe(describe_block) expect(describe_block.before_each_blocks).to_have_length(1) expect(describe_block.describe_blocks).to_have_length(1) expect(describe_block.it_blocks).to_have_length(1)
def test__collect_describe__when_there_are_nested_describes__collects_them(): def describe_block_method(): @describe def when_something_happens(): @before_each def do(): pass @it def does_something(): pass @describe def when_something_is_true(): pass describe_block = DescribeBlock(None, None, describe_block_method) test_collection.collect_describe(describe_block) expect( describe_block.describe_blocks[0].before_each_blocks).to_have_length(1) expect(describe_block.describe_blocks[0].describe_blocks).to_have_length(1) expect(describe_block.describe_blocks[0].it_blocks).to_have_length(1)
def __init__(self): self.top_level_describe = DescribeBlock(None, "All Tests", no_tests) self.current_describe = self.top_level_describe
def named_describe(method): test_collection.current_describe.describe_blocks.append( DescribeBlock(test_collection.current_describe, description, method))