def mock_linters(adaptor: PythonTargetAdaptor) -> LintResults: name = adaptor.name if name == "bad": return LintResults([ LintResult(exit_code=0, stdout=f"Linter 1 passed for `{name}`", stderr=""), LintResult(exit_code=127, stdout=f"Linter 2 failed for `{name}`", stderr=""), ]) return LintResults([ LintResult(exit_code=0, stdout=f"Linter 1 passed for `{name}`", stderr=""), LintResult(exit_code=0, stdout=f"Linter 2 passed for `{name}`", stderr=""), ])
def test_non_union_member_noops() -> None: result, console = run_lint_rule( targets=[make_target(adaptor_type=JvmAppAdaptor)], mock_linter=lambda target: LintResult(exit_code=1, stdout="", stderr=""), ) assert result.exit_code == 0 assert console.stdout.getvalue().strip() == ""
def lint_result(self) -> LintResult: addresses = [ adaptor_with_origin.adaptor.address for adaptor_with_origin in self.adaptors_with_origins ] return LintResult(self.exit_code(addresses), self.stdout(addresses), "")
async def lint( wrapped_target: FormattablePythonTarget, black_setup: BlackSetup, python_setup: PythonSetup, subprocess_encoding_environment: SubprocessEncodingEnvironment, ) -> LintResult: request = black_setup.create_execute_request( wrapped_target=wrapped_target, python_setup=python_setup, subprocess_encoding_environment=subprocess_encoding_environment, check_only=True ) result = await Get(FallibleExecuteProcessResult, ExecuteProcessRequest, request) return LintResult( exit_code=result.exit_code, stdout=result.stdout.decode(), stderr=result.stderr.decode(), )
def lint_with_black( wrapped_target: FormattablePythonTarget, black_input: BlackInput, python_setup: PythonSetup, subprocess_encoding_environment: SubprocessEncodingEnvironment, ) -> LintResult: request = _generate_black_request(wrapped_target, black_input, python_setup, subprocess_encoding_environment, check_only=True) result = yield Get(FallibleExecuteProcessResult, ExecuteProcessRequest, request) yield LintResult( exit_code=result.exit_code, stdout=result.stdout.decode(), stderr=result.stderr.decode(), )
def run_lint_rule( *, targets: List[HydratedTarget], mock_linter: Optional[Callable[[PythonTargetAdaptor], LintResult]] = None, ) -> Tuple[Lint, str]: if mock_linter is None: mock_linter = lambda target_adaptor: LintResult( exit_code=1, stdout=f"Linted the target `{target_adaptor.name}`", stderr="" ) console = MockConsole(use_colors=False) result: Lint = run_rule( lint, rule_args=[ console, HydratedTargets(targets), UnionMembership(union_rules={TargetWithSources: [PythonTargetAdaptor]}) ], mock_gets=[ MockGet(product_type=LintResult, subject_type=PythonTargetAdaptor, mock=mock_linter), ], ) return result, console.stdout.getvalue()
def mock_linter(adaptor: PythonTargetAdaptor) -> LintResult: if adaptor.name == "bad": return LintResult(exit_code=127, stdout="failure", stderr="") return LintResult(exit_code=0, stdout=f"Linted the target `{adaptor.name}`", stderr="")
def mock_linters(_: PythonTargetAdaptor) -> LintResults: return LintResults([ LintResult(exit_code=0, stdout=f"Linter 1", stderr=""), LintResult(exit_code=1, stdout=f"Linter 2", stderr=""), ])