Test the --python-executable flag with --python-version
(self)
| 25 | assert options.snapshot() == parsed_options.snapshot() |
| 26 | |
| 27 | def test_executable_inference(self) -> None: |
| 28 | """Test the --python-executable flag with --python-version""" |
| 29 | sys_ver_str = "{ver.major}.{ver.minor}".format(ver=sys.version_info) |
| 30 | |
| 31 | base = ["file.py"] # dummy file |
| 32 | |
| 33 | # test inference given one (infer the other) |
| 34 | matching_version = base + [f"--python-version={sys_ver_str}"] |
| 35 | _, options = process_options(matching_version) |
| 36 | assert options.python_version == sys.version_info[:2] |
| 37 | assert options.python_executable == sys.executable |
| 38 | |
| 39 | matching_version = base + [f"--python-executable={sys.executable}"] |
| 40 | _, options = process_options(matching_version) |
| 41 | assert options.python_version == sys.version_info[:2] |
| 42 | assert options.python_executable == sys.executable |
| 43 | |
| 44 | # test inference given both |
| 45 | matching_version = base + [ |
| 46 | f"--python-version={sys_ver_str}", |
| 47 | f"--python-executable={sys.executable}", |
| 48 | ] |
| 49 | _, options = process_options(matching_version) |
| 50 | assert options.python_version == sys.version_info[:2] |
| 51 | assert options.python_executable == sys.executable |
| 52 | |
| 53 | # test that --no-site-packages will disable executable inference |
| 54 | matching_version = base + [f"--python-version={sys_ver_str}", "--no-site-packages"] |
| 55 | _, options = process_options(matching_version) |
| 56 | assert options.python_version == sys.version_info[:2] |
| 57 | assert options.python_executable is None |
| 58 | |
| 59 | # Test setting python_version/executable from config file |
| 60 | special_opts = argparse.Namespace() |
| 61 | special_opts.python_executable = None |
| 62 | special_opts.python_version = None |
| 63 | special_opts.no_executable = None |
| 64 | |
| 65 | # first test inferring executable from version |
| 66 | options = Options() |
| 67 | options.python_executable = cast(Any, None) |
| 68 | options.python_version = sys.version_info[:2] |
| 69 | infer_python_executable(options, special_opts) |
| 70 | assert options.python_version == sys.version_info[:2] |
| 71 | assert options.python_executable == sys.executable |
| 72 | |
| 73 | # then test inferring version from executable |
| 74 | options = Options() |
| 75 | options.python_executable = sys.executable |
| 76 | infer_python_executable(options, special_opts) |
| 77 | assert options.python_version == sys.version_info[:2] |
| 78 | assert options.python_executable == sys.executable |
nothing calls this directly
no test coverage detected