コード例 #1
0
def test__report_end_result__when_a_test_has_failed__it_raises_test_failed():
    reporter = ExceptionReporter()

    it_block = ItBlock(None, None, None)
    reporter.report_failure(it_block, it_block, Exception("some exception"), 0)

    expect(reporter.report_end_result).to_raise_error_with_message("Tests failed.")
コード例 #2
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
 def _(self):
     some_instance = SomeClass()
     with stub(some_instance.some_method) as spy:
         some_instance.some_method("anything", ["can"], go="here")
         expect(spy.last_call).to_be((("anything", ["can"]), {
             "go": "here"
         }))
コード例 #3
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
 def _(self):
     some_instance = SomeClass()
     with stub(some_instance.some_method).then_return(
             "some_value") as spy:
         result = some_instance.some_method("anything", ["can"],
                                            go="here")
         expect(result).to_be("some_value")
コード例 #4
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
 def _(self):
     with stub(SomeClass.some_class_method) as spy:
         SomeClass.some_class_method("anything", ["can"], go="here")
         expect(spy.last_call).to_be((("anything", ["can"]), {
             "go": "here"
         }))
         expect(Spy.get_spy(SomeClass.some_class_method)).to_be(spy)
コード例 #5
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
 def _(self):
     some_instance = SomeClass()
     with stub('some_method', on=some_instance) as spy:
         some_instance.some_method("some_arg 123")
         expect(spy.last_call).to_be((("some_arg 123", ), {}))
         expect(Spy.get_spy(
             some_instance.some_method)).to_be(spy)
コード例 #6
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
        def _(self):
            some_instance = SomeOtherClass()

            with stub(some_instance.some_function).call_real():
                result = some_instance.some_function("anything", ["can"],
                                                     go="here")
                expect(result).to_be("some_value")
コード例 #7
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
def test__then_return__can_set_the_return_value_for_a_class_method():
    with TemporaryClass() as SomeTemporaryClass:
        when(SomeTemporaryClass.some_class_method).then_return("some value")

        expect(
            SomeTemporaryClass.some_class_method(
                "anything", ["can"], go="here")).to_be("some value")
コード例 #8
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
def test__stub__when_passed_in_an_instance_method__tracks_what_the_method_was_called_with(
):
    instance = SomeClass()
    spy = when(instance.some_method)

    instance.some_method("anything", ["can"], go="here")
    expect(spy.last_call).to_be((("anything", ["can"]), {"go": "here"}))
コード例 #9
0
ファイル: pyne_test_runner_test.py プロジェクト: Avvir/pyne
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"])
コード例 #10
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
def test__then_return__can_set_the_return_value_for_a_function():
    def some_function(*args, **kwargs):
        return "some_value"

    with when(some_function) as spy:
        spy.then_return("some_other_value")
        expect(spy.return_value).to_be("some_other_value")
コード例 #11
0
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")
コード例 #12
0
ファイル: pyne_test_runner_test.py プロジェクト: Avvir/pyne
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"])
コード例 #13
0
ファイル: attached_spy_test.py プロジェクト: Avvir/pyne
 def _(self):
     some_instance = SomeClass()
     with AttachedSpy(some_instance, "some_method") as spy:
         some_instance.some_method("some_arg")
         expect(spy.last_call).to_be((("some_arg", ), {}))
         expect(AttachedSpy.get_spy(
             some_instance.some_method)).to_be(spy)
コード例 #14
0
ファイル: pyne_test_runner_test.py プロジェクト: Avvir/pyne
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"])
コード例 #15
0
def test__matches_dict_matcher__when_dict_is_the_same_instance__explains_why_not(
):
    some_dict = {"some-key": "some-value"}

    matcher = MatchesDictMatcher(some_dict)
    matcher.matches(some_dict)
    expect(matcher.reason()).to_contain("it was the exact same instance")
コード例 #16
0
def test__for_an_instance_method__was_called__can_pass():
    some_instance = SomeClass()

    spy_on(some_instance.some_method)

    some_instance.some_method()
    expect(some_instance.some_method).was_called()
コード例 #17
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
def test__restore__after_stubbing_an_instance_method__sets_the_method_back_to_what_it_originally_was(
):
    instance = SomeClass()
    when(instance.some_method).then_return("some value")

    instance.some_method.restore()
    expect(instance.some_method("anything", ["can"], go="here")).to_be_none()
コード例 #18
0
ファイル: attached_spy_test.py プロジェクト: Avvir/pyne
 def _(self):
     some_instance = SomeClass()
     with AttachedSpy(some_instance, "some_method") as spy:
         some_instance.some_method("anything", ["can"], go="here")
         some_instance.some_method("or", ["here"], xor="here")
         expect(spy.calls).to_have_length(2)
         expect(spy.calls[1]).to_be((("or", ["here"]), {"xor": "here"}))
コード例 #19
0
ファイル: pyne_test_runner_test.py プロジェクト: Avvir/pyne
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)
コード例 #20
0
def test__for_a_static_method__was_called_with__can_pass():
    with TemporaryClass() as SomeTemporaryClass:
        spy_on(SomeTemporaryClass.some_static_method, on=SomeTemporaryClass)

        SomeTemporaryClass.some_static_method("some-positional-argument",
                                              ["some-array-content"])
        expect(SomeTemporaryClass.some_static_method).was_called_with(
            "some-positional-argument", ["some-array-content"])
コード例 #21
0
ファイル: pyne_tree_reporter_test.py プロジェクト: Avvir/pyne
def test__report_pending__prints_test_description():
    with StubPrint():
        it_block = ItBlock(None, "Some it block description", None)
        reporter = PrintingReporter(PyneTreeReporter())

        reporter.report_pending(it_block)

        expect(printed_text[0]).to_contain("Some it block description")
コード例 #22
0
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)
コード例 #23
0
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)
コード例 #24
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
def test__stub__when_spying_on_a_function__tracks_what_the_stubbed_method_returns(
):
    def some_function(*args, **kwargs):
        return "some_value"

    with spy_on(some_function) as spy:
        spy("anything", ["can"], go="here")
        expect(spy.return_value).to_be(None)
コード例 #25
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
def test__restore__causes_the_spy_to_return_none():
    spy = Spy()

    spy.then_return("some value")
    expect(spy("anything", ["can"], go="here")).to_be("some value")

    spy.restore()
    expect(spy("anything", ["can"], go="here")).to_be_none()
コード例 #26
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
def test__restore__resets_what_the_spy_was_last_called_with():
    spy = Spy()

    spy("anything", ["can"], go="here")
    expect(spy.last_call).to_be((("anything", ["can"]), {"go": "here"}))

    spy.restore()
    expect(spy.last_call).to_be_none()
コード例 #27
0
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)
コード例 #28
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
def test__stub__when_spying_on_a_function__tracks_what_the_method_was_called_with(
):
    def some_function(*args, **kwargs):
        return "some_value"

    with spy_on(some_function) as spy:
        spy("anything", ["can"], go="here")
        expect(spy.last_call).to_be((("anything", ["can"]), {"go": "here"}))
コード例 #29
0
 def _(self):
     with attach_stub(matching, "match_images_with_pairs"):
         images = self.images
         pairs_matches, preport = matching.match_images(
             self.data, images, images)
         args, kwargs = last_call_of(matching.match_images_with_pairs)
         data, exifs, ref_images, pairs = args
         expect(pairs).to_be(self.expected_pairs)
コード例 #30
0
ファイル: spy_test.py プロジェクト: Avvir/pyne
def test__then_return__returns_the_given_value_when_a_stubbed_method_is_called(
):
    instance = SomeClass()

    when(instance.some_method).then_return("some value")

    expect(instance.some_method("anything", ["can"],
                                go="here")).to_be("some value")