48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
# coding=utf-8
|
|
from datetime import datetime
|
|
from unittest.mock import patch
|
|
|
|
from spark_executor.core.job_store import JobStore
|
|
from spark_executor.models import Job
|
|
from spark_executor.tools import logs
|
|
|
|
|
|
def _seed(job_id="abc", app_id="application_1"):
|
|
logs.store = JobStore()
|
|
logs.store.put(
|
|
Job(
|
|
job_id=job_id,
|
|
application_id=app_id,
|
|
script_path="/tmp/j.py",
|
|
queue="default",
|
|
submit_time=datetime(2026, 6, 24),
|
|
connection="prod",
|
|
)
|
|
)
|
|
|
|
|
|
def test_get_job_logs_tails_to_default_5000():
|
|
_seed()
|
|
big = "x" * 8000 + "\nEND"
|
|
with patch("spark_executor.tools.logs.get_application_logs", return_value=big):
|
|
out = logs.get_job_logs("abc")
|
|
assert out.endswith("END")
|
|
assert len(out) == 5000
|
|
|
|
|
|
def test_get_job_logs_respects_custom_tail_chars():
|
|
_seed()
|
|
with patch(
|
|
"spark_executor.tools.logs.get_application_logs",
|
|
return_value="0123456789",
|
|
):
|
|
out = logs.get_job_logs("abc", tail_chars=3)
|
|
assert out == "789"
|
|
|
|
|
|
def test_get_job_logs_raises_for_unknown_job():
|
|
_seed()
|
|
import pytest
|
|
with pytest.raises(KeyError):
|
|
logs.get_job_logs("missing")
|