def parse_args(argv): description = _("A TAP consumer for Python") epilog = _( "When no files are given or a dash (-) is used for the file name, " "tappy will read a TAP stream from STDIN." ) parser = argparse.ArgumentParser(description=description, epilog=epilog) parser.add_argument( "files", metavar="FILE", nargs="*", help=_( "A file containing TAP output. Any directories listed will be " "scanned for files to include as TAP files." ), ) parser.add_argument( "-v", "--verbose", action="store_const", default=1, const=2, help=_("use verbose messages"), ) # argparse expects the executable to be removed from argv. args = parser.parse_args(argv[1:]) # When no files are provided, the user wants to use a TAP stream on STDIN. # But they probably didn't mean it if there is no pipe connected. # In that case, print the help and exit. if not args.files and sys.stdin.isatty(): sys.exit(parser.print_help()) return args
def parse_args(argv): description = _("A TAP consumer for Python") epilog = _( "When no files are given or a dash (-) is used for the file name, " "tappy will read a TAP stream from STDIN.") parser = argparse.ArgumentParser(description=description, epilog=epilog) parser.add_argument( "files", metavar="FILE", nargs="*", help=_("A file containing TAP output. Any directories listed will be " "scanned for files to include as TAP files."), ) parser.add_argument( "-v", "--verbose", action="store_const", default=1, const=2, help=_("use verbose messages"), ) # argparse expects the executable to be removed from argv. args = parser.parse_args(argv[1:]) # When no files are provided, the user wants to use a TAP stream on STDIN. # But they probably didn't mean it if there is no pipe connected. # In that case, print the help and exit. if not args.files and sys.stdin.isatty(): sys.exit(parser.print_help()) return args
def parse_args(argv): description = _('A TAP consumer for Python') epilog = _( 'When no files are given or a dash (-) is used for the file name, ' 'tappy will read a TAP stream from STDIN.') parser = argparse.ArgumentParser(description=description, epilog=epilog) parser.add_argument( 'files', metavar='FILE', nargs='*', help=_('A file containing TAP output. Any directories listed will be ' 'scanned for files to include as TAP files.')) parser.add_argument('-v', '--verbose', action='store_const', default=1, const=2, help=_('use verbose messages')) # argparse expects the executable to be removed from argv. args = parser.parse_args(argv[1:]) # When no files are provided, the user wants to use a TAP stream on STDIN. # But they probably didn't mean it if there is no pipe connected. # In that case, print the help and exit. if not args.files and sys.stdin.isatty(): sys.exit(parser.print_help()) return args
def options(self, parser, env=os.environ): super(TAP, self).options(parser, env=env) parser.add_option( '--tap-stream', default=False, action='store_true', help=_('Stream TAP output instead of the default test runner' ' output.')) parser.add_option( '--tap-outdir', metavar='PATH', help=_('An optional output directory to write TAP files to. ' 'If the directory does not exist, it will be created.')) parser.add_option( '--tap-combined', default=False, action='store_true', help=_('Store all TAP test results into a combined output file.')) parser.add_option( '--tap-format', default='', metavar='FORMAT', help=_('An optional format string for the TAP output.' ' The format options are:' ' {short_description} for the short description, and' ' {method_name} for the test method name.'))
def pytest_addoption(parser): """Include all the command line options.""" group = parser.getgroup('terminal reporting', after='general') group.addoption( '--tap-stream', default=False, action='store_true', help=_( 'Stream TAP output instead of the default test runner output.')) group.addoption('--tap-outdir', metavar='path', help=_( 'An optional output directory to write TAP files to. ' 'If the directory does not exist, it will be created.')) group.addoption( '--tap-combined', default=False, action='store_true', help=_('Store all TAP test results into a combined output file.'))
def parse_args(argv): description = _('A TAP consumer for Python') parser = argparse.ArgumentParser(description=description) parser.add_argument( 'files', metavar='FILE', nargs='+', help=_( 'A file containing TAP output. Any directories listed will be ' 'scanned for files to include as TAP files.')) parser.add_argument( '-v', '--verbose', action='store_const', default=1, const=2, help=_('use verbose messages')) # argparse expects the executable to be removed from argv. args = parser.parse_args(argv[1:]) return args
def test_requires_plan(self): rules = self._make_one() rules.check(42) self.assertEqual(_('Missing a plan.'), self.suite._tests[0]._line.description)
def _parse_version(self, match): version = int(match.group('version')) if version < self.TAP_MINIMUM_DECLARED_VERSION: raise ValueError( _('It is an error to explicitly specify ' 'any version lower than 13.')) return Version(version)
def test_adds_expected_failure(self): exc = self.factory.make_exc() result = self._make_one() result.addExpectedFailure(FakeTestCase(), exc) line = result.tracker._test_cases['FakeTestCase'][0] self.assertFalse(line.ok) self.assertEqual(line.directive.text, _('(expected failure)'))
def test_requires_plan(self): rules = self._make_one() rules.check(42) self.assertEqual( _('Missing a plan.'), self.suite._tests[0]._line.description)
def parse_args(argv): description = _("A TAP consumer for Python") parser = argparse.ArgumentParser(description=description) parser.add_argument( "files", metavar="FILE", nargs="+", help=_( "A file containing TAP output. Any directories listed will be " "scanned for files to include as TAP files." ), ) parser.add_argument("-v", "--verbose", action="store_const", default=1, const=2, help=_("use verbose messages")) # argparse expects the executable to be removed from argv. args = parser.parse_args(argv[1:]) return args
def test_adds_unexpected_success(self): result = self._make_one() result.addUnexpectedSuccess(FakeTestCase()) line = result.tracker._test_cases['FakeTestCase'][0] self.assertTrue(line.ok) self.assertEqual(line.directive.text, 'TODO {}'.format(_('(unexpected success)')))
def _parse_version(self, match): version = int(match.group("version")) if version < self.TAP_MINIMUM_DECLARED_VERSION: raise ValueError( _("It is an error to explicitly specify any version lower than 13.") ) return Version(version)
def test_adds_expected_failure(self): exc = self.factory.make_exc() result = self._make_one() result.addExpectedFailure(FakeTestCase(), exc) line = result.tracker._test_cases["FakeTestCase"][0] self.assertFalse(line.ok) self.assertEqual(line.directive.text, "TODO {}".format(_("(expected failure)")))
def addExpectedFailure(self, test, err): super(TAPTestResult, self).addExpectedFailure(test, err) diagnostics = formatter.format_exception(err) self.tracker.add_not_ok(self._cls_name(test), self._description(test), _('(expected failure)'), diagnostics=diagnostics)
def addUnexpectedSuccess(self, test): super(TAPTestResult, self).addUnexpectedSuccess(test) self.tracker.add_ok( self._cls_name(test), self._description(test), "TODO {}".format(_("(unexpected success)")), )
def test_adds_unexpected_success(self): result = self._make_one() result.addUnexpectedSuccess(FakeTestCase()) line = result.tracker._test_cases["FakeTestCase"][0] self.assertTrue(line.ok) self.assertEqual( line.directive.text, "TODO {}".format(_("(unexpected success)")) )
def options(self, parser, env=os.environ): super(TAP, self).options(parser, env=env) parser.add_option( '--tap-outdir', help=_('An optional output directory to write TAP files to. If the' ' directory does not exist, it will be created.')) parser.add_option( '--tap-combined', default=False, action='store_true', help=_('Store all TAP test results into a combined output file.')) parser.add_option( '--tap-format', default='', help=_( 'An optional format string for the TAP output.' ' The format options are:' ' {short_description} for the short description, and' ' {method_name} for the test method name.'))
def test_file_does_not_exist(self): """The loader records a failure when a file does not exist.""" loader = Loader() suite = loader.load_suite_from_file('phony.tap') self.assertEqual(1, len(suite._tests)) self.assertEqual( _('{filename} does not exist.').format(filename='phony.tap'), suite._tests[0]._line.description)
def test_errors_plan_not_at_end(self): plan = self.factory.make_plan() rules = self._make_one() rules.saw_plan(plan, 41) rules.check(42) self.assertEqual( _('A plan must appear at the beginning or end of the file.'), self.suite._tests[0]._line.description)
def test_only_one_plan(self): plan = self.factory.make_plan() rules = self._make_one() rules.saw_plan(plan, 41) rules.saw_plan(plan, 42) rules.check(42) self.assertEqual(_('Only one plan line is permitted per file.'), self.suite._tests[0]._line.description)
def test_errors_on_bail(self): bail = self.factory.make_bail(reason="Missing something important.") rules = self._make_one() rules.handle_bail(bail) self.assertEqual(1, len(self.suite._tests)) self.assertEqual( _("Bailed: {reason}").format(reason="Missing something important."), self.suite._tests[0]._line.description, )
def test_errors_on_bail(self): bail = self.factory.make_bail(reason='Missing something important.') rules = self._make_one() rules.handle_bail(bail) self.assertEqual(1, len(self.suite._tests)) self.assertEqual( _('Bailed: {reason}').format( reason='Missing something important.'), self.suite._tests[0]._line.description)
def test_only_one_plan(self): plan = self.factory.make_plan() rules = self._make_one() rules.saw_plan(plan, 41) rules.saw_plan(plan, 42) rules.check(42) self.assertEqual( _('Only one plan line is permitted per file.'), self.suite._tests[0]._line.description)
def test_errors_when_expected_tests_differs_from_actual(self): plan = self.factory.make_plan(expected_tests=42) rules = self._make_one() rules.saw_plan(plan, 1) rules.saw_test() rules.check(2) self.assertEqual( _('Expected {expected_count} tests but only ' '{seen_count} ran.').format(expected_count=42, seen_count=1), self.suite._tests[0]._line.description)
def _process_plan_lines(self, final_line_count): """Process plan line rules.""" if not self._lines_seen['plan']: self._add_error(_('Missing a plan.')) return if len(self._lines_seen['plan']) > 1: self._add_error(_('Only one plan line is permitted per file.')) return plan, at_line = self._lines_seen['plan'][0] if not self._plan_on_valid_line(at_line, final_line_count): self._add_error( _('A plan must appear at the beginning or end of the file.')) return if plan.expected_tests != self._lines_seen['test']: self._add_error(_( 'Expected {expected_count} tests ' 'but only {seen_count} ran.').format( expected_count=plan.expected_tests, seen_count=self._lines_seen['test']))
def _description(self, test): if self.FORMAT: try: return self.FORMAT.format( method_name=str(test), short_description=test.shortDescription() or '') except KeyError: sys.exit(_( 'Bad format string: {format}\n' 'Replacement options are: {{short_description}} and ' '{{method_name}}').format(format=self.FORMAT)) return test.shortDescription() or str(test)
def _description(self, test): if self.FORMAT: try: return self.FORMAT.format( method_name=str(test), short_description=test.shortDescription() or '') except KeyError: sys.exit( _('Bad format string: {format}\n' 'Replacement options are: {{short_description}} and ' '{{method_name}}').format(format=self.FORMAT)) return test.shortDescription() or str(test)
def _process_plan_lines(self, final_line_count): """Process plan line rules.""" if not self._lines_seen['plan']: self._add_error(_('Missing a plan.')) return if len(self._lines_seen['plan']) > 1: self._add_error(_('Only one plan line is permitted per file.')) return plan, at_line = self._lines_seen['plan'][0] if not self._plan_on_valid_line(at_line, final_line_count): self._add_error( _('A plan must appear at the beginning or end of the file.')) return if plan.expected_tests != self._lines_seen['test']: self._add_error( _('Expected {expected_count} tests ' 'but only {seen_count} ran.').format( expected_count=plan.expected_tests, seen_count=self._lines_seen['test']))
def pytest_addoption(parser): """Include all the command line options.""" group = parser.getgroup('terminal reporting', after='general') group.addoption( '--tap-stream', default=False, action='store_true', help=_('Stream TAP output instead of the default test runner output.')) group.addoption( '--tap-files', default=False, action='store_true', help=_( 'Store all TAP test results into individual files per test case.')) group.addoption( '--tap-combined', default=False, action='store_true', help=_('Store all TAP test results into a combined output file.')) group.addoption( '--tap-outdir', metavar='path', help=_('An optional output directory to write TAP files to. ' 'If the directory does not exist, it will be created.'))
def parse_args(argv): description = _('A TAP consumer for Python') epilog = _( 'When no files are given or a dash (-) is used for the file name, ' 'tappy will read a TAP stream from STDIN.') parser = argparse.ArgumentParser(description=description, epilog=epilog) parser.add_argument( 'files', metavar='FILE', nargs='*', help=_( 'A file containing TAP output. Any directories listed will be ' 'scanned for files to include as TAP files.')) parser.add_argument( '-v', '--verbose', action='store_const', default=1, const=2, help=_('use verbose messages')) # argparse expects the executable to be removed from argv. args = parser.parse_args(argv[1:]) # When no files are provided, the user wants to use a TAP stream on STDIN. # But they probably didn't mean it if there is no pipe connected. # In that case, print the help and exit. if not args.files and sys.stdin.isatty(): sys.exit(parser.print_help()) return args
def test_errors_with_version_not_on_first_line(self): sample = inspect.cleandoc("""# Something that doesn't belong. TAP version 13 1..0 """) temp = tempfile.NamedTemporaryFile(delete=False) temp.write(sample.encode('utf-8')) temp.close() loader = Loader() suite = loader.load_suite_from_file(temp.name) self.assertEqual(1, len(suite._tests)) self.assertEqual(_('The version must be on the first line.'), suite._tests[0]._line.description)
def test_errors_with_multiple_version_lines(self): sample = inspect.cleandoc("""TAP version 13 TAP version 13 1..0 """) temp = tempfile.NamedTemporaryFile(delete=False) temp.write(sample.encode("utf-8")) temp.close() loader = Loader() suite = loader.load_suite_from_file(temp.name) self.assertEqual(1, len(suite._tests)) self.assertEqual(_("Multiple version lines appeared."), suite._tests[0]._line.description)
def test_errors_with_multiple_version_lines(self): sample = inspect.cleandoc( """TAP version 13 TAP version 13 1..0 """) temp = tempfile.NamedTemporaryFile(delete=False) temp.write(sample.encode('utf-8')) temp.close() loader = Loader() suite = loader.load_suite_from_file(temp.name) self.assertEqual(1, len(suite._tests)) self.assertEqual( _('Multiple version lines appeared.'), suite._tests[0]._line.description)
def test_errors_with_version_not_on_first_line(self): sample = inspect.cleandoc( """# Something that doesn't belong. TAP version 13 1..0 """) temp = tempfile.NamedTemporaryFile(delete=False) temp.write(sample.encode('utf-8')) temp.close() loader = Loader() suite = loader.load_suite_from_file(temp.name) self.assertEqual(1, len(suite._tests)) self.assertEqual( _('The version must be on the first line.'), suite._tests[0]._line.description)
def _make_header(self, test_case): return _('# TAP results for {test_case}').format(test_case=test_case)
def addUnexpectedSuccess(self, test): super(TAPTestResult, self).addUnexpectedSuccess(test) self.tracker.add_ok(self._cls_name(test), self._description(test), _('(unexpected success)'))
def addExpectedFailure(self, test, err): super(TAPTestResult, self).addExpectedFailure(test, err) self.tracker.add_not_ok(self._cls_name(test), self._description(test), _('(expected failure)'))
def _write_test_case_header(self, test_case, stream): print(_('# TAP results for {test_case}').format(test_case=test_case), file=stream)
def _process_version_lines(self): """Process version line rules.""" if len(self._lines_seen['version']) > 1: self._add_error(_('Multiple version lines appeared.')) elif self._lines_seen['version'][0] != 1: self._add_error(_('The version must be on the first line.'))
def test_adds_unexpected_success(self): result = self._make_one() result.addUnexpectedSuccess(FakeTestCase()) line = result.tracker._test_cases['FakeTestCase'][0] self.assertTrue(line.ok) self.assertEqual(line.directive.text, _('(unexpected success)'))
def addExpectedFailure(self, test, err): super(TAPTestResult, self).addExpectedFailure(test, err) self.tracker.add_not_ok(self._cls_name(test), self._description(test), _("(expected failure)"))
def handle_bail(self, bail): """Handle a bail line.""" self._add_error(_("Bailed: {reason}").format(reason=bail.reason))
def _write_test_case_header(self, test_case, stream): print(_('# TAP results for {test_case}').format( test_case=test_case), file=stream)
def handle_file_does_not_exist(self): """Handle a test file that does not exist.""" self._add_error(_('{filename} does not exist.').format( filename=self._filename))
def addExpectedFailure(self, test, err): super(TAPTestResult, self).addExpectedFailure(test, err) diagnostics = formatter.format_exception(err) self.tracker.add_not_ok( self._cls_name(test), self._description(test), _('(expected failure)'), diagnostics=diagnostics)
def _process_version_lines(self): """Process version line rules.""" if len(self._lines_seen["version"]) > 1: self._add_error(_("Multiple version lines appeared.")) elif self._lines_seen["version"][0] != 1: self._add_error(_("The version must be on the first line."))
def addUnexpectedSuccess(self, test): super(TAPTestResult, self).addUnexpectedSuccess(test) self.tracker.add_ok(self._cls_name(test), self._description(test), _("(unexpected success)"))
def handle_file_does_not_exist(self): """Handle a test file that does not exist.""" self._add_error( _("{filename} does not exist.").format(filename=self._filename))
def handle_bail(self, bail): """Handle a bail line.""" self._add_error(_('Bailed: {reason}').format(reason=bail.reason))