def test_unsupported_platform(monkeypatch): # GIVEN monkeypatch.setattr(sys, "platform", "unsupported_platform") # WHEN retval = main() # THEN assert retval == 1
def test_help(monkeypatch, capsys): # GIVEN monkeypatch.setattr(sys, "argv", ["auditwheel"]) # WHEN retval = main() # THEN assert retval is None captured = capsys.readouterr() assert "usage: auditwheel [-h] [-V] [-v] command ..." in captured.out
def test_non_linux_platform(monkeypatch, capsys): # GIVEN monkeypatch.setattr(sys, "platform", "darwin") # WHEN retval = main() # THEN assert retval == 1 captured = capsys.readouterr() assert captured.out == "Error: This tool only supports Linux\n"
def test_verbose_logging_verbose(basic_cfg_mock, parser_mock, monkeypatch): # GIVEN monkeypatch.setattr(sys, "platform", "linux") args = Mock() args.verbose = 1 args.func.return_value = 0 parser_mock.return_value.parse_args.return_value = args # WHEN retval = main() # THEN assert retval == 0 basic_cfg_mock.assert_called_once_with(level=logging.DEBUG)
def copylib(src_path: str, dest_dir: str, patcher: ElfPatcher) -> Tuple[str, str]: # Do NOT hash filename to make it unique in the particular case of boost # python modules, since otherwise it will be impossible to share a common # registery, which is necessary for cross module interoperability. if "libboost_python" in src_path: src_name = os.path.basename(src_path) dest_path = os.path.join(dest_dir, src_name) if os.path.exists(dest_path): return src_name, dest_path logger.debug('Grafting: %s -> %s', src_path, dest_path) shutil.copy2(src_path, dest_path) rpaths = elf_read_rpaths(src_path) statinfo = os.stat(dest_path) if not statinfo.st_mode & stat.S_IWRITE: os.chmod(dest_path, statinfo.st_mode | stat.S_IWRITE) patcher.set_soname(dest_path, src_name) if any(itertools.chain(rpaths['rpaths'], rpaths['runpaths'])): patcher.set_rpath(dest_path, dest_dir) return src_name, dest_path return copylib_orig(src_path, dest_dir, patcher) auditwheel.repair.copylib = copylib if __name__ == '__main__': sys.exit(main())
@functools.wraps(orig_inwheelctx_enter) def inwheelctx_enter(self): rtn = orig_inwheelctx_enter(self) # `self.path` is a path that extracted files from the wheel file exists # base_dir = glob.glob(join(self.path, '*.dist-info')) # wheel_path = join(base_dir[0], 'WHEEL') # with open(wheel_path, 'r') as f: # wheel_text = f.read() # wheel_text = wheel_text.replace('Root-Is-Purelib: true', 'Root-Is-Purelib: false') # with open(wheel_path, 'w') as f: # f.write(wheel_text) return rtn # # sys.argv replacement # testargs = ["auditwheel_repair.py", "repair", "--plat", "manylinux2014_x86_64", "-w", "wherehouse", "cuclara_image-0.1.1-py3-none-manylinux2014_x86_64.whl"] # with patch.object(sys, 'argv', testargs): if __name__ == '__main__': # Patch with patch.object(auditwheel.elfutils, 'elf_is_python_extension', elf_is_python_extension): with patch.object(InWheelCtx, '__enter__', inwheelctx_enter): main()