Skip to content
Myr

Comment the test cases

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kevin Deldycke · committed by Kevin Deldycke · parent b035019 · Browse files · 1 file+47 added−21 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Refs: https://github.com/pallets/click/pull/3030/files#r2289224850

Diff stats

1 file+47 added−21 removed

  • tests:+47 added−21 removed

1 file+47 added−21 removed

modified:tests/test_options.py+47 added-21 removed
1852 unmodified lines
18531854@pytest.mark.parametrize(1855 ("opt_params", "args", "expected"),1856 [1857 # Reproduction of cases from1858 # https://github.com/pallets/click/issues/3024#issuecomment-31464807141859 ({"type": EngineType, "flag_value": None}, [], None),1857 # Check that the flag value is returned as-is when the option is passed, and not normalized1858 # to a boolean, even if it is explicitly declared as a flag.1859 ({"type": EngineType, "flag_value": None}, ["--pro"], None),1861 ({"type": EngineType, "flag_value": EngineType.MAX}, [], None),1860 (1863 {"type": EngineType, "flag_value": EngineType.MAX},1861 {"type": EngineType, "is_flag": True, "flag_value": None},1862 ["--pro"],1865 EngineType.MAX,1863 None,1864 ),1867 ({"type": EngineType, "default": EngineType.OSS}, [], EngineType.OSS),1865 ({"type": EngineType, "flag_value": EngineType.OSS}, ["--pro"], EngineType.OSS),1866 (1869 {"type": EngineType, "default": EngineType.OSS},1867 {"type": EngineType, "is_flag": True, "flag_value": EngineType.OSS},1868 ["--pro"],1871 re.compile(re.escape("Error: Option '--pro' requires an argument.\n")),1869 EngineType.OSS,1870 ),1871 (1872 {"type": EngineType, "is_flag": True, "default": EngineType.OSS},1875 [],1873 ["--pro"],1874 EngineType.OSS,1875 ),1876 # The default value is returned as-is when the option is not passed, whatever the flag value.1877 ({"type": EngineType, "flag_value": None}, [], None),1878 ({"type": EngineType, "is_flag": True, "flag_value": None}, [], None),1879 ({"type": EngineType, "flag_value": EngineType.OSS}, [], None),1880 (1881 {"type": EngineType, "is_flag": True, "flag_value": EngineType.OSS},1882 [],1883 None,1884 ),1885 (1886 {"type": EngineType, "is_flag": True, "default": EngineType.OSS},1880 ["--pro"],1887 [],1888 EngineType.OSS,1889 ),1883 # Reproduction of cases from1884 # https://github.com/pallets/click/issues/2012#issuecomment-8924370601890 # The option has not enough parameters to be detected as flag-like, so it requires an argument.1891 (1886 {"flag_value": EngineType.OSS, "default": True},1887 [],1888 "True",1892 {"type": EngineType, "default": EngineType.OSS},1893 ["--pro"],1894 re.compile(re.escape("Error: Option '--pro' requires an argument.\n")),1895 ),1896 ({"type": EngineType, "default": EngineType.OSS}, [], EngineType.OSS),1897 # If a flag value is set, it is returned instead of the default value.1898 (1899 {"type": EngineType, "flag_value": EngineType.OSS, "default": True},1900 ["--pro"],1901 EngineType.OSS,1902 ),1903 (1904 {"type": EngineType, "flag_value": EngineType.OSS, "default": True},1905 [],1906 EngineType.OSS,1907 ),1895 ({"flag_value": 1, "default": True}, [], 1),1908 # Type is not specified and default to string, so the default value is1909 # returned as a string, even if it is a boolean.1910 ({"flag_value": "1", "default": True}, [], "True"),1897 ({"flag_value": 1, "type": str, "default": True}, [], "True"),1898 ({"flag_value": "1", "type": str, "default": True}, [], "True"),1899 ({"flag_value": 1, "type": int, "default": True}, [], 1),1900 ({"flag_value": "1", "type": int, "default": True}, [], 1),1911 ({"flag_value": EngineType.OSS, "default": True}, [], "True"),1912 # See: the result is the same if we force the type to be str.1913 ({"type": str, "flag_value": 1, "default": True}, [], "True"),1914 ({"type": str, "flag_value": "1", "default": True}, [], "True"),1915 ({"type": str, "flag_value": EngineType.OSS, "default": True}, [], "True"),1916 # But having the flag value set to integer is automaticcally recognized by click.1917 ({"flag_value": 1, "default": True}, [], 1),1918 ({"type": int, "flag_value": 1, "default": True}, [], 1),1919 ({"type": int, "flag_value": "1", "default": True}, [], 1),1920 ],1921)1922def test_custom_type_flag_value_standalone_option(runner, opt_params, args, expected):1923 """Test how the type and flag_value influence the returned value.19241925 Cover cases reported in:1926 https://github.com/pallets/click/issues/3024#issuecomment-31464807141927 https://github.com/pallets/click/issues/2012#issuecomment-8924370601928 """19291930 @click.command()1931 @click.option("--pro", **opt_params)1932 def scan(pro):1933 click.echo(repr(pro), nl=False)
153 unmodified lines