Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
def test__report_enter_context__prints_context_description():
    with StubPrint():
        describe_block = DescribeBlock(None, "Some context description", None)
        reporter = PrintingReporter(PyneTreeReporter())
        printed_text.clear()

        reporter.report_enter_context(describe_block)

        expect(printed_text[0]).to_contain("Some context description")
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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)
Ejemplo n.º 6
0
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")
Ejemplo n.º 7
0
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")
Ejemplo n.º 8
0
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")
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
def test__report_enter_context__indents_based_on_tree_depth():
    with StubPrint():
        describe_block = DescribeBlock(None, "Some context description", None)
        reporter = PrintingReporter(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)
Ejemplo n.º 11
0
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
Ejemplo n.º 12
0
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 = PrintingReporter(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)
Ejemplo n.º 13
0
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)
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
def test__when_a_describe_block_with_nested_describes_is_pended__it_reports_the_contained_tests_as_pending(
):
    reset()

    describe_block = DescribeBlock(None, "some describe", None, pending=True)
    inner_describe = DescribeBlock(describe_block, "some inner description",
                                   None)
    describe_block.describe_blocks = [inner_describe]

    def it1(self):
        pass

    inner_describe.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)
Ejemplo n.º 17
0
 def named_describe(method):
     test_collection.current_describe.describe_blocks.append(
             DescribeBlock(test_collection.current_describe, description, method))
Ejemplo n.º 18
0
 def __init__(self):
     self.top_level_describe = DescribeBlock(None, "All Tests", no_tests)
     self.current_describe = self.top_level_describe
Ejemplo n.º 19
0
def test__when_a_describe_block_has_focused_descendants__it_runs_only_the_focused_tests(
):
    reset()

    describe_block = DescribeBlock(None, "some describe", None)
    inner_describe = DescribeBlock(describe_block, "some inner description",
                                   None)
    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, focused=True),
        ItBlock(describe_block, "some test", it1)
    ]
    describe_block.has_focused_descendants = True
    inner_describe.has_focused_descendants = True

    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(1)