Пример #1
0
    def load_suite_from_file(self, filename):
        """Load a test suite with test lines from the provided TAP file.

        :returns: A ``unittest.TestSuite`` instance
        """
        suite = unittest.TestSuite()
        rules = Rules(filename, suite)

        if not os.path.exists(filename):
            rules.handle_file_does_not_exist()
            return suite

        line_counter = 0
        for line in self._parser.parse_file(filename):
            line_counter += 1

            if line.category in self.ignored_lines:
                continue

            if line.category == 'test':
                suite.addTest(Adapter(filename, line))
                rules.saw_test()
            elif line.category == 'plan':
                if line.skip:
                    rules.handle_skipping_plan(line)
                    return suite
                rules.saw_plan(line, line_counter)
            elif line.category == 'bail':
                rules.handle_bail(line)
                return suite
            elif line.category == 'version':
                rules.saw_version_at(line_counter)

        rules.check(line_counter)
        return suite
Пример #2
0
    def _load_lines(self, filename, line_generator, suite, rules):
        """Load a suite with lines produced by the line generator."""
        line_counter = 0
        for line in line_generator:
            line_counter += 1

            if line.category in self.ignored_lines:
                continue

            if line.category == 'test':
                suite.addTest(Adapter(filename, line))
                rules.saw_test()
            elif line.category == 'plan':
                if line.skip:
                    rules.handle_skipping_plan(line)
                    return suite
                rules.saw_plan(line, line_counter)
            elif line.category == 'bail':
                rules.handle_bail(line)
                return suite
            elif line.category == 'version':
                rules.saw_version_at(line_counter)

        rules.check(line_counter)
        return suite
Пример #3
0
    def test_handles_ok_test_line(self):
        """Add a success for an ok test line."""
        ok_line = self.factory.make_ok()
        adapter = Adapter('fake.tap', ok_line)
        result = mock.Mock()

        adapter(result)

        self.assertTrue(result.addSuccess.called)
Пример #4
0
 def test_expected_failure_on_26(self):
     """Python 2.6 does not support addExpectedFailure."""
     todo_line = self.factory.make_not_ok(
         directive_text='TODO An incomplete test')
     result = mock.Mock()
     result.addExpectedFailure.side_effect = AttributeError
     adapter = Adapter('fake.tap', todo_line)
     adapter(result)
     self.assertTrue(result.addSuccess.called)
Пример #5
0
 def test_skips_on_26(self):
     """Python 2.6 does not support addSkip."""
     skip_line = self.factory.make_ok(
         directive_text='SKIP This is the reason.')
     result = mock.Mock()
     result.addSkip.side_effect = AttributeError
     adapter = Adapter('fake.tap', skip_line)
     adapter(result)
     self.assertTrue(result.addSuccess.called)
Пример #6
0
    def test_handles_not_ok_todo_test_line(self):
        """Add an expected failure for a not ok todo test line."""
        todo_line = self.factory.make_not_ok(directive_text="TODO An incomplete test")
        adapter = Adapter("fake.tap", todo_line)
        result = self.factory.make_test_result()

        adapter(result)

        self.assertEqual(1, len(result.expectedFailures))
Пример #7
0
    def test_handles_ok_todo_test_line(self):
        """Add an unexpected success for an ok todo test line."""
        todo_line = self.factory.make_ok(
            directive_text='TODO An incomplete test')
        adapter = Adapter('fake.tap', todo_line)
        result = self.factory.make_test_result()

        adapter(result)

        self.assertEqual(1, len(result.unexpectedSuccesses))
Пример #8
0
    def test_handles_skip_test_line(self):
        """Add a skip when a test line contains a skip directive."""
        skip_line = self.factory.make_ok(directive_text="SKIP This is the reason.")
        adapter = Adapter("fake.tap", skip_line)
        result = self.factory.make_test_result()

        adapter(result)

        self.assertEqual(1, len(result.skipped))
        self.assertEqual("This is the reason.", result.skipped[0][1])
Пример #9
0
    def test_handles_not_ok_todo_test_line(self):
        """Add an expected failure for a not ok todo test line."""
        # Don't test on Python 2.6.
        if sys.version_info[0] == 2 and sys.version_info[1] == 6:
            return

        todo_line = self.factory.make_not_ok(
            directive_text='TODO An incomplete test')
        adapter = Adapter('fake.tap', todo_line)
        result = self.factory.make_test_result()

        adapter(result)

        self.assertEqual(1, len(result.expectedFailures))
Пример #10
0
    def test_handles_skip_test_line(self):
        """Add a skip when a test line contains a skip directive."""
        # Don't test on Python 2.6.
        if sys.version_info[0] == 2 and sys.version_info[1] == 6:
            return

        skip_line = self.factory.make_ok(
            directive_text='SKIP This is the reason.')
        adapter = Adapter('fake.tap', skip_line)
        result = self.factory.make_test_result()

        adapter(result)

        self.assertEqual(1, len(result.skipped))
        self.assertEqual('This is the reason.', result.skipped[0][1])
Пример #11
0
 def _add_error(self, message):
     """Add an error test to the suite."""
     error_line = Result(False, None, message, Directive(""))
     self._suite.addTest(Adapter(self._filename, error_line))
Пример #12
0
 def handle_skipping_plan(self, skip_plan):
     """Handle a plan that contains a SKIP directive."""
     skip_line = Result(True, None, skip_plan.directive.text,
                        Directive("SKIP"))
     self._suite.addTest(Adapter(self._filename, skip_line))
Пример #13
0
    def test_adapter_has_filename(self):
        """The adapter has a TAP filename."""
        tap_filename = 'fake.tap'
        adapter = Adapter(tap_filename, None)

        self.assertEqual(tap_filename, adapter._filename)