def main(): feature_filenames = [] for path, _, basenames in os.walk(FEATURE_ROOT): for basename in basenames: if basename.endswith('.feature'): feature_filename = os.path.join(path, basename) parse_from_filename(feature_filename)
def main(): try: shutil.rmtree(PARSED_FEATURE_ROOT) except OSError: if os.path.isdir(PARSED_FEATURE_ROOT): raise has_errors = False for path, _, basenames in os.walk(FEATURE_ROOT): for basename in basenames: if basename.endswith('.feature'): feature_filename = os.path.join(path, basename) parsed_feature_filename = re.sub(r'\.feature$', '.json', os.path.join(PARSED_FEATURE_ROOT, os.path.relpath(feature_filename, FEATURE_ROOT)) ) try: os.makedirs(os.path.dirname(parsed_feature_filename)) except OSError: if not os.path.isdir(os.path.dirname(parsed_feature_filename)): raise try: parsed = parse_from_filename(feature_filename, dict_cls=collections.OrderedDict) except ParseError as exc: print >>sys.stderr, '{} of {}'.format(exc, feature_filename) has_errors = True else: open(parsed_feature_filename, 'w').write(json.dumps(parsed, indent=4)) if has_errors: exit(1)
def test_features_against_schema(self): for path, _, basenames in os.walk(FEATURE_ROOT): for basename in basenames: if not basename.endswith('.feature'): continue feature_filename = os.path.join(path, basename) parsed = parse_from_filename(feature_filename) try: jsonschema.validate(parsed, SCHEMA) except jsonschema.ValidationError: sys.stderr.write('{}\n'.format(feature_filename)) raise
def test_previously_parsed_features(self): for path, _, basenames in os.walk(FEATURE_ROOT): for basename in basenames: if not basename.endswith('.feature'): continue feature_filename = os.path.join(path, basename) parsed = parse_from_filename(feature_filename) parsed_feature_filename = re.sub(r'\.feature$', '.json', os.path.join(PARSED_FEATURE_ROOT, os.path.relpath(feature_filename, FEATURE_ROOT)) ) with open(parsed_feature_filename) as fp: pre_parsed = json.load(fp) try: self.assertEqual( json.loads(json.dumps(parsed)), pre_parsed ) except AssertionError as exc: raise AssertionError('{}:\n\n{}'.format(feature_filename, exc))
def from_filename(cls, filename): parsed = gherkin_parser.parse_from_filename(filename) return cls(parsed, filename)