From a4f670a7639f79fa85d050ab6cea027f30a4f633 Mon Sep 17 00:00:00 2001 From: hausman-gdit Date: Tue, 30 Jan 2024 14:38:49 -0500 Subject: [PATCH] move to utils, test, add node --- frontend/package.json | 2 +- .../Main/AnalysisForm/AnalysisForm.js | 9 ++------- frontend/src/utils/parsers.js | 6 ++++++ frontend/tests/utils/parsers.test.js | 20 +++++++++++++++++++ 4 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 frontend/src/utils/parsers.js create mode 100644 frontend/tests/utils/parsers.test.js diff --git a/frontend/package.json b/frontend/package.json index 5869324f..916c0fd2 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -9,7 +9,7 @@ "start": "node devServer.js", "lint": "eslint --cache .", "format": "eslint --cache --fix .", - "test": "./node_modules/mochapack/bin/mochapack \"tests/**/*.js\"", + "test": "node ./node_modules/mochapack/bin/mochapack \"tests/**/*.js\"", "test-windows": "node_modules\\.bin\\mochapack \"tests/**/*.js\"" }, "repository": { diff --git a/frontend/src/components/Main/AnalysisForm/AnalysisForm.js b/frontend/src/components/Main/AnalysisForm/AnalysisForm.js index 4b62da81..67cf4152 100644 --- a/frontend/src/components/Main/AnalysisForm/AnalysisForm.js +++ b/frontend/src/components/Main/AnalysisForm/AnalysisForm.js @@ -2,6 +2,7 @@ import {inject, observer} from "mobx-react"; import PropTypes from "prop-types"; import React, {Component} from "react"; +import {ParseError} from "../../../utils/parsers"; import Button from "../../common/Button"; import Icon from "../../common/Icon"; import SelectInput from "../../common/SelectInput"; @@ -34,12 +35,6 @@ RunChecklist.propTypes = { class AnalysisForm extends Component { render() { const {mainStore} = this.props; - const trim_error = function(error) { - console.log(error[0]); - var t_2 = error[0].slice(error[0].indexOf("Error")); - var t_3 = t_2.slice(t_2.indexOf(")") + 2); - return t_3; - }; return (
@@ -73,7 +68,7 @@ class AnalysisForm extends Component { {mainStore.errorMessage ? (
- {trim_error(mainStore.errorMessage)} + {ParseError(mainStore.errorMessage)}
) : null}
diff --git a/frontend/src/utils/parsers.js b/frontend/src/utils/parsers.js new file mode 100644 index 00000000..ff7028c7 --- /dev/null +++ b/frontend/src/utils/parsers.js @@ -0,0 +1,6 @@ +export const ParseError = function(error) { + let _error = error[0]; + console.error(_error); + _error = _error.match(/(?<=ValueError:\s).*/)[0]; + return _error.toString(); +}; diff --git a/frontend/tests/utils/parsers.test.js b/frontend/tests/utils/parsers.test.js new file mode 100644 index 00000000..e669e192 --- /dev/null +++ b/frontend/tests/utils/parsers.test.js @@ -0,0 +1,20 @@ +import {ParseError} from "../../src/utils/parsers"; +import assert from "../helpers"; + +const check = function(func, input, output) { + assert.equal(func(input), output); +}; + +const error = [ + 'Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/bmds_server/analysis/models.py", line 237, in try_run_session return AnalysisSession.run(inputs, dataset_index, option_index) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/bmds_server/analysis/executor.py", line 134, in run session = cls.create(inputs, dataset_index, option_index) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/bmds_server/analysis/executor.py", line 140, in create dataset = build_dataset(inputs["datasets"][dataset_index]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/bmds_server/analysis/transforms.py", line 93, in build_dataset return schema.model_validate(dataset).deserialize() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/bmds/datasets/continuous.py", line 247, in deserialize ds = ContinuousDataset( ^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/bmds/datasets/continuous.py", line 104, in _init_ self._sort_by_dose_group() File "/usr/local/lib/python3.11/site-packages/bmds/datasets/continuous.py", line 116, in _sort_by_dose_group self._validate() File "/usr/local/lib/python3.11/site-packages/bmds/datasets/continuous.py", line 108, in _validate self._validate_summary_data() File "/usr/local/lib/python3.11/site-packages/bmds/datasets/continuous.py", line 23, in _validate_summary_data raise ValueError("Doses are not unique") ValueError: Doses are not unique', + "", +]; +const result = "Doses are not unique"; + +describe("Parsing", function() { + describe("ParseError", function() { + it("parses out the correct error message", function() { + check(ParseError, error, result); + }); + }); +});