class FreshenNosePlugin(Plugin): name = "freshen" def options(self, parser, env): super(FreshenNosePlugin, self).options(parser, env) parser.add_option('--tags', action='store', dest='tags', default=env.get('NOSE_FRESHEN_TAGS'), help="Run only those scenarios and features which " "match the given tags. Should be a comma-separated " "list. Each tag can be prefixed with a ~ to negate " "[NOSE_FRESHEN_TAGS]") parser.add_option('--language', action="store", dest='language', default='en', help='Change the language used when reading the feature files', ) def configure(self, options, config): super(FreshenNosePlugin, self).configure(options, config) all_tags = options.tags.split(",") if options.tags else [] self.tagmatcher = TagMatcher(all_tags) self.language = load_language(options.language) self.impl_loader = StepImplLoader() if not self.language: print >> sys.stderr, "Error: language '%s' not available" % options.language exit(1) def wantDirectory(self, dirname): if not os.path.exists(os.path.join(dirname, ".freshenignore")): return True return None def wantFile(self, filename): return filename.endswith(".feature") or None def loadTestsFromFile(self, filename, indexes=[]): log.debug("Loading from file %s" % filename) step_registry = StepImplRegistry(TagMatcher) try: feat = load_feature(filename, self.language) path = os.path.dirname(filename) self.impl_loader.load_steps_impl(step_registry, path, feat.use_step_defs) except ParseException, e: ec, ev, tb = sys.exc_info() yield Failure(ParseException, ParseException(e.pstr, e.loc, e.msg + " in %s" % filename), tb) return cnt = 0 ctx = FeatureSuite() for i, sc in enumerate(feat.iter_scenarios()): if (not indexes or (i + 1) in indexes): if self.tagmatcher.check_match(sc.tags + feat.tags): yield FreshenTestCase(StepsRunner(step_registry), step_registry, feat, sc, ctx) cnt += 1 if not cnt: yield False
def load_file(filepath): feature = load_feature(filepath, load_language(LANGUAGE)) registry = StepImplRegistry(TagMatcher) loader = StepImplLoader() loader.load_steps_impl(registry, os.path.dirname(feature.src_file), feature.use_step_defs) return registry
def configure(self, options, config): super(FreshenNosePlugin, self).configure(options, config) all_tags = options.tags.split(",") if options.tags else [] self.tagmatcher = TagMatcher(all_tags) self.language = load_language(options.language) self.impl_loader = StepImplLoader() if not self.language: print >> sys.stderr, "Error: language '%s' not available" % options.language exit(1)
def load_dir(dirpath): registry = StepImplRegistry(TagMatcher) loader = StepImplLoader() def walktree(top, filter_func=lambda x: True): names = os.listdir(top) for name in names: path = os.path.join(top, name) if filter_func(path): yield path if os.path.isdir(path): for i in walktree(path, filter_func): yield i for feature_file in walktree(dirpath, lambda x: x.endswith('.feature')): feature = load_feature(feature_file, load_language(LANGUAGE)) loader.load_steps_impl(registry, os.path.dirname(feature.src_file), feature.use_step_defs) return registry
class FreshenNosePlugin(Plugin): name = "freshen" def options(self, parser, env): super(FreshenNosePlugin, self).options(parser, env) parser.add_option('--tags', action='store', dest='tags', default=env.get('NOSE_FRESHEN_TAGS'), help="Run only those scenarios and features which " "match the given tags. Should be a comma-separated " "list. Each tag can be prefixed with a ~ to negate " "[NOSE_FRESHEN_TAGS]") parser.add_option( '--language', action="store", dest='language', default='en', help='Change the language used when reading the feature files', ) def configure(self, options, config): super(FreshenNosePlugin, self).configure(options, config) all_tags = options.tags.split(",") if options.tags else [] self.tagmatcher = TagMatcher(all_tags) self.language = load_language(options.language) self.impl_loader = StepImplLoader() if not self.language: print >> sys.stderr, "Error: language '%s' not available" % options.language exit(1) def wantDirectory(self, dirname): if not os.path.exists(os.path.join(dirname, ".freshenignore")): return True return None def wantFile(self, filename): return filename.endswith(".feature") or None def loadTestsFromFile(self, filename, indexes=[]): log.debug("Loading from file %s" % filename) step_registry = StepImplRegistry(TagMatcher) try: feat = load_feature(filename, self.language) path = os.path.dirname(filename) self.impl_loader.load_steps_impl(step_registry, path, feat.use_step_defs) except ParseException, e: ec, ev, tb = sys.exc_info() yield Failure( ParseException, ParseException(e.pstr, e.loc, e.msg + " in %s" % filename), tb) return cnt = 0 ctx = FeatureSuite() for i, sc in enumerate(feat.iter_scenarios()): if (not indexes or (i + 1) in indexes): if self.tagmatcher.check_match(sc.tags + feat.tags): yield FreshenTestCase(StepsRunner(step_registry), step_registry, feat, sc, ctx) cnt += 1 if not cnt: yield False
def load_step_definitions(paths): loader = StepImplLoader() sr = StepImplRegistry(TagMatcher) for path in paths: loader.load_steps_impl(sr, path) return sr