Beispiel #1
0
    def test_prepare_failing_feature_verbose_0(self, mock_feature, mock_prepare_border,
                                               mock_prepare_step, mock_prepare_scenario, mock_prepare_exception, cyan_mock, red_mock):
        display = Display()
        display.verbosity_level = 0

        mock_feature.description = 'Mock Feature'
        mock_feature.passed = False
        mock_feature.exception = 'FooBarException'
        mock_feature.scenarios = ['scenario_one', 'scenario_two']
        mock_feature.before_all = ['before_all_one', 'before_all_two']
        mock_feature.after_all = ['after_all']
        mock_feature.before_each = ['before_each']
        mock_feature.after_each = ['after_each_one', 'after_each_two']

        display.prepare_feature(mock_feature)

        cyan_mock.assert_not_called()
        red_mock.assert_called_once_with("Feature: Mock Feature")

        display.prepare_step.assert_any_call('before_all_one', 'BeforeAll')
        display.prepare_step.assert_any_call('before_all_two', 'BeforeAll')
        display.prepare_step.assert_any_call('after_all', 'AfterAll')
        display.prepare_step.assert_any_call('before_each', 'BeforeEach')
        display.prepare_step.assert_any_call('after_each_one', 'AfterEach')
        display.prepare_step.assert_any_call('after_each_two', 'AfterEach')

        display.prepare_scenario.assert_any_call('scenario_one')
        display.prepare_scenario.assert_any_call('scenario_two')
        display.prepare_exception.assert_called_once_with('FooBarException')

        self.assertEqual(display.display_string,
                         "="*150 + "\n" + "Feature: Mock Feature\n" + "="*150 + "\n")
Beispiel #2
0
    def test_prepare_exception(self, yellow_mock):
        try:
            raise Exception('FooBarException')
        except Exception as e:
            display = Display()
            display.prepare_exception(e)

            self.assertEqual(display.indentation_level, 0)
            self.assertEqual(display.display_string, "FooBarException\n" + extract_traceback(e))
            display.yellow.assert_called_once_with(("FooBarException\n" + extract_traceback(e)).rstrip())
Beispiel #3
0
    def test_prepare_passing_suite_verbose_0(self, mock_suite, mock_prepare_feature,
                                             mock_prepare_border, mock_prepare_statistics,
                                             mock_cyan, mock_red):

        display = Display()
        display.verbosity_level = 0

        mock_suite.passed = True

        display.prepare_suite(mock_suite)

        display.prepare_border.assert_called_with(mock_cyan, 150)
        display.prepare_feature.assert_not_called()
        display.prepare_statistics.assert_called_with(mock_suite)
        self.assertEqual(display.display_string, "="*150 + "\n" + "="*150 + "\n")
Beispiel #4
0
    def test_prepare_exception_without_str_representation(self, yellow_mock):
        try:
            class FooBarException(Exception):

                def __str__(self):
                    return ''

            raise FooBarException
        except FooBarException as e:
            display = Display()
            display.prepare_exception(e)

            self.assertEqual(display.indentation_level, 0)
            self.assertEqual(display.display_string, "FooBarException\n" + extract_traceback(e))
            display.yellow.assert_called_once_with(("FooBarException\n" + extract_traceback(e)).rstrip())
Beispiel #5
0
    def test_prepare_skipped_scenario_verbose_1(self, scenario, cyan_mock, red_mock, grey_mock):
        display = Display()
        display.verbosity_level = 1

        scenario.description = 'Mock Scenario'
        scenario.ran = False
        scenario.passed = True

        display.prepare_scenario(scenario)

        cyan_mock.assert_not_called()
        red_mock.assert_not_called()
        grey_mock.assert_called_once_with("Scenario: Mock Scenario")
        self.assertEqual(display.indentation_level, 0)
        self.assertEqual(display.display_string, "Scenario: Mock Scenario\n")
Beispiel #6
0
    def test_prepare_failing_suite_verbose_0(self, mock_suite, mock_prepare_feature,
                                             mock_prepare_border, mock_prepare_statistics,
                                             mock_cyan, mock_red):

        display = Display()
        display.verbosity_level = 0

        mock_suite.passed = False
        mock_suite.features = ['feature_one', 'feature_two']

        display.prepare_suite(mock_suite)

        display.prepare_border.assert_called_with(mock_red, 150)
        display.prepare_feature.assert_any_call('feature_one')
        display.prepare_feature.assert_any_call('feature_two')
        display.prepare_statistics.assert_called_with(mock_suite)
        self.assertEqual(display.display_string, "="*150 + "\n" + "="*150 + "\n")
Beispiel #7
0
    def test_prepare_skipped_step(self, step_mock, cyan_mock, red_mock, grey_mock):
        step_mock.ran = False
        step_mock.passed = False
        step_mock.kwargs = {'mock': 'kwargs'}

        def mock_function():
            pass

        step_mock.function = mock_function

        display = Display()
        display.prepare_step(step_mock, 'MockStep')

        self.assertEqual(display.indentation_level, 0)
        self.assertEqual(display.display_string, "MockStep: mock_function {'mock': 'kwargs'}\n")
        display.cyan.assert_not_called()
        display.red.assert_not_called()
        display.grey.assert_called_once_with("MockStep: mock_function {'mock': 'kwargs'}")
Beispiel #8
0
    def test_init(self, mock_deinit):
        display = Display()

        self.assertEqual(display.display_string, '')
        self.assertEqual(display.indentation_level, 0)
        self.assertEqual(display.verbosity_level, 0)
        self.assertEqual(display.colored, True)
        self.assertEqual(display.force_ansi, True)
        mock_deinit.assert_called_once()
Beispiel #9
0
    def test_prepare_passing_feature_verbose_1(self, mock_feature, mock_prepare_border,
                                               mock_prepare_scenario, mock_prepare_exception, cyan_mock, red_mock):
        display = Display()
        display.verbosity_level = 1

        mock_feature.description = 'Mock Feature'
        mock_feature.passed = True
        mock_feature.exception = None
        mock_feature.scenarios = ['scenario_one', 'scenario_two']

        display.prepare_feature(mock_feature)

        cyan_mock.assert_called_once_with("Feature: Mock Feature")
        red_mock.assert_not_called()
        display.prepare_scenario.assert_any_call('scenario_one')
        display.prepare_scenario.assert_any_call('scenario_two')
        display.prepare_exception.assert_not_called()

        self.assertEqual(display.display_string,
                         "="*150 + "\n" + "Feature: Mock Feature\n" + "="*150 + "\n")
Beispiel #10
0
    def test_prepare_failing_statistics(self, mock_suite, mock_cyan, mock_red):
        display = Display()

        mock_suite.passed = False
        mock_suite.num_features_passed = 4
        mock_suite.num_features_failed = 1
        mock_suite.num_scenarios_passed = 15
        mock_suite.num_scenarios_failed = 5

        display.prepare_statistics(mock_suite)

        display.cyan.assert_not_called()
        display.red.assert_called_once_with(
            "4 Features passed, 1 failed.\n"
            "15 Scenarios passed, 5 failed."
        )

        self.assertEqual(
            display.display_string,
            "4 Features passed, 1 failed.\n15 Scenarios passed, 5 failed.\n"
        )
Beispiel #11
0
    def test_prepare_passing_statistics(self, mock_suite, mock_cyan, mock_red):
        display = Display()

        mock_suite.passed = True
        mock_suite.num_features_passed = 5
        mock_suite.num_features_failed = 0
        mock_suite.num_scenarios_passed = 20
        mock_suite.num_scenarios_failed = 0

        display.prepare_statistics(mock_suite)

        display.red.assert_not_called()
        display.cyan.assert_called_once_with(
            "5 Features passed, 0 failed.\n"
            "20 Scenarios passed, 0 failed."
        )

        self.assertEqual(
            display.display_string,
            "5 Features passed, 0 failed.\n20 Scenarios passed, 0 failed.\n"
        )
Beispiel #12
0
    def test_prepare_failing_scenario_verbose_0(self, scenario, prepare_step_mock, prepare_exception_mock, cyan_mock, red_mock, grey_mock):
        display = Display()
        display.verbosity_level = 0

        scenario.description = 'Mock Scenario'
        scenario.ran = True
        scenario.passed = False
        scenario.exception = 'FooBarException'
        scenario.before_all = ['before_all_one', 'before_all_two']
        scenario.after_all = ['after_all']
        scenario.before_each = ['before_each']
        scenario.after_each = ['after_each_one', 'after_each_two']
        scenario.given = ['given_one', 'given_two']
        scenario.when = ['when_one', 'when_two']
        scenario.then = ['then_one', 'then_two']

        display.prepare_scenario(scenario)

        cyan_mock.assert_not_called()
        red_mock.assert_called_once_with('Scenario: Mock Scenario')
        grey_mock.assert_not_called()

        display.prepare_step.assert_any_call('before_all_one', 'BeforeAll')
        display.prepare_step.assert_any_call('before_all_two', 'BeforeAll')
        display.prepare_step.assert_any_call('after_all', 'AfterAll')
        display.prepare_step.assert_any_call('before_each', 'BeforeEach')
        display.prepare_step.assert_any_call('after_each_one', 'AfterEach')
        display.prepare_step.assert_any_call('after_each_two', 'AfterEach')
        display.prepare_step.assert_any_call('given_one', 'Given')
        display.prepare_step.assert_any_call('given_two', 'And')
        display.prepare_step.assert_any_call('when_one', 'When')
        display.prepare_step.assert_any_call('when_two', 'And')
        display.prepare_step.assert_any_call('then_one', 'Then')
        display.prepare_step.assert_any_call('then_two', 'And')

        display.prepare_exception.assert_called_once_with('FooBarException')

        self.assertEqual(display.display_string, 'Scenario: Mock Scenario\n')
Beispiel #13
0
    def test_display_windows_with_ansi(self, mock_print, mock_sys, mock_init, mock_deinit):
        mock_sys.platform = 'win32'

        display = Display()
        display.display_string = 'foobar'
        display.force_ansi = True

        display.display()

        mock_init.assert_not_called()
        mock_print.assert_called_once_with('foobar')
        mock_deinit.assert_called()
Beispiel #14
0
    def test_display_non_windows(self, mock_print, mock_sys, mock_init, mock_deinit):
        mock_sys.platform = 'foobarbaz'

        display = Display()
        display.display_string = 'foobar'
        display.force_ansi = False

        display.display()

        mock_init.assert_not_called()
        mock_print.assert_called_once_with('foobar')
        mock_deinit.assert_called()
Beispiel #15
0
def jasper(test_directory, ansi, v):
    """
    The entrypoint of the application.

    Runs Jasper tests within a given directory and displays the results.

    :param test_directory: The directory containing feature files to run.
    :param ansi: A flag for whether or not to force ansi escape sequences in the display for coloring purposes.
    :param v: A verbosity level for the display. Ranges from 0 to 2.
    """
    runner = Runner(test_directory)
    completed_suite = runner.run()
    display = Display(force_ansi=ansi, verbosity_level=v)
    display.prepare_suite(completed_suite)
    display.display()
Beispiel #16
0
    def test_grey_without_colored_on(self):
        display = Display()
        display.colored = False

        self.assertEqual(display.grey('foobar'), 'foobar')
Beispiel #17
0
    def test_grey_with_colored_on(self):
        display = Display()
        display.colored = True

        self.assertEqual(display.grey('foobar'), colored('foobar', 'white'))
Beispiel #18
0
    def test_cyan_with_colored_on(self):
        display = Display()
        display.colored = True

        self.assertEqual(display.cyan('foobar'), colored('foobar', 'cyan'))
Beispiel #19
0
    def test_prepare_border(self, cyan_mock):
        display = Display()
        border = display.prepare_border(cyan_mock, 50)

        self.assertEqual(border, '='*50)
        display.cyan.assert_called_once_with('='*50)
Beispiel #20
0
    def test_prepare_passing_scenario_verbose_0(self, scenario):
        display = Display()
        display.prepare_scenario(scenario)

        self.assertEqual(display.display_string, "")
Beispiel #21
0
    def test_red_with_colored_on(self):
        display = Display()
        display.colored = True

        self.assertEqual(display.red('foobar'), colored('foobar', 'red'))
Beispiel #22
0
    def test_yellow_without_colored_on(self):
        display = Display()
        display.colored = False

        self.assertEqual(display.yellow('foobar'), 'foobar')
Beispiel #23
0
    def test_prepare_passing_feature_verbose_0(self, mock_feature):
        display = Display()
        display.prepare_feature(mock_feature)

        self.assertEqual(display.display_string, "")
Beispiel #24
0
    def test_yellow_with_colored_on(self):
        display = Display()
        display.colored = True

        self.assertEqual(display.yellow('foobar'), colored('foobar', 'yellow'))