From fcf6fbdaaae460bed917b73db033a3d063443389 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Fri, 12 Feb 2021 15:49:19 +0300 Subject: Add new procedure to return a python dict from a json file * gn3/file_utils.py (jsonfile_to_dict): New procedure * tests/unit/test_file_utils.py: New test-cases. --- tests/unit/test_file_utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'tests') diff --git a/tests/unit/test_file_utils.py b/tests/unit/test_file_utils.py index 231dcd0..a54680d 100644 --- a/tests/unit/test_file_utils.py +++ b/tests/unit/test_file_utils.py @@ -3,6 +3,7 @@ import os import unittest from unittest import mock +from gn3.file_utils import jsonfile_to_dict from gn3.file_utils import lookup_file from gn3.file_utils import get_dir_hash @@ -48,3 +49,17 @@ class TestFileUtils(unittest.TestCase): "GENENETWORK_FILES", "genotype_files", "genotype.txt") + + def test_jsonfile_to_dict(self): + """Test that a json file is parsed correctly""""" + json_file = os.path.join(os.path.dirname(__file__), + "test_data", "metadata.json") + self.assertEqual("Longer description", + jsonfile_to_dict(json_file).get("description")) + + def test_jsonfile_to_dict_nonexistent_file(self): + """Test that a ValueError is raised when the json file is +non-existent""" + self.assertRaises(FileNotFoundError, + jsonfile_to_dict, + "/non-existent-dir") -- cgit v1.2.3