Skip to content

Commit

Permalink
Use str.splitlines() to split lines in providers (#33593)
Browse files Browse the repository at this point in the history
  • Loading branch information
eumiro committed Aug 21, 2023
1 parent abbd567 commit bb2689a
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions airflow/providers/apache/hive/hooks/hive.py
Expand Up @@ -317,14 +317,14 @@ def test_hql(self, hql: str) -> None:
try:
self.run_cli(query, verbose=False)
except AirflowException as e:
message = e.args[0].split("\n")[-2]
message = e.args[0].splitlines()[-2]
self.log.info(message)
error_loc = re.search(r"(\d+):(\d+)", message)
if error_loc and error_loc.group(1).isdigit():
lst = int(error_loc.group(1))
begin = max(lst - 2, 0)
end = min(lst + 3, len(query.split("\n")))
context = "\n".join(query.split("\n")[begin:end])
end = min(lst + 3, len(query.splitlines()))
context = "\n".join(query.splitlines()[begin:end])
self.log.info("Context :\n %s", context)
else:
self.log.info("SUCCESS")
Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/microsoft/psrp/hooks/psrp.py
Expand Up @@ -256,7 +256,7 @@ def _log_record(self, log, record):
if message_type == MessageType.ERROR_RECORD:
log(INFO, "%s: %s", record.reason, record)
if record.script_stacktrace:
for trace in record.script_stacktrace.split("\r\n"):
for trace in record.script_stacktrace.splitlines():
log(INFO, trace)

level = INFORMATIONAL_RECORD_LEVEL_MAP.get(message_type)
Expand Down
2 changes: 1 addition & 1 deletion airflow/providers/ssh/hooks/ssh.py
Expand Up @@ -446,7 +446,7 @@ def _pkey_from_private_key(self, private_key: str, passphrase: str | None = None
:return: ``paramiko.PKey`` appropriate for given key
:raises AirflowException: if key cannot be read
"""
if len(private_key.split("\n", 2)) < 2:
if len(private_key.splitlines()) < 2:
raise AirflowException("Key must have BEGIN and END header/footer on separate lines.")

for pkey_class in self._pkey_loaders:
Expand Down
6 changes: 3 additions & 3 deletions tests/providers/docker/operators/test_docker.py
Expand Up @@ -164,9 +164,9 @@ def setup_patchers(self, docker_api_client_patcher):
def dotenv_mock_return_value(**kwargs):
env_dict = {}
env_str = kwargs["stream"]
for env_var in env_str.split("\n"):
kv = env_var.split("=")
env_dict[kv[0]] = kv[1]
for env_var in env_str.splitlines():
key, _, val = env_var.partition("=")
env_dict[key] = val
return env_dict

self.dotenv_patcher = mock.patch("airflow.providers.docker.operators.docker.dotenv_values")
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/elasticsearch/log/test_es_task_handler.py
Expand Up @@ -670,7 +670,7 @@ def test_dynamic_offset(self, stdout_mock, ti, time_machine):
ti.log.info("Test3")

# assert
first_log, second_log, third_log = map(json.loads, stdout_mock.getvalue().strip().split("\n"))
first_log, second_log, third_log = map(json.loads, stdout_mock.getvalue().strip().splitlines())
assert first_log["offset"] < second_log["offset"] < third_log["offset"]
assert first_log["asctime"] == t1.format("YYYY-MM-DDTHH:mm:ss.SSSZZ")
assert second_log["asctime"] == t2.format("YYYY-MM-DDTHH:mm:ss.SSSZZ")
Expand Down
2 changes: 1 addition & 1 deletion tests/providers/google/cloud/hooks/test_dataflow.py
Expand Up @@ -1883,7 +1883,7 @@ class TestDataflow:
],
)
def test_data_flow_valid_job_id(self, log):
echos = ";".join(f"echo {shlex.quote(line)}" for line in log.split("\n"))
echos = ";".join(f"echo {shlex.quote(line)}" for line in log.splitlines())
cmd = ["bash", "-c", echos]
found_job_id = None

Expand Down
Expand Up @@ -372,7 +372,7 @@ def test_should_return_valid_external_url(self, mock_client, mock_get_creds_and_
assert {"project", "interval", "resource", "advancedFilter"} == set(parsed_qs.keys())
assert "global" in parsed_qs["resource"]

filter_params = parsed_qs["advancedFilter"][0].split("\n")
filter_params = parsed_qs["advancedFilter"][0].splitlines()
expected_filter = [
'resource.type="global"',
'logName="projects/project_id/logs/airflow"',
Expand Down

0 comments on commit bb2689a

Please sign in to comment.