Skip to content

Commit

Permalink
Merge pull request #7 from Open-EO/hotfix
Browse files Browse the repository at this point in the history
added code and test for checking file existence;
  • Loading branch information
lforesta authored Dec 5, 2019
2 parents fbc4dac + 39f0c1a commit d5db442
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/openeo_pg_parser_python/translate_process_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,12 @@ def link_nodes(graph):

def translate_graph(pg_filepath):
if isinstance(pg_filepath, str):
if os.path.isfile(pg_filepath):
pg_dict = load(open(pg_filepath))
pg_dict = load(open(pg_filepath))
elif isinstance(pg_filepath, dict):
pg_dict = pg_filepath
else:
raise ValueError("'pg_filepath must either be file path to a JSON file or a dictionary.'")

nodes = OrderedDict()
nodes, _, _, _ = walk_pg_graph(nodes, pg_dict)
# create graph object
Expand Down
21 changes: 21 additions & 0 deletions tests/test_translate_pg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import unittest
from openeo_pg_parser_python.translate_process_graph import translate_graph


class PGTranslateTester(unittest.TestCase):
""" Responsible for testing the translation of an openEO process graph. """

def setUp(self):
""" Specifies paths to the test data. """

self.pg_test_1_filepath = r"process_graphs/test_1.json"

def test_pg_not_found(self):
pg_filepath = r"process_graphs/does_not_exist.json"
try:
translate_graph(pg_filepath)
except FileNotFoundError:
assert True

if __name__ == '__main__':
unittest.main()

0 comments on commit d5db442

Please sign in to comment.