How to use run_refurb method in refurb

Best Python code snippet using refurb_python

test_checks.py

Source:test_checks.py Github

copy

Full Screen

...10TEST_DATA_PATH = get_test_data_path()11def test_checks() -> None:12 run_checks_in_folder(TEST_DATA_PATH)13def test_fatal_mypy_error_is_bubbled_up() -> None:14 errors = run_refurb(Settings(files=["something"]))15 assert errors == [16 "refurb: can't read file 'something': No such file or directory"17 ]18def test_mypy_error_is_bubbled_up() -> None:19 errors = run_refurb(Settings(files=["some_file.py"]))20 assert errors == [21 "refurb: can't read file 'some_file.py': No such file or directory"22 ]23def test_ignore_check_is_respected() -> None:24 test_file = str(TEST_DATA_PATH / "err_100.py")25 errors = run_refurb(26 Settings(27 files=[test_file], ignore=set((ErrorCode(100), ErrorCode(123)))28 )29 )30 assert len(errors) == 031def test_ignore_custom_check_is_respected() -> None:32 args = [33 "test/e2e/custom_check.py",34 "--load",35 "test.custom_checks.disallow_call",36 ]37 ignore_args = args + ["--ignore", "XYZ100"]38 errors_normal = run_refurb(parse_command_line_args(args))39 errors_while_ignoring = run_refurb(parse_command_line_args(ignore_args))40 assert errors_normal41 assert not errors_while_ignoring42def test_system_exit_is_caught() -> None:43 test_pkg = "test/e2e/empty_package"44 errors = run_refurb(Settings(files=[test_pkg]))45 assert errors == [46 "refurb: There are no .py[i] files in directory 'test/e2e/empty_package'"47 ]48DISABLED_CHECK = "test.custom_checks.disabled_check"49def test_disabled_check_is_not_ran_by_default() -> None:50 errors = run_refurb(51 Settings(files=["test/e2e/dummy.py"], load=[DISABLED_CHECK])52 )53 assert not errors54def test_disabled_check_ran_if_explicitly_enabled() -> None:55 errors = run_refurb(56 Settings(57 files=["test/e2e/dummy.py"],58 load=[DISABLED_CHECK],59 enable=set((ErrorCode(prefix="XYZ", id=101),)),60 )61 )62 expected = "test/e2e/dummy.py:1:1 [XYZ101]: This message is disabled by default" # noqa: E50163 assert len(errors) == 164 assert str(errors[0]) == expected65def test_disable_all_will_only_load_explicitly_enabled_checks() -> None:66 errors = run_refurb(67 Settings(68 files=["test/data/"],69 disable_all=True,70 enable=set((ErrorCode(100),)),71 )72 )73 assert all(74 isinstance(error, Error) and error.code == 100 for error in errors75 )76def test_disable_will_actually_disable_check_loading() -> None:77 errors = run_refurb(78 Settings(79 files=["test/data/err_123.py"],80 disable=set((ErrorCode(123),)),81 )82 )83 assert not errors84def test_load_will_only_load_each_modules_once() -> None:85 errors_normal = run_refurb(86 Settings(87 files=["test/e2e/custom_check.py"],88 load=["test.custom_checks"],89 )90 )91 duplicated_load_errors = run_refurb(92 Settings(93 files=["test/e2e/custom_check.py"],94 load=["test.custom_checks", "test.custom_checks"],95 )96 )97 assert len(errors_normal) == len(duplicated_load_errors)98def test_load_builtin_checks_again_does_nothing() -> None:99 errors_normal = run_refurb(Settings(files=["test/data/err_100.py"]))100 duplicated_load_errors = run_refurb(101 Settings(102 files=["test/data/err_100.py"],103 load=["refurb"],104 )105 )106 assert len(errors_normal) == len(duplicated_load_errors)107def test_injection_of_settings_into_checks() -> None:108 errors = run_refurb(109 Settings(110 files=["test/e2e/dummy.py"],111 load=["test.custom_checks.settings"],112 )113 )114 msg = "test/e2e/dummy.py:1:1 [XYZ103]: Files being checked: ['test/e2e/dummy.py']"115 assert len(errors) == 1116 assert str(errors[0]) == msg117def test_explicitly_disabled_check_is_ignored_when_enable_all_is_set() -> None:118 errors = run_refurb(119 Settings(120 files=["test/data/err_123.py"],121 enable_all=True,122 disable=set((ErrorCode(123),)),123 )124 )125 assert not errors126def test_checks_with_python_version_dependant_error_msgs() -> None:127 run_checks_in_folder(Path("test/data_3.10"), version=(3, 10))128def run_checks_in_folder(129 folder: Path, *, version: tuple[int, int] | None = None130) -> None:131 errors = run_refurb(132 Settings(133 files=[str(folder)],134 python_version=version,135 enable=set((ErrorCode(120),)),136 )137 )138 got = "\n".join([str(error) for error in errors])139 files = sorted(folder.glob("*.txt"), key=lambda p: p.name)140 expected = "\n".join(file.read_text()[:-1] for file in files)...

Full Screen

Full Screen

test_main.py

Source:test_main.py Github

copy

Full Screen

...55 Error101(filename="1_last", line=10, column=5, msg=""),56 ]57def test_debug_flag():58 settings = Settings(files=["test/e2e/dummy.py"], debug=True)59 output = run_refurb(settings)60 assert output == [61 """\62MypyFile:1(63 test/e2e/dummy.py64 ExpressionStmt:1(65 StrExpr(\\u000aThis is a dummy file just to make sure that the refurb command is installed\\u000aand running correctly.\\u000a)))"""66 ]67def test_generate_subcommand():68 with patch("refurb.main.generate") as p:69 main(["gen"])70 p.assert_called_once()71def test_help_flag_calls_print():72 for args in (["--help"], ["-h"], []):73 with patch("builtins.print") as p:74 main(args) # type: ignore75 p.assert_called_once()76 assert "usage" in p.call_args[0][0]77def test_version_flag_calls_version_func():78 for args in (["--version"], ["-v"]):79 with patch("refurb.main.version") as p:80 main(args)81 p.assert_called_once()82def test_explain_flag_mentioned_if_error_exists():83 with patch("builtins.print") as p:84 main(["test/data/err_100.py"])85 p.assert_called_once()86 assert "Run `refurb --explain ERR`" in p.call_args[0][0]87def test_explain_flag_not_mentioned_when_quiet_flag_is_enabled():88 with patch("builtins.print") as p:89 main(["test/data/err_100.py", "--quiet"])90 p.assert_called_once()91 assert "Run `refurb --explain ERR`" not in p.call_args[0][0]92def test_no_blank_line_printed_if_there_are_no_errors():93 with patch("builtins.print") as p:94 main(["test/e2e/dummy.py"])95 assert p.call_count == 096@pytest.mark.skipif(not os.getenv("CI"), reason="Locale installation required")97def test_utf8_is_used_to_load_files_when_error_occurs() -> None:98 """99 See issue https://github.com/dosisod/refurb/issues/37. This check will100 set the zh_CN.GBK locale, run a particular file, and if all goes well,101 no exception will be thrown. This test is only ran when the CI environment102 variable is set, which is set by GitHub Actions.103 """104 setlocale(LC_ALL, "zh_CN.GBK")105 try:106 main(["test/e2e/gbk.py"])107 except UnicodeDecodeError:108 setlocale(LC_ALL, "")109 raise110 setlocale(LC_ALL, "")111def test_load_custom_config_file():112 args = [113 "test/data/err_101.py",114 "--quiet",115 "--config-file",116 "test/config/config.toml",117 ]118 errors = run_refurb(load_settings(args))...

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