Skip to content

Commit

Permalink
Fix unittestsFix unittests
Browse files Browse the repository at this point in the history
Signed-off-by: Adam.Dybbroe <a000680@c21856.ad.smhi.se>
  • Loading branch information
Adam.Dybbroe committed May 7, 2021
1 parent 128a999 commit 28d1d28
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
12 changes: 6 additions & 6 deletions activefires_pp/post_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,13 @@ def _generate_output_message(self, filepath, input_msg, region=None):
pubmsg = Message(output_topic, 'file', to_send)
return pubmsg

def _generate_no_fires_messages(self, input_msg, msg_string)
"""Create the output messages to publish."""
def _generate_no_fires_messages(self, input_msg, msg_string):
"""Create the output messages to publish."""

to_send = prepare_posttroll_message(input_msg)
to_send['info'] = msg_string
publish_messages = []
for ext in ['National', 'Regional']:
to_send = prepare_posttroll_message(input_msg)
to_send['info'] = msg_string
publish_messages = []
for ext in ['National', 'Regional']:
topic = self.output_topic + '/' + ext
publish_messages.append(Message(topic, 'info', to_send))

Expand Down
6 changes: 3 additions & 3 deletions activefires_pp/tests/test_fires_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,9 @@ def test_general_national_fires_filtering(get_global_mask, setup_comm, get_confi
mymsg = "Fake message"

with patch('activefires_pp.post_processing.store_geojson') as store_geojson:
with patch('activefires_pp.post_processing.ActiveFiresPostprocessing.get_output_message') as get_output_msg:
with patch('activefires_pp.post_processing.ActiveFiresPostprocessing.get_output_messages') as get_output_msg:
store_geojson.return_value = "/some/output/path"
get_output_msg.return_value = "my fake output message"
get_output_msg.return_value = ["my fake output message"]
outmsg, result = afpp.fires_filtering(mymsg, af_shapeff)

store_geojson.assert_called_once()
Expand All @@ -287,4 +287,4 @@ def test_general_national_fires_filtering(get_global_mask, setup_comm, get_confi
assert len(result) == 1
np.testing.assert_almost_equal(result.iloc[0]['latitude'], 59.52483368)
np.testing.assert_almost_equal(result.iloc[0]['longitude'], 17.1681633)
assert outmsg == "my fake output message"
assert outmsg == ["my fake output message"]
19 changes: 10 additions & 9 deletions activefires_pp/tests/test_messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def test_prepare_posttroll_message(setup_comm, get_config, gethostname):
myconfigfile = "/my/config/file/path"
myboarders_file = "/my/shape/file/with/country/boarders"
mymask_file = "/my/shape/file/with/polygons/to/filter/out"
#myregion_filepath = "/my/region/file/path"

afpp = ActiveFiresPostprocessing(myconfigfile, myboarders_file, mymask_file)

Expand All @@ -86,11 +85,13 @@ def test_prepare_posttroll_message(setup_comm, get_config, gethostname):
assert res_msg.subject == '/VIIRS/L2/Fires/PP/Regional/9999'

msg_str = 'No fire detections for this granule'
res_msg = afpp._generate_no_fires_message(input_msg, msg_str)

assert res_msg.data['info'] == msg_str
assert res_msg.subject == '/VIIRS/L2/Fires/PP'
assert 'type' not in res_msg.data
assert 'format' not in res_msg.data
assert 'product' not in res_msg.data
assert 'uri' not in res_msg.data

result_messages = afpp._generate_no_fires_messages(input_msg, msg_str)

for (nat_or_reg, res_msg) in zip(['National', 'Regional'], result_messages):
assert res_msg.data['info'] == msg_str
assert res_msg.subject == '/VIIRS/L2/Fires/PP/' + nat_or_reg
assert 'type' not in res_msg.data
assert 'format' not in res_msg.data
assert 'product' not in res_msg.data
assert 'uri' not in res_msg.data

0 comments on commit 28d1d28

Please sign in to comment.