def check(args): filename = args[0] output = ChunkedIO() namespace = Namespace('Test', '1.0') logger = MessageLogger.get(namespace=namespace, output=output) logger.enable_warnings(True) transformer = Transformer(namespace) transformer.set_include_paths([ os.path.join(top_srcdir, 'gir'), top_builddir, os.path.join(top_builddir, 'gir'), ]) transformer.register_include(Include.from_string('GObject-2.0')) ss = SourceScanner() options = Options() exit_code = process_packages(options, ['gobject-2.0']) if exit_code: sys.exit(exit_code) ss.set_cpp_options(options.cpp_includes, options.cpp_defines, options.cpp_undefines) ss.parse_files([filename]) ss.parse_macros([filename]) transformer.parse(ss.get_symbols()) cbp = GtkDocCommentBlockParser() blocks = cbp.parse_comment_blocks(ss.get_comments()) main = MainTransformer(transformer, blocks) main.transform() final = IntrospectablePass(transformer, blocks) final.validate() emitted_warnings = [w[w.find(':') + 1:] for w in output.getvalue()] expected_warnings = _extract_expected(filename) sortkey = lambda x: int(x.split(':')[0]) expected_warnings.sort(key=sortkey) emitted_warnings.sort(key=sortkey) if len(expected_warnings) != len(emitted_warnings): raise SystemExit("ERROR in '%s': %d warnings were emitted, " "expected %d:\n%s" % (os.path.basename(filename), len(emitted_warnings), len(expected_warnings), _diff(expected_warnings, emitted_warnings))) for emitted_warning, expected_warning in zip(emitted_warnings, expected_warnings): if expected_warning != emitted_warning: raise SystemExit( "ERROR in '%s': expected warning does not match emitted " "warning:\n%s" % (filename, _diff([expected_warning], [emitted_warning])))
def check(args): filename = args[0] output = StringIO() namespace = Namespace("Test", "1.0") logger = MessageLogger.get(namespace=namespace, output=output) logger.enable_warnings(True) transformer = Transformer(namespace) transformer.set_include_paths( [os.path.join(top_srcdir, 'gir'), top_builddir]) transformer.register_include(Include.from_string("GObject-2.0")) ss = SourceScanner() options = Options() exit_code = process_packages(options, ['gobject-2.0']) if exit_code: sys.exit(exit_code) ss.set_cpp_options(options.cpp_includes, options.cpp_defines, options.cpp_undefines) ss.parse_files([filename]) ss.parse_macros([filename]) transformer.parse(ss.get_symbols()) ap = AnnotationParser() blocks = ap.parse(ss.get_comments()) main = MainTransformer(transformer, blocks) main.transform() final = IntrospectablePass(transformer, blocks) final.validate() raw = output.getvalue() if raw.endswith('\n'): raw = raw[:-1] warnings = raw.split('\n') failed_tests = 0 expected_warnings = _extract_expected(filename) if '' in warnings: warnings.remove('') if len(expected_warnings) != len(warnings): raise SystemExit( "ERROR in %r: expected %d warnings, but got %d:\n" "----\nexpected:\n%s\n----\ngot:\n%s\n----" % (os.path.basename(filename), len(expected_warnings), len(warnings), '\n'.join([w[1] for w in expected_warnings]), '\n'.join( [w.split(':', 2)[2][1:] for w in warnings]))) for warning, (sort_key, expected) in zip(warnings, expected_warnings): actual = warning.split(":", 1)[1] if _diff(expected, actual, filename): raise SystemExit("ERROR: tests %r failed" % (filename, ))
def check(args): filename = args[0] output = ChunkedIO() namespace = Namespace('Test', '1.0') logger = MessageLogger.get(namespace=namespace, output=output) logger.enable_warnings((WARNING, ERROR, FATAL)) transformer = Transformer(namespace) transformer.set_include_paths([os.path.join(top_srcdir, 'gir'), top_builddir]) transformer.register_include(Include.from_string('GObject-2.0')) ss = SourceScanner() options = Options() exit_code = process_packages(options, ['gobject-2.0']) if exit_code: sys.exit(exit_code) ss.set_cpp_options(options.cpp_includes, options.cpp_defines, options.cpp_undefines) ss.parse_files([filename]) ss.parse_macros([filename]) transformer.parse(ss.get_symbols()) cbp = GtkDocCommentBlockParser() blocks = cbp.parse_comment_blocks(ss.get_comments()) main = MainTransformer(transformer, blocks) main.transform() final = IntrospectablePass(transformer, blocks) final.validate() emitted_warnings = [w[w.find(':') + 1:] for w in output.getvalue()] expected_warnings = _extract_expected(filename) sortkey = lambda x: int(x.split(':')[0]) expected_warnings.sort(key=sortkey) emitted_warnings.sort(key=sortkey) if len(expected_warnings) != len(emitted_warnings): raise SystemExit("ERROR in '%s': %d warnings were emitted, " "expected %d:\n%s" % (os.path.basename(filename), len(emitted_warnings), len(expected_warnings), _diff(expected_warnings, emitted_warnings))) for emitted_warning, expected_warning in zip(emitted_warnings, expected_warnings): if expected_warning != emitted_warning: raise SystemExit("ERROR in '%s': expected warning does not match emitted " "warning:\n%s" % (filename, _diff([expected_warning], [emitted_warning])))
def load_tests(loader, tests, pattern): suite = unittest.TestSuite() # add standard tests from module suite.addTests(tests) # Initialize message logger namespace = Namespace('Test', '1.0') logger = MessageLogger.get(namespace=namespace) logger.enable_warnings((WARNING, ERROR, FATAL)) # Load test cases from disc tests_dir = os.path.dirname(os.path.abspath(__file__)) for name, test_case in _all_tests.iteritems(): tests = loader.loadTestsFromTestCase(test_case) suite.addTests(tests) return suite
def create_test_cases(): # Initialize message logger namespace = Namespace('Test', '1.0') logger = MessageLogger.get(namespace=namespace) logger.enable_warnings((WARNING, ERROR, FATAL)) test_cases = {} # Load test cases from disc tests_dir = os.path.dirname(os.path.abspath(__file__)) for dirpath, dirnames, filenames in os.walk(tests_dir): for filename in filenames: tests_file = os.path.join(dirpath, filename) if os.path.basename(tests_file).endswith('.xml'): validate(tests_file) test_case = create_test_case(logger, tests_dir, tests_file) test_cases[test_case.__name__] = test_case return test_cases
n=max(len(expected_tree), len(parsed_tree)), lineterm='') for line in diff: msg += '%s\n' % (line, ) # Compare parsed with expected DocBlock tree self.assertEqual(parsed_tree, expected_tree, msg) return do_test if __name__ == '__main__': # Initialize message logger # TODO: at some point it might be a good idea to test warnings emitted # by annotationparser here, instead of having them in tests/warn/annotationparser.h? namespace = Namespace('Test', '1.0') logger = MessageLogger.get(namespace=namespace) logger.enable_warnings(False) # Load test cases from disc tests_dir = os.path.dirname(os.path.abspath(__file__)) for dirpath, dirnames, filenames in os.walk(tests_dir): for filename in filenames: tests_file = os.path.join(dirpath, filename) if os.path.basename(tests_file).endswith('.xml'): create_tests(tests_dir, tests_file) # Run test suite unittest.main()
def doc_translate (args): parser = argparse.ArgumentParser() parser.add_argument("--packages", nargs="+", action="store", dest="packages", help="CFlags for source scanning") parser.add_argument("-I", nargs="+", action="store", dest="cpp_includes", default=[], help="Pre processor include files") parser.add_argument("-D", nargs="+", action="store", dest="cpp_defines", help="Pre processor defines") parser.add_argument("-U", nargs="+", action="store", dest="cpp_undefines", help="Pre processor undefines") parser.add_argument ("-f", "--filenames", action="store", nargs="+", dest="filenames") parser.add_argument ("-i", "--inplace", action="store_true", dest="inplace") logger = MessageLogger.get(namespace=None) args = parser.parse_args(args[1:]) filename_block_map = {} translator = LegacyTranslator () cflags = [] if args.packages: for p in args.packages: includes = PkgConfig ("--cflags %s" % p) for include in includes: if include: cflags.append (include) cpp_includes = [] for i in args.cpp_includes: cpp_includes.append (os.path.realpath (i)) args.cpp_includes = cpp_includes ss = create_source_scanner (args, args.filenames, cflags) print "sources scanned" cbp = GtkDocCommentBlockParser() blocks = cbp.parse_comment_blocks(ss.get_comments()) for name, block in blocks.iteritems(): try: blocklist = filename_block_map[block.position.filename] except: blocklist = [] filename_block_map[block.position.filename] = blocklist blocklist.append ((name, block)) for filename, blocks in filename_block_map.iteritems(): if args.inplace: print "Translating %s" % filename res = translate_one (filename, translator, blocks) if args.inplace: with open (filename, 'w') as f: f.write (res) else: print res pass
def setUp(self): # Hack to set logging singleton self.namespace = ast.Namespace('Test', '1.0') logger = MessageLogger.get(namespace=self.namespace) logger.enable_warnings((WARNING, ERROR, FATAL))
print('GTK-Doc source directory "%s" not found' % gtkdoc_tests) sys.exit(1) else: print('Using GTK-Doc source directory "%s"' % gtkdoc_tests) for root, dirs, files in os.walk(gtkdoc_tests): for inputfile in files: ext = os.path.splitext(inputfile)[-1].lower() if 'src' in root and ext in ['.c', '.h']: path = os.path.join(root, inputfile) print('Reading "%s"' % path) relpath = os.path.relpath(path, gtkdoc_tests).split(os.sep) relpath = os.path.join(relpath[0], relpath[len(relpath) - 1]) logger = MessageLogger.get(namespace=None) parser = GtkDocCommentBlockParser() writer = GtkDocCommentBlockWriter(indent=True) logger.enable_warnings(True) with io.open(path, 'r') as f: lines = f.readlines() chunks = [] in_comment = False chunk_start = 0 chunk_end = 0 for line_index, line in enumerate(lines): if not in_comment: if COMMENT_BLOCK_START_RE.match(line):
print('GTK-Doc source directory "%s" not found' % gtkdoc_tests) sys.exit(1) else: print('Using GTK-Doc source directory "%s"' % gtkdoc_tests) for root, dirs, files in os.walk(gtkdoc_tests): for inputfile in files: ext = os.path.splitext(inputfile)[-1].lower() if 'src' in root and ext in ['.c', '.h']: path = os.path.join(root, inputfile) print('Reading "%s"' % path) relpath = os.path.relpath(path, gtkdoc_tests).split(os.sep) relpath = os.path.join(relpath[0], relpath[len(relpath) - 1]) logger = MessageLogger.get(namespace=None) parser = GtkDocCommentBlockParser() writer = GtkDocCommentBlockWriter(indent=True) logger.enable_warnings((ERROR, FATAL)) with io.open(path, 'rU') as f: lines = f.readlines() chunks = [] in_comment = False chunk_start = 0 chunk_end = 0 for line_index, line in enumerate(lines): if not in_comment: if COMMENT_BLOCK_START_RE.match(line):