Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion medcat-v2/medcat/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,9 @@ def load_model_pack(cls, model_pack_path: str,
TOKENIZER_PREFIX,
# components will be loaded semi-manually
# within the creation of pipe
COMPONENTS_FOLDER},
COMPONENTS_FOLDER,
# ignore hidden files/folders
'.'},
config_dict=config_dict,
addon_config_dict=addon_config_dict)
# NOTE: deserialising of components that need serialised
Expand Down
33 changes: 30 additions & 3 deletions medcat-v2/tests/test_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import unittest
import tempfile
import pickle
import shutil

from . import EXAMPLE_MODEL_PACK_ZIP
from . import V1_MODEL_PACK_PATH, UNPACKED_V1_MODEL_PACK_PATH
Expand All @@ -30,18 +31,19 @@

orig_init = cat.CAT.__init__

expected_model_pack_path = EXAMPLE_MODEL_PACK_ZIP.replace(".zip", "")


class ModelLoadTests(unittest.TestCase):

def assert_has_model_name(self, func):
expected_model_packl_name = EXAMPLE_MODEL_PACK_ZIP.replace(".zip", "")

def wrapper(*args, **kwargs):
if 'model_load_path' in kwargs:
self.assertEqual(kwargs['model_load_path'],
expected_model_packl_name)
expected_model_pack_path)
else:
self.assertEqual(args[-1], expected_model_packl_name)
self.assertEqual(args[-1], expected_model_pack_path)
return func(*args, **kwargs)
return wrapper

Expand All @@ -61,6 +63,31 @@ def test_can_load_CDB_from_model_pack(self):
self.assertIsInstance(cdb, CDB)


class ModelLoadIWithHiddenFilesTests(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls._temp_dir = tempfile.TemporaryDirectory()
cls.model_path = os.path.join(cls._temp_dir.name, "model")
shutil.copytree(expected_model_pack_path, cls.model_path)
# add file
file_path = os.path.join(cls.model_path, '.some_file.txt')
with open(file_path, 'w') as f:
f.write("Nothing")
# add folder
folder_path = os.path.join(cls.model_path, '.some_folder')
os.mkdir(folder_path)

@classmethod
def tearDownClass(cls):
cls._temp_dir.cleanup()

def test_can_load_with_add_hidden_files_and_folders(self):
# try load
inst = cat.CAT.load_model_pack(self.model_path)
self.assertIsInstance(inst, cat.CAT)


class TrainedModelTests(unittest.TestCase):
TRAINED_MODEL_PATH = EXAMPLE_MODEL_PACK_ZIP

Expand Down
Loading