diff options
author | BonfaceKilz | 2021-03-03 10:58:55 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-03-08 21:09:58 +0300 |
commit | 9dff9888f81b7eec0e698466518ce4cb55b8bd8c (patch) | |
tree | bdd937882498267d1f51864af779a7d8294e014d | |
parent | 5000815bdcb5f85a2898831589849088e50b93f2 (diff) | |
download | genenetwork3-9dff9888f81b7eec0e698466518ce4cb55b8bd8c.tar.gz |
Delete "lookup_file" procedure
-rw-r--r-- | gn3/file_utils.py | 23 | ||||
-rw-r--r-- | tests/unit/test_file_utils.py | 29 |
2 files changed, 8 insertions, 44 deletions
diff --git a/gn3/file_utils.py b/gn3/file_utils.py index 16b2f94..ca80373 100644 --- a/gn3/file_utils.py +++ b/gn3/file_utils.py @@ -27,21 +27,14 @@ def get_dir_hash(directory: str) -> str: return md5hash.hexdigest() -def lookup_file(environ_var: str, - root_dir: str, - file_name: str) -> str: - """Look up FILE_NAME in the path defined by ENVIRON_VAR/ROOT_DIR/; If -ENVIRON_VAR/ROOT_DIR/FILE_NAME does not exist, raise an exception. -Otherwise return ENVIRON_VAR/ROOT_DIR/FILE_NAME. - - """ - _dir = APP_DEFAULTS.get(environ_var, - os.environ.get(environ_var)) - if _dir: - _file = os.path.join(_dir, root_dir, file_name) - if os.path.isfile(_file): - return _file - raise FileNotFoundError +def get_dir_hash(directory: str) -> str: + """Return the hash of a DIRECTORY""" + if not os.path.exists(directory): + raise FileNotFoundError + all_files = [os.path.join(root, names) + for root, _, files in os.walk(directory) + for names in sorted(files)] + return get_hash_of_files(all_files) def jsonfile_to_dict(json_file: str) -> Dict: diff --git a/tests/unit/test_file_utils.py b/tests/unit/test_file_utils.py index 7f4d83d..af86ba8 100644 --- a/tests/unit/test_file_utils.py +++ b/tests/unit/test_file_utils.py @@ -8,7 +8,6 @@ from unittest import mock from gn3.file_utils import extract_uploaded_file from gn3.file_utils import get_dir_hash from gn3.file_utils import jsonfile_to_dict -from gn3.file_utils import lookup_file @dataclass @@ -32,34 +31,6 @@ class TestFileUtils(unittest.TestCase): get_dir_hash, "/non-existent-file") - @mock.patch("os.path.isfile") - @mock.patch.dict(os.environ, {"GENENETWORK_FILES": "/tmp/"}) - def test_lookup_genotype_file_exists(self, mock_isfile): - """Test whether genotype file exists if file is present""" - mock_isfile.return_value = True - self.assertEqual(lookup_file("GENENETWORK_FILES", - "genotype_files", "genotype.txt"), - "/tmp/genotype_files/genotype.txt") - - @mock.patch("os.path.isfile") - @mock.patch.dict(os.environ, {"GENENETWORK_FILES": "/tmp"}) - def test_lookup_genotype_file_does_not_exist(self, mock_isfile): - """Test whether genotype file exists if file is absent""" - mock_isfile.return_value = False - self.assertRaises(FileNotFoundError, - lookup_file, - "GENENETWORK_FILES", - "genotype_files", - "genotype.txt") - - def test_lookup_genotype_file_env_does_not_exist(self): - """Test whether genotype file exists if GENENETWORK_FILES is absent""" - self.assertRaises(FileNotFoundError, - lookup_file, - "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__), |