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"
Exemplo n.º 3
0
 def test_suite_erred_message(self):
     err = RuntimeError("something broke")
     EventBroker.publish(event=TestEvent.suite_erred,
                         suite_name="spam",
                         exception=err)
     level, msg = self.logged()
     expect(msg).to(equal(format_exception(err)))
Exemplo n.º 4
0
 def test_does_not_quit_when_debugging_and_test_failed(self):
     self.set_debug_flag()
     sut = Browser()
     sut
     EventBroker.publish(event=TestEvent.test_failed)
     EventBroker.publish(event=TestEvent.suite_ended)
     assert not self.quit_was_called(), "quit() was called"
Exemplo n.º 5
0
 def test_sample_measured_level(self):
     EventBroker.publish(event=TestEvent.sample_measured,
                         test_name="spam",
                         sample_parameters="spam",
                         sample_execution_seconds=0)
     level, msg = self.logged()
     expect(level).to(equal("info"))
Exemplo n.º 6
0
 def setUp(self):
     close_all_dependency_contexts()
     disable_default_reporters()
     self.context = open_dependency_context(supply_fs=True)
     self.fake_logging = FakeLogging()
     self.context.inject(logging, self.fake_logging)
     EventBroker.reset()
    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"
Exemplo n.º 8
0
 def test_uses_given_time_if_specified(self):
     event = 12
     expected = self.fake_now + timedelta(minutes=42)
     subscriber = Subscriber(event=event)
     EventBroker.publish(event=event, event_time=expected)
     expect(subscriber.kwargs_received).to(
         contain_key_with_value("event_time", expected))
Exemplo n.º 9
0
 def setUp(self):
     EventBroker.reset()
     self.context = open_dependency_context()
     self.fake_now = datetime.fromtimestamp(1515429469.61845)
     self.fake_datetime_module = EmptyFake()
     self.fake_datetime_module.now = lambda: self.fake_now
     self.context.inject(datetime, self.fake_datetime_module)
Exemplo n.º 10
0
 def setUp(self):
     self.context = open_dependency_context(supply_fs=True,
                                            supply_logging=True)
     self.context.inject(StreamHandler, EmptyFake())
     EventBroker.reset()
     subscribe_event_handlers(self)
     self.skip_events = 0
Exemplo n.º 11
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()
Exemplo n.º 12
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)
Exemplo n.º 13
0
 def test_attaches_artifact_to_suite_when_no_test_named(self):
     artifact = b"fffffffffffffff"
     start_suite()
     EventBroker.publish(event=TestEvent.artifact_created,
                         artifact=artifact)
     end_suite()
     results = self.retrieve_results()
     expect(results.artifacts).to(contain(artifact))
    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)
Exemplo n.º 15
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)
Exemplo n.º 16
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))
Exemplo n.º 17
0
 def test_test_skipped_level(self):
     err = TestSkipped("Let's not go there")
     test_name = "A rather silly place"
     EventBroker.publish(event=TestEvent.test_skipped,
                         exception=err,
                         test_name=test_name)
     level, msg = self.logged()
     expect(level).to(equal("warning"))
Exemplo n.º 18
0
 def test_test_failed_message(self):
     err = AssertionError("oops")
     test_name = "Test tea"
     EventBroker.publish(event=TestEvent.test_failed,
                         exception=err,
                         test_name=test_name)
     level, msg = self.logged()
     expect(msg).to(equal('Check "%s" failed: %s' % (test_name, err)))
 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()
Exemplo n.º 20
0
 def test_test_skipped_message(self):
     err = TestSkipped("Let's not go there")
     test_name = "A rather silly place"
     EventBroker.publish(event=TestEvent.test_skipped,
                         exception=err,
                         test_name=test_name)
     level, msg = self.logged()
     expect(msg).to(equal('Check "%s" skipped: %s' % (test_name, err)))
Exemplo n.º 21
0
 def test_creates_suite_exception_if_none_specified(self):
     suite_name = "Squirelly Suite"
     start_suite(suite_name)
     EventBroker.publish(event=TestEvent.suite_erred,
                         suite_name=suite_name,
                         exception=RuntimeError())
     end_suite()
     expect(self.retrieve_results().suite_exception).to(be_a(Exception))
 def publish_results(self):
     self.results = SuiteResults()
     self.results.suite_name = self.suite_name
     self.results.tests = [
         TestResult(test_name="Test %d" % n) for n in range(4)
     ]
     EventBroker.publish(event=TestEvent.suite_results_compiled,
                         suite_results=self.results)
    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)
 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)
Exemplo n.º 25
0
 def setUp(self):
     EventBroker.reset()
     self.context = open_dependency_context(supply_env=True, supply_fs=True)
     self.fake_file = FakeFile()
     self.context.inject(open, self.fake_file.open)
     self.makedirs_spy = MasterSpy(self.context.os.makedirs)
     self.context.os.makedirs = self.makedirs_spy
     self.sut = ArtifactSaver()
     self.sut.activate()
Exemplo n.º 26
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 = []
 def test_saves_artifact_with_suite_and_test_to_test_dir_under_suite(self):
     suite_name = "Libations"
     test_name = "test_tea"
     EventBroker.publish(event=TestEvent.suite_started,
                         suite_name=suite_name)
     publish_artifact(test_name=test_name)
     run_id, kind, suite, test, filename = self.extract_key_parts()
     expect(suite).to(equal(suite_name))
     expect(test).to(equal(test_name))
Exemplo n.º 28
0
 def test_saves_artifact_with_suite_and_test_to_test_dir_under_suite(self):
     suite_name = "Libations"
     test_name = "test_tea"
     EventBroker.publish(event=TestEvent.suite_started,
                         suite_name=suite_name)
     publish(test_name=test_name)
     actual_path, _ = os.path.split(self.fake_file.filename)
     expect(actual_path).to(
         equal(os.path.join(self.artifacts_path, suite_name, test_name)))
Exemplo n.º 29
0
 def on_suite_erred(self, suite_name=None, test_name=None, **kwargs):
     EventBroker.publish(
         event=TestEvent.artifact_created,
         artifact=str(self._transcript),
         artifact_mime_type="text/plain",
         artifact_type="http_transcript",
         suite_name=suite_name,
         test_name=test_name,
     )
Exemplo n.º 30
0
 def test_attaches_exception_to_errant_suite(self):
     suite_name = "SPAMmy Suite"
     exception = RuntimeError("I don't like SPAM!")
     start_suite(suite_name)
     EventBroker.publish(event=TestEvent.suite_erred,
                         suite_name=suite_name,
                         exception=exception)
     end_suite()
     expect(self.retrieve_results().suite_exception).to(equal(exception))