Skip to content

Commit

Permalink
move to utils, test, add node
Browse files Browse the repository at this point in the history
  • Loading branch information
hausman-gdit committed Jan 30, 2024
1 parent 76abd5d commit a4f670a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 2 additions & 7 deletions frontend/src/components/Main/AnalysisForm/AnalysisForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 (
<div>
Expand Down Expand Up @@ -73,7 +68,7 @@ class AnalysisForm extends Component {

{mainStore.errorMessage ? (
<div className="alert alert-danger">
{trim_error(mainStore.errorMessage)}
{ParseError(mainStore.errorMessage)}
</div>
) : null}
<div id="controlPanel" className="card bg-light">
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/utils/parsers.js
Original file line number Diff line number Diff line change
@@ -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();
};
20 changes: 20 additions & 0 deletions frontend/tests/utils/parsers.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});

0 comments on commit a4f670a

Please sign in to comment.