diff --git a/gdcdictionary/__init__.py b/gdcdictionary/__init__.py index 565eaff2..0760ac0b 100644 --- a/gdcdictionary/__init__.py +++ b/gdcdictionary/__init__.py @@ -1,4 +1,5 @@ import os + from dictionaryutils import DataDictionary as GDCDictionary SCHEMA_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)), "schemas") diff --git a/gdcdictionary/schema_test.py b/gdcdictionary/schema_test.py index 74faffa1..bd25f776 100644 --- a/gdcdictionary/schema_test.py +++ b/gdcdictionary/schema_test.py @@ -8,8 +8,6 @@ """ -from __future__ import print_function - import argparse import copy import glob @@ -99,14 +97,14 @@ def assert_link_is_also_prop(link, properties, s_id): ), f"Entity '{s_id}' has '{link}' as a link but not property" for link in [ - schema_link ["name"] + schema_link["name"] for schema_link in schema_value["links"] if "name" in schema_link ]: assert_link_is_also_prop(link, schema_properties, s_id) for subgroup in [ schema_link["subgroup"] - for schema_link in schema_value["links"] + for schema_link in schema_value["links"] if "name" not in schema_link ]: for link in [ @@ -121,9 +119,9 @@ class SchemaTest(unittest.TestCase): def setUp(self): self.dictionary = gdcdictionary with open( - os.path.join(CUR_DIR, "schemas", "_definitions.yaml"), - "r", - encoding="utf8", + os.path.join(CUR_DIR, "schemas", "_definitions.yaml"), + "r", + encoding="utf8", ) as def_file: self.definitions = yaml.safe_load(def_file) @@ -135,7 +133,8 @@ def test_valid_files(self): """Test files that are expected to be valid""" for path in glob.glob(os.path.join(DATA_DIR, "valid", "*.json")): print(f"Validating {path}") - doc = json.load(open(path, "r", encoding="utf8")) + with open(path, "r", encoding="utf8") as json_file: + doc = json.load(json_file) print(doc) if isinstance(doc, dict): self.add_system_props(doc) @@ -151,7 +150,8 @@ def test_invalid_files(self): """Test files that are expected to be invalid""" for path in glob.glob(os.path.join(DATA_DIR, "invalid", "*.json")): print(f"Validating {path}") - doc = json.load(open(path, "r", encoding="utf8")) + with open(path, "r", encoding="utf8") as json_file: + doc = json.load(json_file) if isinstance(doc, dict): self.add_system_props(doc) with self.assertRaises(ValidationError):