Skip to content

Commit

Permalink
add tests after BasicSyntoolConverter update
Browse files Browse the repository at this point in the history
  • Loading branch information
aperrin66 committed Mar 6, 2024
1 parent fa8561b commit 4e5ce6c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/converters/test_syntool_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ def test_find_ingest_config_error(self):
with self.assertRaises(converters_base.ConversionError):
converter.find_ingest_config('foo')

def test_find_ingest_config_type_error(self):
"""An exception must be raised if ingest_parameter_files is
not a string or ParameterSelector or a list of these
"""
with self.assertRaises(converters_base.ConversionError):
syntool_converter.BasicSyntoolConverter(
converter_type='foo',
ingest_parameter_files=1).find_ingest_config('foo')
with self.assertRaises(converters_base.ConversionError):
syntool_converter.BasicSyntoolConverter(
converter_type='foo',
ingest_parameter_files=[1, 2]).find_ingest_config('foo')

def test_parse_converter_options(self):
"""Test parsing and merging converter options"""
converter = syntool_converter.BasicSyntoolConverter(
Expand Down Expand Up @@ -226,6 +239,31 @@ def test_run(self):
mock_post_ingest.assert_called_once_with(['ingested_dir1', 'ingested_dir2'], 'results')
mock_remove.assert_has_calls((mock.call('conv1.tiff'), mock.call('conv2.tiff')))

def test_run_no_converter(self):
"""If no converter is set, convert() should return the path to
the input file
"""
converter = syntool_converter.BasicSyntoolConverter(
converter_type=None,
ingest_parameter_files='bar')
with mock.patch.object(converter, 'convert',) as mock_convert, \
mock.patch.object(converter, 'ingest',
return_value=['ingested_dir1']) as mock_ingest, \
mock.patch.object(converter, 'post_ingest') as mock_post_ingest, \
mock.patch('os.remove') as mock_remove:
converter.run(
in_file='in.nc',
out_dir='out',
results_dir='results')
mock_convert.assert_not_called()
mock_ingest.assert_called_once_with(
Path('out', 'in.nc'),
'results',
['--config', Path('parameters/3413.ini'),
'--options-file', converter.PARAMETERS_DIR / 'bar'])
mock_post_ingest.assert_called_once_with(['ingested_dir1'], 'results')
mock_remove.assert_called_once_with('in.nc')


class Sentinel1SyntoolConverterTestCase(unittest.TestCase):
"""Tests for the Sentinel1SyntoolConverter class"""
Expand Down Expand Up @@ -270,6 +308,9 @@ def test_convert(self):
for file_name in file_names:
mock_convert.assert_any_call(measurement_dir / file_name, 'out_dir', ['--baz'])




def test_ingest(self):
"""Test that the subdirectories created by ingestion are copied
to the ingested results folder
Expand Down

0 comments on commit 4e5ce6c

Please sign in to comment.