コード例 #1
0
 def expect_invalid(self, *, default, override):
     key = "thing"
     defaults = {} if default is UNSET else {key: default}
     if override is not UNSET:
         self.context.os.environ[key] = override
     cfg = ModuleCfg(defaults=defaults)
     expect(partial(getattr, cfg, key)).to(complain(InvalidConfiguration))
コード例 #2
0
    def test_requires_requests_response_object(self):
        def init_good_operation_failed():
            fake_requests_response = requests.Response()
            fake_requests_response.json = lambda: {"errors": "who cares"}
            OperationFailed(requests_response=fake_requests_response)

        expect(init_good_operation_failed).to_not(complain(TypeError))
コード例 #3
0
    def test_complains_when_row_contains_too_few_columns(self):
        table = (("one", "two"), ("surprise", "fear"))

        def func(one, two, three):
            pass

        expect(partial(execute_test_table, func=func,
                       table=table)).to(complain(TypeError))
コード例 #4
0
 def test_event_and_events_are_mutually_exclusive(self):
     expect(
         partial(
             EventBroker.subscribe,
             event=TestEvent.test_started,
             events=(TestEvent.test_ended, TestEvent.test_erred),
             func=lambda **k: None,
         )).to(complain(TypeError))
コード例 #5
0
    def test_sends_data_as_a_json_formatted_string(self):
        self.default_execute()

        data = self.post_spy.kwargs_from_last_call()["data"]

        def json_loads():
            json.loads(data)

        expect(json_loads).to_not(complain(json.decoder.JSONDecodeError))
コード例 #6
0
    def test_complains_when_row_contains_too_many_columns(self):
        table = (("one", "two", "three"), ("surprise", "fear",
                                           "ruthless efficiency"))

        def func(one, two):
            pass

        expect(partial(execute_test_table, func=func,
                       table=table)).to(complain(TypeError))
コード例 #7
0
    def test_complains_on_kwarg_name_mismatch(self):
        table = (("one", "two", "three"), ("surprise", "fear",
                                           "ruthless efficiency"))

        def func(*, one, two, five):
            pass

        expect(partial(execute_test_table, func=func,
                       table=table)).to(complain(TypeError))
コード例 #8
0
    def test_kwarg_mismatch_check_not_tripped_up_by_local_variables(self):
        table = (("one", "two", "three"), ("surprise", "fear",
                                           "ruthless efficiency"))

        def func(one, two):
            three = None
            three

        expect(partial(execute_test_table, func=func,
                       table=table)).to(complain(TypeError))
コード例 #9
0
 def test_assert_was_called_does_not_complain_when_called(self):
     spy = FunctionSpy()
     spy()
     expect(spy.assert_was_called).not_to(complain(FunctionNotCalled))
コード例 #10
0
 def test_args_from_last_call_complains_when_there_are_no_calls(self):
     expect(FunctionSpy().args_from_last_call).to(
         complain(FunctionNotCalled))
コード例 #11
0
 def test_complains_if_there_were_no_calls(self):
     expect(lambda: FunctionSpy()[0]).to(complain(FunctionNotCalled))
コード例 #12
0
 def test_complains_when_requested_arg_is_absent(self):
     spy = FunctionSpy()
     spy(0, 1)
     expect(lambda: spy[2]).to(complain(ArgNotSpecified))
コード例 #13
0
 def test_complains_when_requested_kwarg_is_absent(self):
     spy = FunctionSpy()
     spy(things=2)
     expect(lambda: spy["stuff"]).to(complain(KwargNotSpecified))
コード例 #14
0
 def test_can_use_falsy_object_patterns(self):
     fake = EmptyFake(pattern_obj=set())
     expect(lambda: fake.spam).to(complain(AttributeError))
コード例 #15
0
 def test_requires_event_or_events(self):
     expect(partial(EventBroker.subscribe,
                    func=lambda **k: None)).to(complain(TypeError))
コード例 #16
0
 def test_does_not_wait_after_other_exception(self):
     self.webdriver.Remote = func_that_raises(FakeException())
     expect(Browser).to(complain(FakeException))
コード例 #17
0
 def test_setitem_is_present(self):
     expect(lambda: EmptyFake()["spam"]).not_to(complain(TypeError))
コード例 #18
0
 def test_getattr_does_not_invent_private_attributes(self):
     expect(lambda: EmptyFake()._private).to(complain(AttributeError))
コード例 #19
0
 def test_check_for_both_patterns_not_fooled_by_falsy_objects(self):
     expect(lambda: EmptyFake(pattern_cls=str, pattern_obj=0)).to(
         complain(TypeError))
コード例 #20
0
 def test_complains_about_attempt_to_set_pattern_obj_and_cls(self):
     expect(lambda: EmptyFake(pattern_cls=str, pattern_obj=1)).to(
         complain(TypeError))
コード例 #21
0
 def test_raises_attribute_error_on_attempt_to_break_pattern_cls(self):
     fake = EmptyFake(pattern_cls=str)
     expect(lambda: fake.spam).to(complain(AttributeError))
コード例 #22
0
 def test_complains_when_module_not_found(self):
     expect(partial(config_for_module,
                    "no_esta")).to(complain(NoSuchRecord))
コード例 #23
0
 def test_last_call_to_raises_function_not_called(self):
     stub = EmptyFake()
     stub.func = lambda: None
     spy = MasterSpy(stub)
     expect(lambda: spy.last_call_to("func")).to(
         complain(FunctionNotCalled))
コード例 #24
0
 def test_last_call_complains_when_not_called(self):
     expect(FunctionSpy().last_call).to(complain(FunctionNotCalled))
コード例 #25
0
    def test_can_be_context_manager(self):
        def attempt():
            with EmptyFake(1, beans=0):
                pass

        expect(attempt).not_to(complain(TypeError))
コード例 #26
0
 def test_raises_attribute_error_on_attempt_to_break_pattern_object(self):
     pattern = object()
     fake = EmptyFake(pattern_obj=pattern)
     expect(lambda: fake.nope).to(complain(AttributeError))
コード例 #27
0
    def test_complains_when_sample_size_is_negative(self):
        table = (("foo", "sample size"), (12, -1))

        expect(partial(execute_test_table, table=table,
                       func=lambda foo: None)).to(complain(TypeError))
コード例 #28
0
    def test_delitem_is_present(self):
        def attempt():
            del EmptyFake()["witch"]

        expect(attempt).not_to(complain(TypeError))
コード例 #29
0
    def test_accepts_arbitrary_args_and_kwargs(self):
        def attempt():
            with empty_context_manager(7, spams=2):
                pass

        expect(attempt).not_to(complain(TypeError))
コード例 #30
0
 def test_call_accepts_arbitary_args_and_kwargs(self):
     expect(lambda: EmptyFake()(4, spams=1)).not_to(complain(TypeError))