From b2fb7712e19d5da7dce4cd5c81e9472b232fefa7 Mon Sep 17 00:00:00 2001 From: Glenn Thomas Date: Wed, 3 Jun 2020 12:42:50 -0700 Subject: [PATCH 1/6] Add statement progress to the Statement model --- .gitignore | 2 ++ livy/models.py | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 73bd717..ae9cf78 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ dist/ livy.egg-info/ .pytest_cache/ .tox/ +.venv +.idea diff --git a/livy/models.py b/livy/models.py index 9bfdf80..5e247a1 100644 --- a/livy/models.py +++ b/livy/models.py @@ -112,6 +112,7 @@ class Statement: statement_id: int state: StatementState output: Optional[Output] + progress: Optional[float] @classmethod def from_json(cls, session_id: int, data: dict) -> "Statement": @@ -119,8 +120,11 @@ def from_json(cls, session_id: int, data: dict) -> "Statement": output = None else: output = Output.from_json(data["output"]) + + progress = data.get('progress') + return cls( - session_id, data["id"], StatementState(data["state"]), output + session_id, data["id"], StatementState(data["state"]), output, progress ) From e9c5e6fa681f0cec54aa5c2638649238b6b3303e Mon Sep 17 00:00:00 2001 From: Glenn Thomas Date: Thu, 4 Jun 2020 11:49:53 -0700 Subject: [PATCH 2/6] add tests --- tests/test_models.py | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index 5111fda..457007f 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -58,10 +58,10 @@ def test_session_from_json(): def test_statement_from_json_no_output(): session_id = 5 - statement_json = {"id": 10, "state": "running", "output": None} + statement_json = {"id": 10, "state": "running", "output": None, "progress": 0.0} expected = Statement( - session_id, statement_id=10, state=StatementState.RUNNING, output=None + session_id, statement_id=10, state=StatementState.RUNNING, output=None, progress=0.0 ) assert Statement.from_json(session_id, statement_json) == expected @@ -72,19 +72,48 @@ def test_statement_from_json_with_output(mocker): mocker.patch.object(Output, "from_json") session_id = 5 - statement_json = {"id": 10, "state": "running", "output": "dummy output"} + statement_json = {"id": 10, "state": "running", "output": "dummy output", "progress": 0.5} expected = Statement( session_id, statement_id=10, state=StatementState.RUNNING, output=Output.from_json.return_value, + progress=0.5 ) assert Statement.from_json(session_id, statement_json) == expected Output.from_json.assert_called_once_with("dummy output") +def test_statement_from_json_no_progress(mocker): + + mocker.patch.object(Output, "from_json") + + session_id = 5 + statement_json = {"id": 10, "state": "running", "output": "dummy output", "progress": None} + + expected = Statement( + session_id, statement_id=10, state=StatementState.RUNNING, output=Output.from_json.return_value, progress=None + ) + + assert Statement.from_json(session_id, statement_json) == expected + + +def test_statement_from_json_with_progress(mocker): + + mocker.patch.object(Output, "from_json") + + session_id = 5 + statement_json = {"id": 10, "state": "running", "output": "dummy output", "progress": 0.5} + + expected = Statement( + session_id, statement_id=10, state=StatementState.RUNNING, output=Output.from_json.return_value, progress=0.5 + ) + + assert Statement.from_json(session_id, statement_json) == expected + + def test_output_textdata_from_json(): output_json = {"status": "ok", "data": {"text/plain": "some output"}} From e5a70f7cca3d238b5800faa903fa240fc61fa66b Mon Sep 17 00:00:00 2001 From: Glenn Thomas Date: Thu, 4 Jun 2020 12:02:41 -0700 Subject: [PATCH 3/6] fixes --- livy/models.py | 8 +++++--- tests/test_models.py | 48 ++++++++++++++++++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/livy/models.py b/livy/models.py index 5e247a1..72cf5b9 100644 --- a/livy/models.py +++ b/livy/models.py @@ -121,10 +121,12 @@ def from_json(cls, session_id: int, data: dict) -> "Statement": else: output = Output.from_json(data["output"]) - progress = data.get('progress') - return cls( - session_id, data["id"], StatementState(data["state"]), output, progress + session_id, + data["id"], + StatementState(data["state"]), + output, + data.get("progress"), ) diff --git a/tests/test_models.py b/tests/test_models.py index 457007f..232d7a4 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -58,10 +58,19 @@ def test_session_from_json(): def test_statement_from_json_no_output(): session_id = 5 - statement_json = {"id": 10, "state": "running", "output": None, "progress": 0.0} + statement_json = { + "id": 10, + "state": "running", + "output": None, + "progress": 0.0, + } expected = Statement( - session_id, statement_id=10, state=StatementState.RUNNING, output=None, progress=0.0 + session_id, + statement_id=10, + state=StatementState.RUNNING, + output=None, + progress=0.0, ) assert Statement.from_json(session_id, statement_json) == expected @@ -72,14 +81,19 @@ def test_statement_from_json_with_output(mocker): mocker.patch.object(Output, "from_json") session_id = 5 - statement_json = {"id": 10, "state": "running", "output": "dummy output", "progress": 0.5} + statement_json = { + "id": 10, + "state": "running", + "output": "dummy output", + "progress": 0.5, + } expected = Statement( session_id, statement_id=10, state=StatementState.RUNNING, output=Output.from_json.return_value, - progress=0.5 + progress=0.5, ) assert Statement.from_json(session_id, statement_json) == expected @@ -91,10 +105,19 @@ def test_statement_from_json_no_progress(mocker): mocker.patch.object(Output, "from_json") session_id = 5 - statement_json = {"id": 10, "state": "running", "output": "dummy output", "progress": None} + statement_json = { + "id": 10, + "state": "running", + "output": "dummy output", + "progress": None, + } expected = Statement( - session_id, statement_id=10, state=StatementState.RUNNING, output=Output.from_json.return_value, progress=None + session_id, + statement_id=10, + state=StatementState.RUNNING, + output=Output.from_json.return_value, + progress=None, ) assert Statement.from_json(session_id, statement_json) == expected @@ -105,10 +128,19 @@ def test_statement_from_json_with_progress(mocker): mocker.patch.object(Output, "from_json") session_id = 5 - statement_json = {"id": 10, "state": "running", "output": "dummy output", "progress": 0.5} + statement_json = { + "id": 10, + "state": "running", + "output": "dummy output", + "progress": 0.5, + } expected = Statement( - session_id, statement_id=10, state=StatementState.RUNNING, output=Output.from_json.return_value, progress=0.5 + session_id, + statement_id=10, + state=StatementState.RUNNING, + output=Output.from_json.return_value, + progress=0.5, ) assert Statement.from_json(session_id, statement_json) == expected From 5a033be0e2618f6699b184737ba38c364d56c39f Mon Sep 17 00:00:00 2001 From: Glenn Thomas Date: Thu, 4 Jun 2020 12:04:42 -0700 Subject: [PATCH 4/6] Add statement progress to the Statement model --- .gitignore | 2 ++ livy/models.py | 8 +++++- tests/test_models.py | 67 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 73 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 73bd717..ae9cf78 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ dist/ livy.egg-info/ .pytest_cache/ .tox/ +.venv +.idea diff --git a/livy/models.py b/livy/models.py index 9bfdf80..72cf5b9 100644 --- a/livy/models.py +++ b/livy/models.py @@ -112,6 +112,7 @@ class Statement: statement_id: int state: StatementState output: Optional[Output] + progress: Optional[float] @classmethod def from_json(cls, session_id: int, data: dict) -> "Statement": @@ -119,8 +120,13 @@ def from_json(cls, session_id: int, data: dict) -> "Statement": output = None else: output = Output.from_json(data["output"]) + return cls( - session_id, data["id"], StatementState(data["state"]), output + session_id, + data["id"], + StatementState(data["state"]), + output, + data.get("progress"), ) diff --git a/tests/test_models.py b/tests/test_models.py index 5111fda..232d7a4 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -58,10 +58,19 @@ def test_session_from_json(): def test_statement_from_json_no_output(): session_id = 5 - statement_json = {"id": 10, "state": "running", "output": None} + statement_json = { + "id": 10, + "state": "running", + "output": None, + "progress": 0.0, + } expected = Statement( - session_id, statement_id=10, state=StatementState.RUNNING, output=None + session_id, + statement_id=10, + state=StatementState.RUNNING, + output=None, + progress=0.0, ) assert Statement.from_json(session_id, statement_json) == expected @@ -72,19 +81,71 @@ def test_statement_from_json_with_output(mocker): mocker.patch.object(Output, "from_json") session_id = 5 - statement_json = {"id": 10, "state": "running", "output": "dummy output"} + statement_json = { + "id": 10, + "state": "running", + "output": "dummy output", + "progress": 0.5, + } expected = Statement( session_id, statement_id=10, state=StatementState.RUNNING, output=Output.from_json.return_value, + progress=0.5, ) assert Statement.from_json(session_id, statement_json) == expected Output.from_json.assert_called_once_with("dummy output") +def test_statement_from_json_no_progress(mocker): + + mocker.patch.object(Output, "from_json") + + session_id = 5 + statement_json = { + "id": 10, + "state": "running", + "output": "dummy output", + "progress": None, + } + + expected = Statement( + session_id, + statement_id=10, + state=StatementState.RUNNING, + output=Output.from_json.return_value, + progress=None, + ) + + assert Statement.from_json(session_id, statement_json) == expected + + +def test_statement_from_json_with_progress(mocker): + + mocker.patch.object(Output, "from_json") + + session_id = 5 + statement_json = { + "id": 10, + "state": "running", + "output": "dummy output", + "progress": 0.5, + } + + expected = Statement( + session_id, + statement_id=10, + state=StatementState.RUNNING, + output=Output.from_json.return_value, + progress=0.5, + ) + + assert Statement.from_json(session_id, statement_json) == expected + + def test_output_textdata_from_json(): output_json = {"status": "ok", "data": {"text/plain": "some output"}} From ff4e0d1e5a4403247efc809f3ca1d9cc954bd8b8 Mon Sep 17 00:00:00 2001 From: Glenn Thomas Date: Fri, 12 Jun 2020 11:11:39 -0700 Subject: [PATCH 5/6] remove .gitignore changes --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ae9cf78..f32238b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,4 @@ build/ dist/ livy.egg-info/ .pytest_cache/ -.tox/ -.venv -.idea +.tox/ \ No newline at end of file From 44cbcaf3fe4eb751ca2b3ec60c42c652a49a1b4a Mon Sep 17 00:00:00 2001 From: Glenn Thomas Date: Fri, 12 Jun 2020 11:12:22 -0700 Subject: [PATCH 6/6] typo --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f32238b..73bd717 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ build/ dist/ livy.egg-info/ .pytest_cache/ -.tox/ \ No newline at end of file +.tox/