aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/test_file_utils.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-02-14 06:56:32 +0300
committerFrederick Muriuki Muriithi2022-02-17 06:37:30 +0300
commit74044f3c7985308b4996da3a52f91c5c20a19194 (patch)
treed86714b859b31cbbd1755522f8abd8eed16e321b /tests/unit/test_file_utils.py
parent67f517aa0f44f55dc691ffd791bf22ef7af0b02c (diff)
downloadgenenetwork3-74044f3c7985308b4996da3a52f91c5c20a19194.tar.gz
Use pytest's "mark" feature to categorise tests
Use pytest's `mark` feature to explicitly categorise the tests and run them per category
Diffstat (limited to 'tests/unit/test_file_utils.py')
-rw-r--r--tests/unit/test_file_utils.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/unit/test_file_utils.py b/tests/unit/test_file_utils.py
index 75be4f6..77fea88 100644
--- a/tests/unit/test_file_utils.py
+++ b/tests/unit/test_file_utils.py
@@ -5,6 +5,7 @@ import unittest
from dataclasses import dataclass
from typing import Callable
from unittest import mock
+import pytest
from gn3.fs_helpers import extract_uploaded_file
from gn3.fs_helpers import get_dir_hash
from gn3.fs_helpers import jsonfile_to_dict
@@ -21,17 +22,20 @@ class MockFile:
class TestFileUtils(unittest.TestCase):
"""Test cases for procedures defined in fs_helpers.py"""
+ @pytest.mark.unit_test
def test_get_dir_hash(self):
"""Test that a directory is hashed correctly"""
test_dir = os.path.join(os.path.dirname(__file__), "test_data")
self.assertEqual("3aeafab7d53b4f76d223366ae7ee9738",
get_dir_hash(test_dir))
+ @pytest.mark.unit_test
def test_get_dir_hash_non_existent_dir(self):
"""Test thata an error is raised when the dir does not exist"""
self.assertRaises(FileNotFoundError, get_dir_hash,
"/non-existent-file")
+ @pytest.mark.unit_test
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",
@@ -39,12 +43,14 @@ class TestFileUtils(unittest.TestCase):
self.assertEqual("Longer description",
jsonfile_to_dict(json_file).get("description"))
+ @pytest.mark.unit_test
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")
+ @pytest.mark.unit_test
@mock.patch("gn3.fs_helpers.tarfile")
@mock.patch("gn3.fs_helpers.secure_filename")
def test_extract_uploaded_file(self, mock_file, mock_tarfile):
@@ -65,6 +71,7 @@ non-existent"""
mock_file.assert_called_once_with("upload-data.tar.gz")
self.assertEqual(result, {"status": 0, "token": "abcdef-abcdef"})
+ @pytest.mark.unit_test
@mock.patch("gn3.fs_helpers.secure_filename")
def test_extract_uploaded_file_non_existent_gzip(self, mock_file):
"""Test that the right error message is returned when there is a problem
@@ -78,6 +85,7 @@ extracting the file"""
"error": "gzip failed to unpack file"
})
+ @pytest.mark.unit_test
def test_cache_ipfs_file_cache_hit(self):
"""Test that the correct file location is returned if there's a cache hit"""
# Create empty file
@@ -96,6 +104,7 @@ extracting the file"""
os.rmdir(test_dir)
self.assertEqual(file_loc, f"{test_dir}/genotype.txt")
+ @pytest.mark.unit_test
@mock.patch("gn3.fs_helpers.ipfshttpclient")
def test_cache_ipfs_file_cache_miss(self,
mock_ipfs):