Skip to content
Snippets Groups Projects
Commit 1b14ecea authored by Maeva Pourpoint's avatar Maeva Pourpoint
Browse files

Unit tests for Station level classes

parent 2eea166e
No related branches found
No related tags found
1 merge request!6Metadata station level
Pipeline #1377 passed with stage
in 5 minutes and 6 seconds
......@@ -10,7 +10,8 @@ from obspy import UTCDateTime
from pathlib import Path
from lemi2seed.lemi_data import LemiData
from lemi2seed.lemi_metadata import BaseSurvey, Survey, log_file_path
from lemi2seed.lemi_metadata import (BaseSurvey, Survey, BaseStation, Station_,
log_file_path)
OUTPUT_MSEED = Path(__file__).parent.joinpath('MSEED')
TEST_DIR = Path(__file__).parent.joinpath('test_data')
......@@ -171,3 +172,80 @@ class TestSurvey(unittest.TestCase):
"""Test basic functionality of validate_citation_dataset_doi."""
emails = 'm@passcal.edu, d@passcal.edu'
self.assertTrue(Survey.validate_project_lead_email(emails))
class TestBaseStation(unittest.TestCase):
"""Test suite for BaseStation data class."""
def setUp(self):
"""Set up test fixtures"""
data_input = 2201.77
min_elev, max_elev = [abs(data_input) * x for x in [0.99, 1.01]]
param = ("Station elevation", -500, 8500, min_elev, max_elev, 'm', '')
self.param = param
def test_validate_geographics_undefined(self):
"""Test basic functionality of validate_geographics."""
with self.assertLogs(logger, level='ERROR') as cmd:
BaseStation.validate_geographics(self.param, None)
msg = "Station elevation should be a float. "
self.assertEqual(cmd.output, [":".join(['ERROR', SCR_DIR, msg])])
def test_validate_geographics_erroneous_type(self):
"""Test basic functionality of validate_geographics."""
with self.assertLogs(logger, level='ERROR') as cmd:
BaseStation.validate_geographics(self.param, 'a')
msg = "Station elevation should be a float. "
self.assertEqual(cmd.output, [":".join(['ERROR', SCR_DIR, msg])])
def test_validate_geographics_not_in_range(self):
"""Test basic functionality of validate_geographics."""
geo, min_range, max_range, min_val, max_val, units, msg = self.param
with self.assertLogs(logger, level='ERROR') as cmd:
BaseStation.validate_geographics(self.param, 9000)
msg = ("Unexpected {0}! The {0} should be between {1}{3} and {2}{3}."
.format(geo, min_range, max_range, units))
self.assertEqual(cmd.output, [":".join(['ERROR', SCR_DIR, msg])])
def test_validate_geographics_do_not_match_logger_recorded_metadata(self):
"""Test basic functionality of validate_geographics."""
geo = 'Station elevation'
with self.assertLogs(logger, level='ERROR') as cmd:
BaseStation.validate_geographics(self.param, 2250)
msg = ("Unexpected {0}! Provided {0} should roughly match the {0} "
"recorded by the on-site GPS.".format(geo))
self.assertEqual(cmd.output, [":".join(['ERROR', SCR_DIR, msg])])
class TestStation_(unittest.TestCase):
"""Test suite for Station_ data class."""
def test_validate_archive_id_undefined(self):
"""Test basic functionality of validate_archive_id."""
with self.assertLogs(logger, level='ERROR') as cmd:
Station_.validate_archive_id(None)
msg = "The station name should be a string."
self.assertEqual(cmd.output, [":".join(['ERROR', SCR_DIR, msg])])
def test_validate_archive_id_erroneous_type(self):
"""Test basic functionality of validate_archive_id."""
with self.assertLogs(logger, level='ERROR') as cmd:
Station_.validate_archive_id(12)
msg = "The station name should be a string."
self.assertEqual(cmd.output, [":".join(['ERROR', SCR_DIR, msg])])
def test_validate_archive_id_invalid(self):
"""Test basic functionality of validate_archive_id."""
with self.assertLogs(logger, level='ERROR') as cmd:
Station_.validate_archive_id('KELLYA')
msg = ("The station name should be between three and five "
"alphanumeric character long.")
self.assertEqual(cmd.output, [":".join(['ERROR', SCR_DIR, msg])])
def test_validate_archive_id_valid(self):
"""Test basic functionality of validate_archive_id."""
self.assertTrue(Station_.validate_archive_id('KELLY'))
def test_validate_submitter_email_undefined(self):
"""Test basic functionality of validate_submitter_email."""
self.assertTrue(Station_.validate_submitter_email(None))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment