def assertPipes(self, sinks, transforms, sources, *expected_pipes, **kw): """Check if the plug function yields the expected pipelines. The first three arguments are passed through to plug. Further arguments are the pipes that should be returned. They are interpreted as a set (since the return order from plug is unspecified). bad_sinks is accepted as keyword args, defaulting to the empty list. """ # Writing this the "normal" way interprets the first optional # positional arg incorrectly. bad_sinks = kw.pop('bad_sinks', []) expected_pipes = set(expected_pipes) if kw: raise TypeError('unsupported kwargs %r' % (kw.keys(), )) try: actual_bad_sinks, pipes = base.plug(sinks, transforms, sources) except KeyboardInterrupt: raise except Exception: print print 'Test erroring, rerunning in debug mode' # Rerun in debug mode. def _debug(message, *args): print message % args base.plug(sinks, transforms, sources, _debug) # Should not reach this since base.plug should raise again. raise actual_pipes = set(pipes) good = expected_pipes & actual_pipes expected_pipes -= good actual_pipes -= good if expected_pipes or actual_pipes: # Failure. Build message. message = ['', ''] def _debug(format, *args): message.append(format % args) base.plug(sinks, transforms, sources, _debug) message.extend(['', 'Expected:']) for pipe in expected_pipes: message.append(str(pipe)) message.extend(['', 'Got:']) for pipe in actual_pipes: message.append(str(pipe)) self.fail('\n'.join(message)) self.assertEqual(bad_sinks, actual_bad_sinks)
def assertPipes(self, sinks, transforms, sources, *expected_pipes, **kw): """Check if the plug function yields the expected pipelines. The first three arguments are passed through to plug. Further arguments are the pipes that should be returned. They are interpreted as a set (since the return order from plug is unspecified). bad_sinks is accepted as keyword args, defaulting to the empty list. """ # Writing this the "normal" way interprets the first optional # positional arg incorrectly. bad_sinks = kw.pop('bad_sinks', []) expected_pipes = set(expected_pipes) if kw: raise TypeError('unsupported kwargs %r' % (kw.keys(),)) try: actual_bad_sinks, pipes = base.plug(sinks, transforms, sources) except KeyboardInterrupt: raise except Exception: print print 'Test erroring, rerunning in debug mode' # Rerun in debug mode. def _debug(message, *args): print message % args base.plug(sinks, transforms, sources, _debug) # Should not reach this since base.plug should raise again. raise actual_pipes = set(pipes) good = expected_pipes & actual_pipes expected_pipes -= good actual_pipes -= good if expected_pipes or actual_pipes: # Failure. Build message. message = ['', ''] def _debug(format, *args): message.append(format % args) base.plug(sinks, transforms, sources, _debug) message.extend(['', 'Expected:']) for pipe in expected_pipes: message.append(str(pipe)) message.extend(['', 'Got:']) for pipe in actual_pipes: message.append(str(pipe)) self.fail('\n'.join(message)) self.assertEqual(bad_sinks, actual_bad_sinks)
def main(options, out, err): """Do stuff.""" if options.list_keywords: display_keywords(out, options.checks) return 0 if options.list_checks: display_checks(out, options.checks) return 0 if options.list_reporters: display_reporters( out, options.config, options.config.pkgcheck_reporter_factory.values(), list(get_plugins('reporter', plugins))) return 0 if not options.repo_bases: err.write( 'Warning: could not determine repo base for profiles, some checks will not work.') err.write() if options.guessed_suite: if options.default_suite: err.write('Tried to guess a suite to use but got multiple matches') err.write('and fell back to the default.') else: err.write('using suite guessed from working directory') if options.guessed_target_repo: err.write('using repository guessed from working directory') try: reporter = options.reporter(out) except errors.ReporterInitError as e: err.write( err.fg('red'), err.bold, '!!! ', err.reset, 'Error initializing reporter: ', e) return 1 addons_map = {} def init_addon(klass): res = addons_map.get(klass) if res is not None: return res deps = list(init_addon(dep) for dep in klass.required_addons) try: res = addons_map[klass] = klass(options, *deps) except KeyboardInterrupt: raise except Exception: err.write('instantiating %s' % (klass,)) raise return res for addon in options.addons: # Ignore the return value, we just need to populate addons_map. init_addon(addon) if options.debug: err.write('target repo: ', repr(options.target_repo)) err.write('base dirs: ', repr(options.repo_bases)) for filterer in options.limiters: err.write('limiter: ', repr(filterer)) debug = logging.debug else: debug = None transforms = list(get_plugins('transform', plugins)) # XXX this is pretty horrible. sinks = list(addon for addon in addons_map.itervalues() if getattr(addon, 'feed_type', False)) reporter.start() for filterer in options.limiters: sources = [feeds.RestrictedRepoSource(options.target_repo, filterer)] bad_sinks, pipes = base.plug(sinks, transforms, sources, debug) if bad_sinks: # We want to report the ones that would work if this was a # full repo scan separately from the ones that are # actually missing transforms. bad_sinks = set(bad_sinks) full_scope = feeds.RestrictedRepoSource( options.target_repo, packages.AlwaysTrue) really_bad, ignored = base.plug(sinks, transforms, [full_scope]) really_bad = set(really_bad) assert bad_sinks >= really_bad, \ '%r unreachable with no limiters but reachable with?' % ( really_bad - bad_sinks,) for sink in really_bad: err.error( 'sink %s could not be connected (missing transforms?)' % ( sink,)) out_of_scope = bad_sinks - really_bad if options.verbose and out_of_scope: err.warn('skipping repo checks (not a full repo scan)') if not pipes: out.write(out.fg('red'), ' * ', out.reset, 'No checks!') else: if options.debug: err.write('Running %i tests' % (len(sinks) - len(bad_sinks),)) for source, pipe in pipes: pipe.start() reporter.start_check( list(base.collect_checks_classes(pipe)), filterer) for thing in source.feed(): pipe.feed(thing, reporter) pipe.finish(reporter) reporter.end_check() reporter.finish() # flush stdout first; if they're directing it all to a file, this makes # results not get the final message shoved in midway out.stream.flush() return 0
def main(options, out, err): """Do stuff.""" if options.list_keywords: display_keywords(out, options) return 0 if options.list_checks: display_checks(out, options) return 0 if options.list_reporters: display_reporters(out, options, options.config.pkgcheck_reporter_factory.values(), list(get_plugins('reporter', plugins))) return 0 if not options.repo_bases: err.write( 'Warning: could not determine repo base for profiles, some checks will not work.' ) err.write() if options.guessed_suite: if options.default_suite: err.write('Tried to guess a suite to use but got multiple matches') err.write('and fell back to the default.') else: err.write('using suite guessed from working directory') if options.guessed_target_repo: err.write('using repository guessed from working directory') try: reporter = options.reporter(out) except errors.ReporterInitError as e: err.write(err.fg('red'), err.bold, '!!! ', err.reset, 'Error initializing reporter: ', e) return 1 addons_map = {} def init_addon(klass): res = addons_map.get(klass) if res is not None: return res deps = list(init_addon(dep) for dep in klass.required_addons) try: res = addons_map[klass] = klass(options, *deps) except KeyboardInterrupt: raise except Exception: err.write('instantiating %s' % (klass, )) raise return res for addon in options.addons: # Ignore the return value, we just need to populate addons_map. init_addon(addon) if options.debug: err.write('target repo: ', repr(options.target_repo)) err.write('base dirs: ', repr(options.repo_bases)) for filterer in options.limiters: err.write('limiter: ', repr(filterer)) debug = logging.debug else: debug = None transforms = list(get_plugins('transform', plugins)) # XXX this is pretty horrible. sinks = list(addon for addon in addons_map.itervalues() if getattr(addon, 'feed_type', False)) reporter.start() for filterer in options.limiters: sources = [feeds.RestrictedRepoSource(options.target_repo, filterer)] bad_sinks, pipes = base.plug(sinks, transforms, sources, debug) if bad_sinks: # We want to report the ones that would work if this was a # full repo scan separately from the ones that are # actually missing transforms. bad_sinks = set(bad_sinks) full_scope = feeds.RestrictedRepoSource(options.target_repo, packages.AlwaysTrue) really_bad, ignored = base.plug(sinks, transforms, [full_scope]) really_bad = set(really_bad) assert bad_sinks >= really_bad, \ '%r unreachable with no limiters but reachable with?' % ( really_bad - bad_sinks,) for sink in really_bad: err.error( 'sink %s could not be connected (missing transforms?)' % (sink, )) out_of_scope = bad_sinks - really_bad if options.verbose and out_of_scope: err.warn('skipping repo checks (not a full repo scan)') if not pipes: out.write(out.fg('red'), ' * ', out.reset, 'No checks!') else: if options.debug: err.write('Running %i tests' % (len(sinks) - len(bad_sinks), )) for source, pipe in pipes: pipe.start() reporter.start_check(list(base.collect_checks_classes(pipe)), filterer) for thing in source.feed(): pipe.feed(thing, reporter) pipe.finish(reporter) reporter.end_check() reporter.finish() # flush stdout first; if they're directing it all to a file, this makes # results not get the final message shoved in midway out.stream.flush() return 0