Skip to content

Commit

Permalink
CU-862hyd5wx Unify rosalind/vocab downloading in tests, identify and …
Browse files Browse the repository at this point in the history
…fail meaningfully in case of 503
  • Loading branch information
mart-r committed Oct 12, 2023
1 parent b17be8f commit 7950c57
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
11 changes: 5 additions & 6 deletions tests/archive_tests/test_ner_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from medcat.linking.context_based_linker import Linker
from medcat.config import Config

from ..helper import VocabDownloader


class NerArchiveTests(unittest.TestCase):

Expand All @@ -35,12 +37,9 @@ def setUp(self) -> None:
# Check
#assert cdb.cui2names == {'S-229004': {'movar', 'movarvirus', 'movarviruses'}, 'S-229005': {'cdb'}}

self.vocab_path = "./tmp_vocab.dat"
if not os.path.exists(self.vocab_path):
import requests
tmp = requests.get("https://medcat.rosalind.kcl.ac.uk/media/vocab.dat")
with open(self.vocab_path, 'wb') as f:
f.write(tmp.content)
downloader = VocabDownloader()
self.vocab_path = downloader.vocab_path
downloader.check_or_download()

vocab = Vocab.load(self.vocab_path)
# Make the pipeline
Expand Down
12 changes: 6 additions & 6 deletions tests/medmentions/make_cdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import logging
import os

from ..helper import VocabDownloader


config = Config()
config.general['log_level'] = logging.INFO
config.general['spacy_model'] = 'en_core_sci_lg'
Expand All @@ -21,12 +24,9 @@
from medcat.cdb import CDB
from medcat.cat import CAT

vocab_path = "./tmp_vocab.dat"
if not os.path.exists(vocab_path):
import requests
tmp = requests.get("https://s3-eu-west-1.amazonaws.com/zkcl/vocab.dat")
with open(vocab_path, 'wb') as f:
f.write(tmp.content)
downloader = VocabDownloader()
vocab_path = downloader.vocab_path
downloader.check_or_download()

config = Config()
cdb = CDB.load("./tmp_cdb.dat", config=config)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_ner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from medcat.config import Config
from medcat.cdb import CDB

from .helper import VocabDownloader


class A_NERTests(unittest.TestCase):
@classmethod
Expand All @@ -25,11 +27,9 @@ def setUpClass(cls):
cls.cdb = CDB(config=cls.config)

print("Set up Vocab")
vocab_path = "./tmp_vocab.dat"
if not os.path.exists(vocab_path):
tmp = requests.get("https://medcat.rosalind.kcl.ac.uk/media/vocab.dat")
with open(vocab_path, 'wb') as f:
f.write(tmp.content)
downloader = VocabDownloader()
vocab_path = downloader.vocab_path
downloader.check_or_download()

cls.vocab = Vocab.load(vocab_path)

Expand Down
10 changes: 5 additions & 5 deletions tests/test_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from transformers import AutoTokenizer


from .helper import VocabDownloader


class PipeTests(unittest.TestCase):

Expand All @@ -30,11 +32,9 @@ def setUpClass(cls) -> None:
cls.config.linking['disamb_length_limit'] = 2
cls.cdb = CDB(config=cls.config)

vocab_path = "./tmp_vocab.dat"
if not os.path.exists(vocab_path):
tmp = requests.get("https://medcat.rosalind.kcl.ac.uk/media/vocab.dat")
with open(vocab_path, 'wb') as f:
f.write(tmp.content)
downloader = VocabDownloader()
vocab_path = downloader.vocab_path
downloader.check_or_download()

cls.vocab = Vocab.load(vocab_path)
cls.spell_checker = BasicSpellChecker(cdb_vocab=cls.cdb.vocab, config=cls.config, data_vocab=cls.vocab)
Expand Down

0 comments on commit 7950c57

Please sign in to comment.