|
a |
|
b/test/python/util.py |
|
|
1 |
import unittest |
|
|
2 |
import sys |
|
|
3 |
from zensols.cli import CliHarness, ApplicationFailure |
|
|
4 |
from zensols.config import ConfigFactory |
|
|
5 |
from zensols.mednlp import Application, ApplicationFactory, surpress_warnings |
|
|
6 |
|
|
|
7 |
|
|
|
8 |
class TestBase(unittest.TestCase): |
|
|
9 |
def setUp(self): |
|
|
10 |
import warnings |
|
|
11 |
warnings.simplefilter("ignore", ResourceWarning) |
|
|
12 |
surpress_warnings() |
|
|
13 |
self.text_1 = 'He was diagnosed with kidney failure and heart disease.' |
|
|
14 |
self.text_2 = 'He loved to smoke but Marlboro cigarettes gave John Smith lung cancer while he was in Chicago.' |
|
|
15 |
self.maxDiff = sys.maxsize |
|
|
16 |
|
|
|
17 |
def _get_doc_parser(self, config: str = 'default', section: str = None): |
|
|
18 |
harness: CliHarness = ApplicationFactory.create_harness() |
|
|
19 |
args: str = f'--config test-resources/config/{config}.conf --level=err' |
|
|
20 |
if section is None: |
|
|
21 |
app: Application = harness.get_instance(f'show _ {args}') |
|
|
22 |
if isinstance(app, ApplicationFailure): |
|
|
23 |
raise app.exception |
|
|
24 |
return app.doc_parser |
|
|
25 |
else: |
|
|
26 |
harness: CliHarness = ApplicationFactory.create_harness() |
|
|
27 |
fac: ConfigFactory = harness.get_config_factory(args) |
|
|
28 |
return fac(section) |