chore: add pytest dev-deps and pydantic models (Job, Connection, PendingSubmission)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
# coding=utf-8
|
||||
"""
|
||||
@Time :2026/6/24
|
||||
@Author :tao.chen
|
||||
"""
|
||||
@@ -0,0 +1,8 @@
|
||||
# coding=utf-8
|
||||
# Ensures the project root is on sys.path when running pytest from any cwd.
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
if str(ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(ROOT))
|
||||
@@ -0,0 +1,5 @@
|
||||
# coding=utf-8
|
||||
"""
|
||||
@Time :2026/6/24
|
||||
@Author :tao.chen
|
||||
"""
|
||||
@@ -0,0 +1,87 @@
|
||||
# coding=utf-8
|
||||
from datetime import datetime
|
||||
from spark_executor.models import Connection, Job, JobStatus, PendingSubmission, SubmitResult
|
||||
|
||||
|
||||
def test_job_roundtrip():
|
||||
job = Job(
|
||||
job_id="abc123",
|
||||
application_id="application_17400000001",
|
||||
script_path="/tmp/jobs/job_001.py",
|
||||
queue="default",
|
||||
submit_time=datetime(2026, 6, 24, 10, 0, 0),
|
||||
connection="prod-yarn",
|
||||
)
|
||||
dumped = job.model_dump()
|
||||
assert dumped["job_id"] == "abc123"
|
||||
assert dumped["application_id"] == "application_17400000001"
|
||||
assert dumped["connection"] == "prod-yarn"
|
||||
|
||||
|
||||
def test_job_status_default_raw():
|
||||
s = JobStatus(application_id="application_1", state="RUNNING")
|
||||
assert s.raw == ""
|
||||
|
||||
|
||||
def test_submit_result_tracking_url_optional():
|
||||
r = SubmitResult(job_id="j1", application_id="application_1", tracking_url=None)
|
||||
assert r.tracking_url is None
|
||||
|
||||
|
||||
def test_connection_defaults():
|
||||
c = Connection(name="prod", master="yarn")
|
||||
assert c.deploy_mode == "cluster"
|
||||
assert c.yarn_rm_url is None
|
||||
assert c.spark_conf == {}
|
||||
|
||||
|
||||
def test_connection_with_spark_conf():
|
||||
c = Connection(
|
||||
name="dev",
|
||||
master="spark://master:7077",
|
||||
deploy_mode="client",
|
||||
spark_conf={"spark.sql.shuffle.partitions": "200"},
|
||||
)
|
||||
assert c.spark_conf["spark.sql.shuffle.partitions"] == "200"
|
||||
|
||||
|
||||
def test_pending_submission_defaults_to_pending_status():
|
||||
p = PendingSubmission(
|
||||
pending_id="p_1",
|
||||
connection="prod",
|
||||
master="yarn",
|
||||
deploy_mode="cluster",
|
||||
script_path="/tmp/j.py",
|
||||
queue="default",
|
||||
executor_memory="4G",
|
||||
executor_cores=2,
|
||||
num_executors=2,
|
||||
spark_conf={},
|
||||
created_at=datetime(2026, 6, 24),
|
||||
)
|
||||
assert p.status == "PENDING"
|
||||
assert p.error is None
|
||||
assert p.job_id is None
|
||||
assert p.application_id is None
|
||||
|
||||
|
||||
def test_pending_submission_can_record_outcome():
|
||||
p = PendingSubmission(
|
||||
pending_id="p_2",
|
||||
connection="prod",
|
||||
master="yarn",
|
||||
deploy_mode="cluster",
|
||||
script_path="/tmp/j.py",
|
||||
queue="default",
|
||||
executor_memory="4G",
|
||||
executor_cores=2,
|
||||
num_executors=2,
|
||||
spark_conf={},
|
||||
created_at=datetime(2026, 6, 24),
|
||||
status="SUBMITTED",
|
||||
job_id="j_abc",
|
||||
application_id="application_17400000001",
|
||||
)
|
||||
assert p.status == "SUBMITTED"
|
||||
assert p.job_id == "j_abc"
|
||||
assert p.application_id == "application_17400000001"
|
||||
Reference in New Issue
Block a user