def test_cython_vs_header(file_path): with open(file_path, encoding="utf-8") as f: data = f.read() c, cython = re.split("^-+$", data, maxsplit=1, flags=re.MULTILINE) c = c.strip() cython = cython.strip() + "\n" whitelist = [] cpp_args = [] # Special handling of whitelist.test if file_path.endswith("whitelist.test"): whitelist.append(os.path.join(FILES_DIR, "tux_foo.h")) cpp_args.append(f"-I{FILES_DIR}") # Special handling of whitelist2.test if file_path.endswith("whitelist2.test"): whitelist.append( "<stdin>" ) # Only whitelist declarations in 'whitelist2.test' and ignore includes cpp_args.append(f"-I{FILES_DIR}") actual = autopxd.translate(c, os.path.basename(file_path), cpp_args, whitelist) assert cython == actual, f"\nCYTHON:\n{cython}\n\n\nACTUAL:\n{actual}"
def test(self): whitelist = None cpp_args = [] if test_file == 'test/whitelist.test': test_path = os.path.dirname(test_file) whitelist = ['test/tux_foo.h'] cpp_args = ['-I', test_path] actual = autopxd.translate(c, os.path.basename(test_file), cpp_args, whitelist) self.assertEqual(cython, actual)
def _autopxd(): from autopxd import translate # due to some current limitations in autopxd, we must change # directories to ensure the pxd is generated with the correct includes cwd = os.getcwd() os.chdir('mpack') mpack_src = 'mpack-src/src/mpack.c' with open(mpack_src) as f: hdr = f.read() with open('_cmpack.pxd', 'w') as f: f.write(translate(hdr, mpack_src)) os.chdir(cwd)
def gen_pxd(header_file): """ ... """ with open(header_file) as in_file: source = in_file.read() cpp_args = [ '-D__PXD_DEFINES__="%s/../polysync/include/pxd_defines.h"' % WORKING_DIR, '-D__PXD_TYPEDEFS__="%s/../polysync/include/pxd_typedefs.h"' % WORKING_DIR, '-I%s/../polysync/include/pxd_deps' % WORKING_DIR, '-I%s/../polysync/include/pxd_deps/dcps/C/SAC/' % WORKING_DIR, '-I%s/../polysync/include/pxd_deps/cm/' % WORKING_DIR, '-I%s/../polysync/include/pxd_deps/common/' % WORKING_DIR, '-I%s/../polysync/include/pxd_deps/linux/' % WORKING_DIR, '-I%s/../polysync/include/pxd_deps/plugin/' % WORKING_DIR, '-I%s/../polysync/include/pxd_deps/posix/' % WORKING_DIR, '-I%s/../polysync/include/pxd_deps/protobuf/' % WORKING_DIR, '-I%s/../polysync/include/pxd_deps/rmi/' % WORKING_DIR, '-I%s/../polysync/include/pxd_deps/streams/' % WORKING_DIR, '-I%s/../polysync/include/pxd_deps/sys/' % WORKING_DIR, '-I%s/../polysync/include/pxd_deps/vendor/include/x86_64-linux-gnu' % WORKING_DIR, '-I%s/../polysync/include/pxd_deps/vendor/include' % WORKING_DIR, '-I/usr/local/polysync/pdm', '-I/usr/include', ] pxd_source = autopxd.translate(source, os.path.basename(header_file), cpp_args) # some cases that the Python keyowrd `in` is used in the generated pxd # replace with something that isn't a keyword pxd_source = pxd_source.replace(' in ', ' _in ') pxd_source = pxd_source.replace(' in,', ' _in,') pxd_source = pxd_source.replace(' in)', ' _in)') # DDS_boolean* DDS_sequence_DDS_boolean_allocbuf(DDS_unsigned_long len) # DDS_char* DDS_sequence_DDS_char_allocbuf(DDS_unsigned_long len) # DDS_short* DDS_sequence_DDS_short_allocbuf(DDS_unsigned_long len) # DDS_unsigned_short* DDS_sequence_DDS_unsigned_short_allocbuf(DDS_unsigned_long len) # DDS_long* DDS_sequence_DDS_long_allocbuf(DDS_unsigned_long len) # DDS_unsigned_long* DDS_sequence_DDS_unsigned_long_allocbuf(DDS_unsigned_long len) # DDS_unsigned_long_long* DDS_sequence_DDS_unsigned_long_long_allocbuf(DDS_unsigned_long len) # DDS_long_long* DDS_sequence_DDS_long_long_allocbuf(DDS_unsigned_long len) # DDS_float* DDS_sequence_DDS_float_allocbuf(DDS_unsigned_long len) # DDS_double* DDS_sequence_DDS_double_allocbuf(DDS_unsigned_long len) # DDS_octet* DDS_sequence_DDS_octet_allocbuf(DDS_unsigned_long len) return pxd_source
def test_func(): with open(file_path) as f: data = f.read() c, cython = re.split('^-+$', data, maxsplit=1, flags=re.MULTILINE) c = c.strip() cython = cython.strip() + '\n' whitelist = [] cpp_args = [] if file_path == os.path.join(FILES_DIR, 'whitelist.test'): test_path = os.path.dirname(file_path) whitelist.append(os.path.join(FILES_DIR, 'tux_foo.h')) if test_path: cpp_args.append('-I%s' % test_path) actual = autopxd.translate(c, os.path.basename(file_path), cpp_args, whitelist) assert cython == actual
def test_func(): with open(file_path) as f: data = f.read() c, cython = re.split('^-+$', data, maxsplit=1, flags=re.MULTILINE) c = c.strip() cython = cython.strip() + '\n' whitelist = None cpp_args = [] if file_path == FILES_DIR + '/whitelist.test': test_path = os.path.dirname(file_path) whitelist = [FILES_DIR + '/tux_foo.h'] cpp_args = ['-I', test_path] actual = autopxd.translate(c, os.path.basename(file_path), cpp_args, whitelist) assert cython == actual
def test_all(): files_dir = os.path.join(os.path.dirname(__file__), "test_files") list_to_test = list(glob.iglob(files_dir + '/*.test')) print(len(list_to_test), 'files to test') for file_path in list_to_test: with open(file_path) as f: data = f.read() c, cython = re.split('^-+$', data, maxsplit=1, flags=re.MULTILINE) c = c.strip() cython = cython.strip() + '\n' whitelist = None cpp_args = [] if file_path == files_dir + '/whitelist.test': test_path = os.path.dirname(file_path) whitelist = [files_dir + '/tux_foo.h'] cpp_args = ['-I', test_path] actual = autopxd.translate(c, os.path.basename(file_path), cpp_args, whitelist) assert cython == actual
def test(self): actual = autopxd.translate(c, os.path.basename(test_file)) self.assertEqual(cython, actual)