def test_abs_executable(self): with tests.temporary_file() as tmpname: tmpname = os.path.realpath(tmpname) try: os.symlink(sys.executable, tmpname) except (OSError, NotImplementedError): self.skipTest("os.symlink() failed") self.assertEqual(utils.abs_executable(tmpname), tmpname)
def _process_args_impl(self): args = self.args if args.pipe: args.quiet = True args.verbose = False elif args.quiet: args.verbose = False has_jit = pyperf.python_has_jit() if args.warmups is None and not args.worker and not has_jit: args.warmups = 1 nprocess = self.argparser.get_default('processes') nvalues = self.argparser.get_default('values') if args.rigorous: args.processes = nprocess * 2 # args.values = nvalues * 5 // 3 elif args.fast: # use at least 3 processes to benchmark 3 different (randomized) # hash functions args.processes = max(nprocess // 2, 3) args.values = max(nvalues * 2 // 3, 2) elif args.debug_single_value: args.processes = 1 args.warmups = 0 args.values = 1 args.loops = 1 args.min_time = 1e-9 # calibration if args.calibrate_loops: self._only_in_worker("--calibrate-loops") if args.loops: raise CLIError("--loops=N is incompatible with " "--calibrate-loops") elif args.recalibrate_loops: self._only_in_worker("--recalibrate-loops") if args.loops < 1: raise CLIError("--recalibrate-loops requires --loops=N") elif args.calibrate_warmups: self._only_in_worker("--calibrate-warmups") if args.loops < 1: raise CLIError("--calibrate-warmups requires --loops=N") elif args.recalibrate_warmups: self._only_in_worker("--recalibrate-warmups") if args.loops < 1 or args.warmups is None: raise CLIError("--recalibrate-warmups requires " "--loops=N and --warmups=N") else: if args.worker and args.loops < 1: raise CLIError("--worker requires --loops=N " "or --calibrate-loops") if args.worker and args.warmups is None: raise CLIError("--worker requires --warmups=N " "or --calibrate-warmups") if args.values < 1: raise CLIError("--values must be >= 1") filename = args.output if filename and os.path.exists(filename): raise CLIError("The JSON file %r already exists" % filename) if args.worker_task: self._only_in_worker("--worker-task") if args.tracemalloc: try: import tracemalloc # noqa except ImportError as exc: raise CLIError("fail to import tracemalloc: %s" % exc) if args.track_memory: if MS_WINDOWS: from pyperf._win_memory import check_tracking_memory else: from pyperf._memory import check_tracking_memory err_msg = check_tracking_memory() if err_msg: raise CLIError("unable to track the memory usage " "(--track-memory): %s" % err_msg) args.python = abs_executable(args.python) if args.compare_to: args.compare_to = abs_executable(args.compare_to) if args.compare_to: for option in ('output', 'append'): if getattr(args, option): raise CLIError("--%s option is incompatible " "with --compare-to option" % option)