def test_does_not_create_duplicate_test_on_test_started(self):
     name = "spam"
     start_suite()
     fail_test(name)
     start_test(name)
     end_suite()
     expect(self.retrieve_results().tests).to(have_length(1))
 def retrieve_report(self):
     # Our master spy monitors the TestSuite class,
     # so each of its return value spies monitors an instance of the class.
     spies = self.spy.return_value_spies
     # We expect only one instance to have been created
     expect(spies).to(have_length(1))
     return spies[0].unwrap_spy_target()
 def test_test_started_but_not_ended_has_status_running(self):
     start_suite()
     start_test()
     end_suite()
     results = self.retrieve_results()
     expect(results.tests).to(have_length(1))
     expect(results.tests[0].status).to(equal(TestStatus.running))
 def test_puts_test_name_in_first_test(self):
     name = "Sam Samson"
     start_suite()
     start_test(name)
     end_suite()
     results = self.retrieve_results()
     expect(results.tests).to(have_length(1))
     expect(results.tests[0].name).to(equal(name))
 def test_test_status_pass(self):
     start_suite()
     start_test()
     end_test()
     end_suite()
     results = self.retrieve_results()
     expect(results.tests).to(have_length(1))
     expect(results.tests[0].status).to(equal(TestStatus.passed))
 def test_uses_same_python_executable_as_self(self):
     expected = "/path/to/python"
     self.context.inject(sys.executable, expected)
     self.fake_file(filename="./whatever.py")
     run_all(".")
     opened = self.popen_class.opened
     expect(opened).to(have_length(1))
     expect(opened[0]["args"][0]).to(equal(expected))
 def test_sends_stdout_to_pipe(self):
     path = "things"
     filename = os.path.join(path, "thing.py")
     self.fake_file(filename)
     run_all(path)
     opened = self.popen_class.opened
     expect(opened).to(have_length(1))
     expect(opened[0]["kwargs"]).to(contain_key_with_value("stdout", PIPE))
    def test_list_of_collectors_returned_for_valid_survey(self):
        collector = Collector(connection=self.connection)
        mock = CollectorsListMock(total=2, survey_id=self.survey_id)

        with HTTMock(mock.list):
            collector_list = collector.list(survey_id=self.survey_id)

        expect(collector_list).to(have_length(2))
        expect(collector_list[0]).to(have_keys('href', 'id', 'name'))
 def test_creates_missing_test_on_test_skipped(self):
     test_name = "oops"
     start_suite()
     skip_test(test_name)
     end_suite()
     results = self.retrieve_results()
     expect(results.tests).to(have_length(1))
     test = results.tests[0]
     expect(test.name).to(equal(test_name))
    def test_get_big_list_of_all_surveys(self):
        with HTTMock(self.mocks.surveys):
            survey_big_list = self.surveys.surveys()

        expect(survey_big_list).to(have_length(125))

        for survey in survey_big_list:
            expect(survey).to(have_keys('href', 'id', 'title'))
            expect(survey["href"]).to(end_with(survey['id']))
    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))
 def test_contains_exception_stack_trace(self):
     exception = RuntimeError("failed intentionally")
     self.publish(TestEvent.suite_started)
     self.publish(TestEvent.suite_erred, exception=exception)
     self.publish(TestEvent.suite_ended)
     test = self.extract_dummy_test()
     failures = test.findall("./error")
     expect(failures).to(have_length(1))
     failure = failures[0]
     expect(failure.text).to(contain(format_exception(exception)))
Beispiel #13
0
 def test_specifies_fullscreen_option(self):
     Browser()
     spy = self.fake_webdriver.driver_spy
     expect(spy).not_to(equal(None))
     expect(spy.call_history).to(have_length(1))
     _, kwargs = spy.call_history[0]
     expect(kwargs.keys()).to(contain("chrome_options"))
     opts = kwargs["chrome_options"]
     expect(opts).to(be_a(webdriver.chrome.options.Options))
     expect(opts.arguments).to(contain("start-fullscreen"))
Beispiel #14
0
 def quit_was_called(self):
     assert self.webdriver_spy.attribute_was_requested(
         USE_BROWSER), "%s was not invoked" % USE_BROWSER
     launcher_spy = self.webdriver_spy.attribute_spies[USE_BROWSER]
     expect(launcher_spy.return_value_spies).to(have_length(1))
     driver_spy = launcher_spy.return_value_spies[0]
     if "quit" in driver_spy.attribute_spies.keys():
         quit_spy = driver_spy.attribute_spies["quit"]
         return bool(quit_spy.return_value_spies)
     return False
 def test_test_status_err(self):
     name = "Galahad"
     start_suite()
     start_test(name)
     err_test(name)
     end_test(name)
     end_suite()
     results = self.retrieve_results()
     expect(results.tests).to(have_length(1))
     expect(results.tests[0].status).to(equal(TestStatus.erred))
 def test_test_status_skip(self):
     name = "The Vicious Chicken of Bristol"
     start_suite()
     start_test(name)
     skip_test(name)
     end_test(name)
     end_suite()
     results = self.retrieve_results()
     expect(results.tests).to(have_length(1))
     expect(results.tests[0].status).to(equal(TestStatus.skipped))
 def test_test_status_fail(self):
     name = "Robin"
     start_suite()
     start_test(name)
     fail_test(name)
     end_test(name)
     end_suite()
     results = self.retrieve_results()
     expect(results.tests).to(have_length(1))
     expect(results.tests[0].status).to(equal(TestStatus.failed))
 def test_contains_exception_message(self):
     exception = RuntimeError("failed intentionally")
     self.publish(TestEvent.suite_started)
     self.publish(TestEvent.suite_erred, exception=exception)
     self.publish(TestEvent.suite_ended)
     test = self.extract_dummy_test()
     failures = test.findall("./error")
     expect(failures).to(have_length(1))
     failure = failures[0].attrib
     expect(failure.keys()).to(contain("message"))
     expect(failure["message"]).to(contain(str(exception)))
    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_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
Beispiel #21
0
    def test_get_all_responses(self):
        mock = CollectorResponsesBulkListMock(total=5,
                                              collector_ids=self.collector_ids)
        with HTTMock(mock.bulk):
            responses_list = self.bulk_collector.responses()

        expect(responses_list).to(have_length(5))
        expect(responses_list[0]).to(
            have_keys('analyze_url', 'response_status', 'date_modified'))
        expect(responses_list[0]).to(
            have_keys('id', 'collector_id', 'recipient_id', 'survey_id'))
Beispiel #22
0
    def test_get_responses_by_status(self, status, method_name, be_status):
        mock = CollectorResponsesBulkListMock(total=5,
                                              collector_ids=self.collector_ids,
                                              status=status)

        with HTTMock(mock.bulk):
            responses_list = getattr(self.bulk_collector, method_name)()

        expect(responses_list).to(have_length(5))
        for response in responses_list:
            expect(response).to(be_status)
Beispiel #23
0
    def test_add_recipients_to_existing_message(self, recipients):
        message = Message(
            connection=self.connection,
            collector_id=self.collector_id,
            message_id=self.message_id,
        )

        with HTTMock(self.mock.recipient_add):
            response = message.recipients(recipients)

        expect(response["succeeded"]).to(have_length(be_above_or_equal(1)))
 def test_creates_missing_test_on_artifact_with_test_name(self):
     test_name = "oops"
     start_suite()
     EventBroker.publish(event=TestEvent.artifact_created,
                         test_name=test_name,
                         artifact="this")
     end_suite()
     results = self.retrieve_results()
     expect(results.tests).to(have_length(1))
     test = results.tests[0]
     expect(test.name).to(equal(test_name))
 def test_attaches_exception_to_skipped_test(self):
     name = "Fang"
     exception = RuntimeError("intentional")
     start_suite()
     start_test(name)
     skip_test(name, exception=exception)
     end_test(name)
     end_suite()
     results = self.retrieve_results()
     expect(results.tests).to(have_length(1))
     expect(results.tests[0].exception).to(equal(exception))
Beispiel #26
0
    def test_create_new_message_and_add_a_recipients(self, recipients):
        message = Message(connection=self.connection,
                          collector_id=self.collector_id,
                          config=self.config)

        with HTTMock(MessagesMock(self.config).create):
            message.create()

        with HTTMock(self.mock.recipient_add):
            response = message.recipients(recipients)

        expect(response["succeeded"]).to(have_length(be_above_or_equal(1)))
 def test_kills_running_procs(self):
     limit = 42
     self.context.set_env(RUN_ALL_TIMEOUT=limit)
     spy = FunctionSpy()
     self.fake_process.kill = spy
     tc = self.context.create_time_controller(target=self.exercise_sut)
     tc.start()
     sleep(0.05)
     tc.advance(seconds=limit + 1)
     sleep(0.05)
     expect(spy.call_history).to(have_length(1))
     self.pretend_process_is_stopped()
     tc.join()
 def test_attaches_artifact_to_named_test(self):
     artifact = b"bbbbbbbbbbbbbbbbbb"
     name = "Bobbb"
     start_suite()
     start_test(name)
     EventBroker.publish(event=TestEvent.artifact_created,
                         test_name=name,
                         artifact=artifact)
     end_test(name)
     end_suite()
     results = self.retrieve_results()
     expect(results.tests).to(have_length(1))
     expect(results.tests[0].artifacts).to(contain(artifact))
Beispiel #29
0
 def test_publishes_suite_erred_with_exception_on_error(self):
     expected = FakeException("That's impossible, even for a computer")
     try:
         with test_suite(name="spam"):
             raise expected
     except FakeException:
         pass  # Unexpected, but covered by another test
     erred = [
         msg for msg in self.fake_broker.messages
         if msg["event"] == TestEvent.suite_erred
     ]
     expect(erred).to(have_length(1))
     expect(erred[0]).to(contain_key_with_value("exception", expected))
Beispiel #30
0
 def test_publishes_suite_erred_with_suite_name_on_error(self):
     name = "doomed"
     try:
         with test_suite(name=name):
             raise Exception("intentional")
     except Exception:
         pass  # Unexpected, but covered by another test
     expect(self.fake_broker.messages).not_to(be_empty)
     erred = [
         msg for msg in self.fake_broker.messages
         if msg["event"] == TestEvent.suite_erred
     ]
     expect(erred).to(have_length(1))
     expect(erred[0]).to(contain_key_with_value("suite_name", name))
            expect(inspect.ismodule(module)).to(be_true)

        with it('loads module from relative path'):
            module = _load_module(spec_relpath('without_inner_contexts.py'))

            expect(inspect.ismodule(module)).to(be_true)

    #FIXME: Mixed responsabilities in test [collect, load]??
    with context('when loading'):
        with it('orders examples by line number'):
            module = _load_module(spec_abspath('without_inner_contexts.py'))

            examples = loader.Loader().load_examples_from(module)

            expect(examples).to(have_length(1))
            expect(example_names(examples[0].examples)).to(equal(['it first example', 'it second example', 'it third example']))

        with it('places examples together and groups at the end'):
            module = _load_module(spec_abspath('with_inner_contexts.py'))

            examples = loader.Loader().load_examples_from(module)

            expect(examples).to(have_length(1))
            expect(example_names(examples[0].examples)).to(equal(['it first example', 'it second example', 'it third example', '#inner_context']))

    with context('when reading tags'):
        with it('reads tags from description parameters'):
            module = _load_module(WITH_TAGS_PATH)

            examples = loader.Loader().load_examples_from(module)