Skip to content
Snippets Groups Projects
Commit ed69faa5 authored by Stefano Borini's avatar Stefano Borini
Browse files

Flake8

parent dbf85720
No related branches found
No related tags found
1 merge request!29Extract io layer to writer/reader class
...@@ -3,6 +3,8 @@ import subprocess ...@@ -3,6 +3,8 @@ import subprocess
import os import os
from contextlib import contextmanager from contextlib import contextmanager
from force_bdss.tests import fixtures
@contextmanager @contextmanager
def cd(dir): def cd(dir):
...@@ -22,17 +24,17 @@ def fixture_dir(): ...@@ -22,17 +24,17 @@ def fixture_dir():
class TestExecution(unittest.TestCase): class TestExecution(unittest.TestCase):
def test_plain_invocation_mco(self): def test_plain_invocation_mco(self):
with cd(fixture_dir()): with cd(fixtures.dirpath()):
out = subprocess.check_call(["force_bdss", "test_csv.json"]) out = subprocess.check_call(["force_bdss", "test_csv.json"])
self.assertEqual(out, 0) self.assertEqual(out, 0)
def test_unsupported_file_input(self): def test_unsupported_file_input(self):
with cd(fixture_dir()): with cd(fixtures.dirpath()):
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): def test_corrupted_file_input(self):
with cd(fixture_dir()): with cd(fixtures.dirpath()):
with self.assertRaises(subprocess.CalledProcessError): with self.assertRaises(subprocess.CalledProcessError):
subprocess.check_call(["force_bdss", subprocess.check_call(["force_bdss",
"test_csv_corrupted.json"]) "test_csv_corrupted.json"])
......
...@@ -47,14 +47,15 @@ class WorkflowReader(HasStrictTraits): ...@@ -47,14 +47,15 @@ class WorkflowReader(HasStrictTraits):
wf = Workflow() wf = Workflow()
try: try:
workflow_data = json_data["workflow"] wf_data = json_data["workflow"]
wf.multi_criteria_optimizer = self._extract_mco(workflow_data) wf.multi_criteria_optimizer = self._extract_mco(wf_data)
wf.data_sources[:] = self._extract_data_sources(workflow_data) wf.data_sources[:] = self._extract_data_sources(wf_data)
wf.kpi_calculators[:] = self._extract_kpi_calculators(workflow_data) wf.kpi_calculators[:] = self._extract_kpi_calculators(wf_data)
except KeyError as e: except KeyError as e:
logging.exception("Could not read file") logging.exception("Could not read file")
raise InvalidFileException("Could not read file. " raise InvalidFileException("Could not read file. "
"Unable to find key {}".format(e)) "Unable to find key {}".format(e))
return wf
def _extract_mco(self, json_data): def _extract_mco(self, json_data):
registry = self.bundle_registry registry = self.bundle_registry
......
...@@ -2,4 +2,8 @@ from os.path import join, dirname, abspath ...@@ -2,4 +2,8 @@ from os.path import join, dirname, abspath
def get(filename): def get(filename):
return join(dirname(abspath(__file__)), filename) return join(dirpath(), filename)
def dirpath():
return dirname(abspath(__file__))
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