Example #1
0
    def tests_outputs_stdout_not_json(self):
        """
        Will report input and output, even if it's not JSON.
        """
        stdin = 'a\nb\nc\n'
        stdout = 'd\ne\nf\n'

        expectation = Expectation((1, 2), None, u'aaa')
        results = [
            SuccessResult(
                actual=u'aaa', expectation=expectation,
                plugin=MockPlugin(), stdin=stdin, stdout=stdout)]

        ptr = PluginTestReporter(results)

        self.assertResults(
            u'''
            01 – 02 Pass

            stdin (sent to the plugin)

                a
                b
                c

            stdout (received from the plugin)

                d
                e
                f

            {0}
            Pass 1, Fail 0'''.format(REPORTER_HORIZONTAL_DIVIDER),
            ptr.dumps(verbose=True))
Example #2
0
    def test_single_failure(self):
        """
        Reports a single failure.
        """
        expectation = Expectation((1, 2), None, u'aaa')
        results = [
            FailureResult(actual=u'bbb',
                          expectation=expectation,
                          plugin=MockPlugin())
        ]

        ptr = PluginTestReporter(results)

        self.assertResults(
            u'''
            01 – 02 Fail

            Actual
            {0}

            bbb

            Diff
            {0}

            - aaa
            + bbb

            Pass 0, Fail 1'''.format(REPORTER_HORIZONTAL_DIVIDER), ptr.dumps())
Example #3
0
    def test(self, argv):
        """
        Run the tests for a plugin.
        """
        plugin = argv.plugin
        test_range = argv.range
        verbose = argv.verbose

        with self.out() as out:
            if test_range:
                test_range = parse_range(test_range)

            try:
                ptr = PluginTestRunner(plugin)

                results = ptr.run(test_range=test_range)

                reporter = PluginTestReporter(results)

                test_results = reporter.dumps(verbose=verbose).splitlines()

                failures = [i for i in results if isinstance(i, FailureResult)]

                if failures:
                    # Raise as an error so the status code will be non-zero
                    raise CommandError('\n'.join(test_results))

                # No failures, ok to send this to stdout
                out.extend(test_results)
            except ExpectationError as e:
                raise CommandError(str(e))
Example #4
0
    def test_single_failure(self):
        """
        Reports a single failure.
        """
        expectation = Expectation((1, 2), None, u'aaa')
        results = [
            FailureResult(
                actual=u'bbb', expectation=expectation,
                plugin=MockPlugin())]

        ptr = PluginTestReporter(results)

        self.assertResults(
            u'''
            01 – 02 Fail

            Actual
            {0}

            bbb

            Diff
            {0}

            - aaa
            + bbb

            Pass 0, Fail 1'''.format(REPORTER_HORIZONTAL_DIVIDER),
            ptr.dumps())
Example #5
0
    def test_no_results(self):
        """
        No results reports nothing but the count.
        """
        results = []

        ptr = PluginTestReporter(results)

        self.assertEqual(u'Pass 0, Fail 0', ptr.dumps())
Example #6
0
    def test_no_results(self):
        """
        No results reports nothing but the count.
        """
        results = []

        ptr = PluginTestReporter(results)

        self.assertEqual(u'Pass 0, Fail 0', ptr.dumps())
Example #7
0
    def test_single_success(self):
        """
        Report a single success.
        """
        expectation = Expectation((1, 2), None, u'aaa')
        results = [
            SuccessResult(
                actual=u'aaa', expectation=expectation,
                plugin=MockPlugin())]

        ptr = PluginTestReporter(results)

        self.assertResults(u'''
            01 – 02 Pass

            Pass 1, Fail 0''', ptr.dumps())
Example #8
0
    def test_failure_within_success(self):
        """
        Multiple results.
        """
        expectation1 = Expectation((1, 2), None, u'aaa')
        expectation2 = Expectation((2, 3), None, u'b\nb\nb\n')
        expectation3 = Expectation((3, 4), None, u'ccc')
        results = [
            SuccessResult(actual=u'aaa',
                          expectation=expectation1,
                          plugin=MockPlugin()),
            FailureResult(actual=u'b\nB\nb\n',
                          expectation=expectation2,
                          plugin=MockPlugin()),
            SuccessResult(actual=u'ccc',
                          expectation=expectation3,
                          plugin=MockPlugin())
        ]

        ptr = PluginTestReporter(results)

        self.assertResults(
            u'''
            01 – 02 Pass

            02 – 03 Fail

            Actual
            {0}

            b
            B
            b

            Diff
            {0}

              b
            + B
              b
            - b

            03 – 04 Pass

            Pass 2, Fail 1'''.format(REPORTER_HORIZONTAL_DIVIDER), ptr.dumps())
Example #9
0
    def test_failure_within_success(self):
        """
        Multiple results.
        """
        expectation1 = Expectation((1, 2), None, u'aaa')
        expectation2 = Expectation((2, 3), None, u'b\nb\nb\n')
        expectation3 = Expectation((3, 4), None, u'ccc')
        results = [
            SuccessResult(
                actual=u'aaa', expectation=expectation1,
                plugin=MockPlugin()),
            FailureResult(
                actual=u'b\nB\nb\n', expectation=expectation2,
                plugin=MockPlugin()),
            SuccessResult(
                actual=u'ccc', expectation=expectation3,
                plugin=MockPlugin())]

        ptr = PluginTestReporter(results)

        self.assertResults(
            u'''
            01 – 02 Pass

            02 – 03 Fail

            Actual
            {0}

            b
            B
            b

            Diff
            {0}

              b
            + B
              b
            - b

            03 – 04 Pass

            Pass 2, Fail 1'''.format(REPORTER_HORIZONTAL_DIVIDER),
            ptr.dumps())
Example #10
0
    def test_single_success(self):
        """
        Report a single success.
        """
        expectation = Expectation((1, 2), None, u'aaa')
        results = [
            SuccessResult(actual=u'aaa',
                          expectation=expectation,
                          plugin=MockPlugin())
        ]

        ptr = PluginTestReporter(results)

        self.assertResults(
            u'''
            01 – 02 Pass

            Pass 1, Fail 0''', ptr.dumps())
Example #11
0
    def test_outputs_stdin_stdout(self):
        """
        Will report the input and output of a plugin.
        """
        stdin = json.dumps(['a', 'b', 'c'])
        stdout = json.dumps(['d', 'e', 'f'])

        expectation = Expectation((1, 2), None, u'aaa')
        results = [
            SuccessResult(actual=u'aaa',
                          expectation=expectation,
                          plugin=MockPlugin(),
                          stdin=stdin,
                          stdout=stdout)
        ]

        ptr = PluginTestReporter(results)

        self.assertResults(
            u'''
            01 – 02 Pass

            stdin (sent to the plugin)

                [
                  "a", 
                  "b", 
                  "c"
                ]

            stdout (received from the plugin)

                [
                  "d", 
                  "e", 
                  "f"
                ]

            {0}
            Pass 1, Fail 0'''.format(REPORTER_HORIZONTAL_DIVIDER),
            ptr.dumps(verbose=True))
Example #12
0
    def test_outputs_stdin_stdout(self):
        """
        Will report the input and output of a plugin.
        """
        stdin = json.dumps(['a', 'b', 'c'])
        stdout = json.dumps(['d', 'e', 'f'])

        expectation = Expectation((1, 2), None, u'aaa')
        results = [
            SuccessResult(
                actual=u'aaa', expectation=expectation,
                plugin=MockPlugin(), stdin=stdin, stdout=stdout)]

        ptr = PluginTestReporter(results)

        self.assertResults(
            u'''
            01 – 02 Pass

            stdin (sent to the plugin)

                [
                  "a", 
                  "b", 
                  "c"
                ]

            stdout (received from the plugin)

                [
                  "d", 
                  "e", 
                  "f"
                ]

            {0}
            Pass 1, Fail 0'''.format(REPORTER_HORIZONTAL_DIVIDER),
            ptr.dumps(verbose=True))
Example #13
0
    def tests_outputs_stdout_not_json(self):
        """
        Will report input and output, even if it's not JSON.
        """
        stdin = 'a\nb\nc\n'
        stdout = 'd\ne\nf\n'

        expectation = Expectation((1, 2), None, u'aaa')
        results = [
            SuccessResult(actual=u'aaa',
                          expectation=expectation,
                          plugin=MockPlugin(),
                          stdin=stdin,
                          stdout=stdout)
        ]

        ptr = PluginTestReporter(results)

        self.assertResults(
            u'''
            01 – 02 Pass

            stdin (sent to the plugin)

                a
                b
                c

            stdout (received from the plugin)

                d
                e
                f

            {0}
            Pass 1, Fail 0'''.format(REPORTER_HORIZONTAL_DIVIDER),
            ptr.dumps(verbose=True))