Skip to content
Snippets Groups Projects
Commit 959953b4 authored by martinRenou's avatar martinRenou
Browse files

Raise exception when version not specified

parent 963115b1
No related branches found
No related tags found
1 merge request!27Add file version handling for workflow file.
This commit is part of merge request !27. Comments created here will be created in the context of that merge request.
{
"multi_criteria_optimizer": {
"id": "force.bdss.bundles.enthought.dakota",
"model_data": {
"value_types": ["DUMMY"]
}
},
"data_sources": [
{
"id": "force.bdss.bundles.enthought.csv_extractor",
"model_data": {
"filename": "foo.csv",
"row": 3,
"column": 5,
"cuba_type": "PRESSURE"
}
},
{
"id": "force.bdss.bundles.enthought.csv_extractor",
"model_data": {
"filename": "foo.csv",
"row": 3,
"column": 5,
"cuba_type": "PRESSURE"
}
}
],
"kpi_calculators": [
{
"id": "force.bdss.bundles.enthought.kpi_adder",
"model_data": {
"cuba_type_in": "PRESSURE",
"cuba_type_out": "TOTAL_PRESSURE"
}
}
]
}
...@@ -31,6 +31,12 @@ class TestExecution(unittest.TestCase): ...@@ -31,6 +31,12 @@ class TestExecution(unittest.TestCase):
with self.assertRaises(subprocess.CalledProcessError): with self.assertRaises(subprocess.CalledProcessError):
subprocess.check_call(["force_bdss", "test_csv_v2.json"]) subprocess.check_call(["force_bdss", "test_csv_v2.json"])
def test_corrupted_file_input(self):
with cd(fixture_dir()):
with self.assertRaises(subprocess.CalledProcessError):
subprocess.check_call(["force_bdss",
"test_csv_corrupted.json"])
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -3,7 +3,8 @@ import sys ...@@ -3,7 +3,8 @@ import sys
from traits.api import on_trait_change from traits.api import on_trait_change
from force_bdss.base_core_driver import BaseCoreDriver from force_bdss.base_core_driver import BaseCoreDriver
from force_bdss.workspecs.workflow import InvalidVersionException from force_bdss.workspecs.workflow import (InvalidVersionException,
CorruptedInputFile)
class CoreMCODriver(BaseCoreDriver): class CoreMCODriver(BaseCoreDriver):
...@@ -18,6 +19,9 @@ class CoreMCODriver(BaseCoreDriver): ...@@ -18,6 +19,9 @@ class CoreMCODriver(BaseCoreDriver):
except InvalidVersionException as e: except InvalidVersionException as e:
print e.message print e.message
sys.exit(1) sys.exit(1)
except CorruptedInputFile as e:
print e.message
sys.exit(1)
mco_data = workflow.multi_criteria_optimizer mco_data = workflow.multi_criteria_optimizer
mco_bundle = self.bundle_registry.mco_bundle_by_id(mco_data.id) mco_bundle = self.bundle_registry.mco_bundle_by_id(mco_data.id)
......
...@@ -11,6 +11,10 @@ class InvalidVersionException(Exception): ...@@ -11,6 +11,10 @@ class InvalidVersionException(Exception):
pass pass
class CorruptedInputFile(Exception):
pass
class Workflow(HasStrictTraits): class Workflow(HasStrictTraits):
name = String() name = String()
multi_criteria_optimizer = Instance(MultiCriteriaOptimizer) multi_criteria_optimizer = Instance(MultiCriteriaOptimizer)
...@@ -19,7 +23,13 @@ class Workflow(HasStrictTraits): ...@@ -19,7 +23,13 @@ class Workflow(HasStrictTraits):
@classmethod @classmethod
def from_json(cls, json_data): def from_json(cls, json_data):
if json_data["version"] not in SUPPORTED_FILE_VERSIONS: try:
version = json_data["version"]
except KeyError:
raise CorruptedInputFile("Corrupted input file, no version"
" specified")
if version not in SUPPORTED_FILE_VERSIONS:
raise InvalidVersionException( raise InvalidVersionException(
"File version {} not supported".format(json_data["version"])) "File version {} not supported".format(json_data["version"]))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment