How to use parse_error_id method in refurb

Best Python code snippet using refurb_python

test_arg_parsing.py

Source:test_arg_parsing.py Github

copy

Full Screen

...150 }151 for input, output in tests.items():152 if output == ValueError:153 with pytest.raises(ValueError):154 parse_error_id(input)155 else:156 assert parse_error_id(input) == output157def test_disable_error() -> None:158 settings = parse_args(["--disable", "FURB100"])159 assert settings == Settings(disable=set((ErrorCode(100),)))160def test_disable_existing_enabled_error() -> None:161 settings = parse_args(["--enable", "FURB100", "--disable", "FURB100"])162 assert settings == Settings(disable=set((ErrorCode(100),)))163def test_enable_existing_disabled_error() -> None:164 settings = parse_args(["--disable", "FURB100", "--enable", "FURB100"])165 assert settings == Settings(enable=set((ErrorCode(100),)))166def test_parse_disable_check_missing_arg() -> None:167 with pytest.raises(168 ValueError, match='refurb: missing argument after "--disable"'169 ):170 parse_args(["--disable"])...

Full Screen

Full Screen

settings.py

Source:settings.py Github

copy

Full Screen

...59 config_file=old.config_file or new.config_file,60 python_version=old.python_version or new.python_version,61 )62ERROR_ID_REGEX = re.compile("^([A-Z]{3,4})?(\\d{3})$")63def parse_error_id(err: str) -> ErrorCode:64 if match := ERROR_ID_REGEX.match(err):65 groups = match.groups()66 return ErrorCode(prefix=groups[0] or "FURB", id=int(groups[1]))67 raise ValueError(f'refurb: "{err}" must be in form FURB123 or 123')68def parse_python_version(version: str) -> tuple[int, int]:69 nums = version.split(".")70 if len(nums) == 2 and all(num.isnumeric() for num in nums):71 return tuple(int(num) for num in nums)[:2] # type: ignore72 raise ValueError("refurb: version must be in form `x.y`")73def parse_config_file(contents: str) -> Settings:74 config = tomllib.loads(contents)75 if tool := config.get("tool"):76 if config := tool.get("refurb"):77 ignore = set(78 parse_error_id(str(x)) for x in config.get("ignore", [])79 )80 enable = set(81 parse_error_id(str(x)) for x in config.get("enable", [])82 )83 disable = set(84 parse_error_id(str(x)) for x in config.get("disable", [])85 )86 version = config.get("python_version")87 python_version = parse_python_version(version) if version else None88 return Settings(89 ignore=ignore,90 enable=enable - disable,91 disable=disable,92 load=config.get("load", []),93 quiet=config.get("quiet", False),94 disable_all=config.get("disable_all", False),95 enable_all=config.get("enable_all", False),96 python_version=python_version,97 )98 return Settings()99def parse_command_line_args(args: list[str]) -> Settings:100 if not args or args[0] in ("--help", "-h"):101 return Settings(help=True)102 if args[0] in ("--version", "-v"):103 return Settings(version=True)104 if args[0] == "gen":105 return Settings(generate=True)106 iargs = iter(args)107 settings = Settings()108 def get_next_arg(arg: str, args: Iterator[str]) -> str:109 if (value := next(args, None)) is not None:110 return value111 raise ValueError(f'refurb: missing argument after "{arg}"')112 for arg in iargs:113 if arg == "--debug":114 settings.debug = True115 elif arg == "--quiet":116 settings.quiet = True117 elif arg == "--disable-all":118 settings.enable.clear()119 settings.disable_all = True120 elif arg == "--enable-all":121 settings.disable.clear()122 settings.enable_all = True123 elif arg == "--explain":124 settings.explain = parse_error_id(get_next_arg(arg, iargs))125 elif arg == "--ignore":126 settings.ignore.add(parse_error_id(get_next_arg(arg, iargs)))127 elif arg == "--enable":128 error_code = parse_error_id(get_next_arg(arg, iargs))129 settings.enable.add(error_code)130 settings.disable.discard(error_code)131 elif arg == "--disable":132 error_code = parse_error_id(get_next_arg(arg, iargs))133 settings.disable.add(error_code)134 settings.enable.discard(error_code)135 elif arg == "--load":136 settings.load.append(get_next_arg(arg, iargs))137 elif arg == "--config-file":138 settings.config_file = get_next_arg(arg, iargs)139 elif arg == "--python-version":140 version = get_next_arg(arg, iargs)141 settings.python_version = parse_python_version(version)142 elif arg.startswith("-"):143 raise ValueError(f'refurb: unsupported option "{arg}"')144 else:145 settings.files.append(arg)146 return settings...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run refurb automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful