Best Python code snippet using refurb_python
test_checks.py
Source:test_checks.py
...8 assert data_path.is_dir()9 return data_path.relative_to(Path.cwd())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)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!