示例#1
0
 def test_does_not_subscribe_to_unspecified(self):
     all_events = list(TestEvent)
     events = (all_events[1], all_events[3], all_events[5])
     spy = FunctionSpy()
     EventBroker.subscribe(events=events, func=spy)
     EventBroker.publish(event=all_events[2])
     expect(spy.call_history).to(be_empty)
示例#2
0
 def test_subscribes_to_last(self):
     all_events = list(TestEvent)
     events = (all_events[1], all_events[3], all_events[5])
     spy = FunctionSpy()
     EventBroker.subscribe(events=events, func=spy)
     EventBroker.publish(event=events[-1])
     spy.assert_was_called()
    def test_publishes_event_before_sending_the_request(self):

        event_published = False
        request_sent = False
        request_sent_before_event_published = False

        def stub_post(*args, **kwargs):
            nonlocal request_sent
            request_sent = True
            return EndlessFake()

        def mock_subscriber(**kwargs):
            nonlocal event_published
            nonlocal request_sent_before_event_published
            event_published = True
            request_sent_before_event_published = request_sent

        self.requests_stub.post = stub_post

        EventBroker.subscribe(event=TestEvent.http_request_sent,
                              func=mock_subscriber)

        HttpClient().post("http://something")
        assert event_published, "The event was not published"
        assert not request_sent_before_event_published, "Thre request was sent before the event was published"
        assert request_sent, "Request was not sent after the event was published"
    def test_publishes_test_ended_after_test_erred(self):
        table = (("thing", ), (14, ))
        test_erred = False
        test_ended = False
        ended_before_erred = False

        def ended(**kwargs):
            nonlocal ended_before_erred
            nonlocal test_ended
            test_ended = True
            ended_before_erred = not test_erred

        def erred(**kwargs):
            nonlocal test_erred
            nonlocal ended_before_erred
            test_erred = True

        def test_func(thing):
            raise RuntimeError("An exception escaped the test block")

        EventBroker.subscribe(event=TestEvent.test_ended, func=ended)
        EventBroker.subscribe(event=TestEvent.test_erred, func=erred)
        execute_test_table(table=table, func=test_func)
        assert test_ended, "Test was not ended"
        assert not ended_before_erred, "Test ended before it erred"
    def test_publishes_test_ended_after_test_failed(self):
        table = (("thing", ), (14, ))
        test_failed = False
        test_ended = False
        ended_before_failed = False

        def ended(**kwargs):
            nonlocal ended_before_failed
            nonlocal test_ended
            test_ended = True
            ended_before_failed = not test_failed

        def failed(**kwargs):
            nonlocal test_failed
            nonlocal ended_before_failed
            test_failed = True

        def test_func(thing):
            assert False, "An assertion error escaped"

        EventBroker.subscribe(event=TestEvent.test_ended, func=ended)
        EventBroker.subscribe(event=TestEvent.test_failed, func=failed)
        execute_test_table(table=table, func=test_func)
        assert test_ended, "Test was not ended"
        assert not ended_before_failed, "Test ended before it failed"
示例#6
0
 def setUp(self):
     EventBroker.reset()
     self.published = None
     self.context = open_dependency_context()
     self.fake_requests = FakeRequests()
     self.context.inject(requests, self.fake_requests)
     EventBroker.subscribe(event=TestEvent.artifact_created,
                           func=self.on_artifact_created)
    def test_does_not_publish_sample_measured_if_erred(self):
        def test_func(item):
            raise Exception("Hello!")

        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.sample_measured, func=spy)
        execute(func=test_func)
        expect(spy.call_history).to(be_empty)
    def test_does_not_publish_sample_measured_if_failed(self):
        def test_func(item):
            assert False, "yadda"

        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.sample_measured, func=spy)
        execute(func=test_func)
        expect(spy.call_history).to(be_empty)
示例#9
0
 def test_publishes_event_type(self):
     all_events = list(TestEvent)
     events = (all_events[1], all_events[3], all_events[5])
     published = events[1]
     spy = FunctionSpy()
     EventBroker.subscribe(events=events, func=spy)
     EventBroker.publish(event=published)
     expect(spy["event"]).to(equal(published))
 def setUp(self):
     self.context = open_dependency_context(supply_env=True)
     fake_webdriver = FakeWebdriver()
     self.context.inject(webdriver, fake_webdriver)
     self.events_captured = []
     EventBroker.subscribe(event=TestEvent.artifact_created,
                           func=self.capture_event)
     self.sut = Browser()
 def setUp(self):
     EventBroker.reset()
     self.sut = JunitReporter()
     self.sut.activate()
     self.suite_name = "HowSuite"
     self.published_kwargs = {}
     EventBroker.subscribe(event=TestEvent.report_created,
                           func=self.capture_published_kwargs)
    def test_publishes_test_failed_with_suite_name(self):
        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.test_failed, func=spy)

        def test_func(item):
            assert False, "Albatross!"

        execute(func=test_func)
        expect(spy["suite_name"]).to(equal(SUITE_NAME))
    def test_publishes_test_failed_with_test_name(self):
        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.test_failed, func=spy)

        def test_func(item):
            assert False, "Oh no, you don't"

        execute(func=test_func)
        expect(spy["test_name"]).to(equal(TEST_NAMES[-1]))
    def test_publishes_test_erred_with_suite_name(self):
        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.test_erred, func=spy)

        def test_func(item):
            raise RuntimeError("SPAMoni")

        execute(func=test_func)
        expect(spy["suite_name"]).to(equal(SUITE_NAME))
    def test_publishes_test_erred_with_test_name(self):
        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.test_erred, func=spy)

        def test_func(item):
            raise Exception("intentional")

        execute(func=test_func)
        expect(spy["test_name"]).to(equal(TEST_NAMES[-1]))
    def test_publishes_test_skipped_with_suite_name(self):
        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.test_skipped, func=spy)

        def test_func(item):
            raise TestSkipped("intentional")

        execute(func=test_func)
        expect(spy["suite_name"]).to(equal(SUITE_NAME))
示例#17
0
 def setUp(self):
     self.context = open_dependency_context()
     self.fake_time = FakeDatetime()
     self.context.inject(datetime, self.fake_time)
     self.results = None
     EventBroker.subscribe(event=TestEvent.suite_results_compiled,
                           func=self.capture_results)
     self.sut = ResultCompiler()
     self.sut.activate()
示例#18
0
 def setUp(self):
     EventBroker.reset()
     EventBroker.subscribe(event=TestEvent.artifact_created,
                           func=self.catch_artifact_event)
     self.context = open_dependency_context(supply_env=True, supply_fs=True)
     self.fake_webdriver = FakeWebdriver()
     self.context.inject(webdriver, self.fake_webdriver)
     self.sut = Browser()
     self.artifact_events = []
示例#19
0
    def test_unbound_subscriber_gets_garbage_collected(self):
        def subscriber():
            Evidence.subscriber_ran = True

        EventBroker.subscribe(event=EVENT, func=subscriber)
        subscriber = None
        gc.collect()
        EventBroker.publish(event=EVENT)
        assert not Evidence.subscriber_ran, "Subscriber ran after it should have been garbage collected"
    def test_publishes_test_failed_with_exception(self):
        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.test_failed, func=spy)
        raised = AssertionError("spammy spam spam")

        def test_func(item):
            raise raised

        execute(func=test_func)
        expect(spy["exception"]).to(be(raised))
 def setUp(self):
     self.context = open_dependency_context(supply_env=True)
     EventBroker.reset()
     EventBroker.subscribe(event=TestEvent.artifact_created, func=self.catch_artifact_event)
     self.artifact_events_caught = []
     self.fake_webdriver = FakeWebdriver()
     self.context.inject(webdriver, self.fake_webdriver)
     self.fake_dump = "yaddayaddayadda"
     self.context.inject(dump_dom, lambda x: self.fake_dump)
     self.sut = Browser()
    def test_advances_to_next_row_after_failure(self):
        table = (("thing", ), ("spam", ), ("eggs", ), ("sausage", ))
        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.test_started, func=spy)

        def test_func(thing):
            assert False, "I told you so"

        execute_test_table(func=test_func, table=table)
        expect(spy.call_history).to(have_length(3))
示例#23
0
    def test_does_not_attempt_to_run_garbage_collected_subscriber(self):
        def subscriber():
            pass

        EventBroker.subscribe(event=EVENT, func=subscriber)
        subscriber = None
        gc.collect()
        EventBroker.publish(event=EVENT)
        assert not self.errors_logged(
        ), 'Unexpected errors in the log: "%s"' % (self.errors_logged())
    def test_advances_to_next_row_after_error(self):
        table = (("thing", ), ("spam", ), ("eggs", ), ("sausage", ))
        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.test_started, func=spy)

        def test_func(thing):
            raise RuntimeError("Nobody expects the Spinach Imposition!")

        execute_test_table(func=test_func, table=table)
        expect(spy.call_history).to(have_length(3))
        pass
    def test_does_not_raise_exception_from_subscriber(self):
        def bad_subscriber(**kwargs):
            raise Exception("intentional walrus")

        event = "spamorama"
        EventBroker.subscribe(event=event, func=bad_subscriber)

        def attempt():
            EventBroker.publish(event=event)

        expect(attempt).not_to(raise_error(Exception))
    def test_publishes_sample_measured_with_sample_parameters(self):
        params = {"foo": 14, "bar": "all night", "baz": {"spam": "you betcha"}}
        table = (list(params.keys()), list(params.values()))

        def test_func(foo, bar, baz):
            pass

        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.sample_measured, func=spy)
        execute_test_table(table=table, func=test_func)
        expect(spy["sample_parameters"]).to(equal(params))
示例#27
0
    def test_request_uuid_is_a_uuid(self):
        published_uuid = None

        def subscriber(request_uuid, **kwargs):
            nonlocal published_uuid
            published_uuid = request_uuid

        EventBroker.subscribe(event=TestEvent.http_request_sent,
                              func=subscriber)
        HttpClient().get("http://spam.spam")
        expect(published_uuid).to(be_a(uuid.UUID))
    def test_advances_to_next_row_after_skip(self):
        table = (("thing", ), ("spam", ), ("eggs", ), ("sausage", ))
        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.test_started, func=spy)

        def test_func(thing):
            raise TestSkipped("I prefer not to")

        execute_test_table(func=test_func, table=table)
        expect(spy.call_history).to(have_length(3))
        pass
    def test_publishes_test_erred_when_different_exception_raised(self):
        table = (("expect exception", ), (EOFError, ))
        raised = ValueError()
        spy = FunctionSpy()
        EventBroker.subscribe(event=TestEvent.test_erred, func=spy)

        def test_func():
            raise raised

        execute_test_table(table=table, func=test_func)
        expect(spy["exception"]).to(equal(raised))
    def test_publishes_request_data(self):
        planted_data = "blah blah blah blah blah"
        published_data = None

        def subscriber(request_data, **kwargs):
            nonlocal published_data
            published_data = request_data

        EventBroker.subscribe(event=TestEvent.http_request_sent,
                              func=subscriber)
        HttpClient().post("https://blah.blah", data=planted_data)
        expect(published_data).to(equal(planted_data))