def testParseLibraryWithMultipleHeadersOverSeveralDirectories_MaxDepth4(self): test_library_path = join(THIS_DIR, "samples", "DeepClasses") expected_classes = ["ClassA", "ClassB", "ClassC", "ClassD", "ClassE"] parsed_classes = parse_library(test_library_path, max_depth=4) retrieved_classes = sorted([c.name for c in parsed_classes]) self.assertListEqual(expected_classes, retrieved_classes)
def testParseLibraryWithSingleRootLevelHeader(self): test_library_path = join(THIS_DIR, "samples", "SimpleHeader") expected_classes = ["SimpleClass"] parsed_classes = parse_library(test_library_path) retrieved_classes = sorted([c.name for c in parsed_classes]) self.assertListEqual(expected_classes, retrieved_classes)
def testParseLibraryWithMultipleRootLevelHeaders(self): test_library_path = join(THIS_DIR, "samples", "DeepClasses") expected_classes = ["ClassA", "ClassB"] parsed_classes = parse_library(test_library_path) retrieved_classes = sorted([c.name for c in parsed_classes]) self.assertListEqual(expected_classes, retrieved_classes)
def testWritingKeywordsTxtFile(self): test_library_path = join(THIS_DIR, "samples", "SimpleHeader") classes = parse_library(test_library_path) outfile = StringIO() output_keywords(classes, outfile) outfile.seek(0) content = outfile.read() self.assertEqual(content, "SimpleClass\tKEYWORD1\npublicIntMethod\tKEYWORD2\npublicMethod\tKEYWORD2\npublicMethodWithInt\tKEYWORD2\n")
def testParseLibraryWithMultipleHeadersOverSeveralDirectories_MaxDepth4( self): test_library_path = join(THIS_DIR, "samples", "DeepClasses") expected_classes = ["ClassA", "ClassB", "ClassC", "ClassD", "ClassE"] parsed_classes = parse_library(test_library_path, max_depth=4) retrieved_classes = sorted([c.name for c in parsed_classes]) self.assertListEqual(expected_classes, retrieved_classes)
def testWritingKeywordsTxtFileWithAdditionalMethodsAndConstants(self): test_library_path = join(THIS_DIR, "samples", "SimpleHeader") classes = parse_library(test_library_path) additional_constants = ["const1", "const2"] outfile = StringIO() output_keywords(classes, outfile, additional_constants) outfile.seek(0) content = outfile.read() self.assertEqual(content, "SimpleClass\tKEYWORD1\npublicIntMethod\tKEYWORD2\npublicMethod\tKEYWORD2\npublicMethodWithInt\tKEYWORD2\nconst1\tLITERAL1\nconst2\tLITERAL1\n")
def testWritingKeywordsTxtFile(self): test_library_path = join(THIS_DIR, "samples", "SimpleHeader") classes = parse_library(test_library_path) outfile = StringIO() output_keywords(classes, outfile) outfile.seek(0) content = outfile.read() self.assertEqual( content, "SimpleClass\tKEYWORD1\npublicIntMethod\tKEYWORD2\npublicMethod\tKEYWORD2\npublicMethodWithInt\tKEYWORD2\n" )
def testWritingKeywordsTxtFileWithAdditionalMethodsAndConstants(self): test_library_path = join(THIS_DIR, "samples", "SimpleHeader") classes = parse_library(test_library_path) additional_constants = ["const1", "const2"] outfile = StringIO() output_keywords(classes, outfile, additional_constants) outfile.seek(0) content = outfile.read() self.assertEqual( content, "SimpleClass\tKEYWORD1\npublicIntMethod\tKEYWORD2\npublicMethod\tKEYWORD2\npublicMethodWithInt\tKEYWORD2\nconst1\tLITERAL1\nconst2\tLITERAL1\n" )
args.source = os.path.abspath(args.source) if not os.path.exists(args.source): print("The source path {path} doesn't exist, quitting...".format(path=args.source)) sys.exit(1) if not os.path.isdir(args.source): print("The source path {path} isn't a directory, quitting...".format(path=args.source)) sys.exit(1) # If header files are specifed use those, otherwise search 'source' to a max depth of 'depth' if len(args.headers) == 0: print("Searching for header files in {path}".format(path=args.source)) print("Search max depth is: {depth}".format(depth=args.depth)) classes = parse_library(args.source, args.depth) else: print("Parsing the following header files:") classes = [] for header in args.headers: print("\t{header}".format(header=header)) try: classes.extend(parse_header(os.path.join(args.source, header))) except FileNotFoundError: print("\tFile {file} not found, skipping".format(file=header)) print("") print("Classes found: {count}".format(count=len(classes))) for clazz in classes: filename = os.path.relpath(clazz.filename, args.source) print("\t {class_name} (./{filename})".format(class_name=clazz.name, filename=filename))