diff options
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/test_file_utils.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/unit/test_file_utils.py b/tests/unit/test_file_utils.py index e6109bb..231dcd0 100644 --- a/tests/unit/test_file_utils.py +++ b/tests/unit/test_file_utils.py @@ -2,6 +2,8 @@ import os import unittest +from unittest import mock +from gn3.file_utils import lookup_file from gn3.file_utils import get_dir_hash @@ -18,3 +20,31 @@ class TestFileUtils(unittest.TestCase): self.assertRaises(FileNotFoundError, 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") |