Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding first salinity tests #44

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
45 changes: 44 additions & 1 deletion tests/inputs/test_sample_info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,47 @@ tests:
id: TEST:captest1
text: bill clinton
output:
text: Bill Clinton
text: Bill Clinton
- description: missing space 1
sample:
id: TEST:missing_space1
text: 400g/L
output:
text: 400 g/L
- description: missing space 2
sample:
id: TEST:missing_space2
text: 1%
output:
text: 1 %
- description: categorical vs numerical
sample:
id: TEST:cat_vs_num
text: Halophile
output:
text: NaN
- description: capital units
sample:
id: TEST:cap_units
text: 0.2 psu
output:
text: 0.2 PSU
- description: capital units and space
sample:
id: TEST:cap_units_and_space
text: 0.2psu
output:
text: 0.2 PSU
- description: plus minus error
sample:
id: TEST:plus_min_error
text: 17.3 +/- 2.0 PPT
output:
text: NaN
- description: with unit description
sample:
id: TEST:with_unit_descr
text: 40 PSU (practical salinity units)
output:
text: 40 PSU

35 changes: 35 additions & 0 deletions tests/test_salinity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
import os
import unittest

import yaml

from sample_annotator import capitalizer
# MODEL_DIR, INPUT_DIR, OUTPUT_DIR
from tests import INPUT_DIR

"""Test the ability to capitalize a text slot."""

"""Run as follows to get see test-time printouts:"""

"""python -m pytest -sv tests/test_salinity.py"""

# INPUT_DIR comes from __init__.py
PWD = os.path.dirname(os.path.realpath(__file__))
TEST_DATA = os.path.join(INPUT_DIR, 'test_sample_info.yaml')


class TestSalinity(unittest.TestCase):
"""salinity unit tests."""

def test_missing_space1(self):
with open(TEST_DATA) as stream:
test_obj = yaml.load(stream, Loader=yaml.FullLoader)
for t in test_obj.get('tests'):
desc = t.get('description', None)
# pdb.set_trace()
if desc == 'missing space 1':
current_input = t['sample']['text']
processed_input = capitalizer.capitalizer(current_input)
expected_output = t['output']['text']
assert processed_input == expected_output
40 changes: 40 additions & 0 deletions tests/test_salinity_annotate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
import os
import yaml
import unittest
from sample_annotator.measurements.measurements import MeasurementEngine
from sample_annotator.report_model import AnnotationReport

# MODEL_DIR, INPUT_DIR, OUTPUT_DIR
from tests import INPUT_DIR

"""Test the ability to capitalize a text slot."""

"""Run as follows to get see test-time printouts:"""

"""python -m pytest -sv tests/test_salinity.py"""

# INPUT_DIR comes from __init__.py
PWD = os.path.dirname(os.path.realpath(__file__))
TEST_DATA = os.path.join(INPUT_DIR, 'test_sample_info.yaml')


class TestSalinityAnnotate(unittest.TestCase):
"""salinity unit tests."""

report = AnnotationReport(messages=[])
m = MeasurementEngine()

with open(TEST_DATA) as stream:
test_obj = yaml.load(stream, Loader=yaml.FullLoader)
for t in test_obj.get('tests'):
desc = t.get('description', None)
# pdb.set_trace()
if desc == 'missing space 1':
current_input = t['sample']['text']

processed_input = m.repair(current_input, report=report)
print(processed_input)

expected_output = t['output']['text']
assert processed_input == expected_output