44import pytest
55import logging
66
7+ from METdbLoad .ush import constants as CN
78from METdbLoad .ush .read_data_files import ReadDataFiles
89from METdbLoad .ush .read_load_xml import XmlLoadFile
910from METdbLoad .test .utils import (
2526 MTD_HEADER_NO_DATA ,
2627 TCSTAT_DIR ,
2728 TCSTAT_NO_HEADER ,
29+ MTD_HEADER_NO_DATA ,
30+ MTD_INTENSITY_90_LAST_COL ,
31+ MTD_NO_FCST_T_BEG ,
2832)
2933
3034
@@ -117,7 +121,6 @@ def test_read_data_logger():
117121 assert rdf_logger_given .logger .name == logger_name
118122
119123
120-
121124def test_read_data_no_valid_files ():
122125 """
123126 test that when no valid files are available to load, a ValueError is raised
@@ -128,7 +131,6 @@ def test_read_data_no_valid_files():
128131 load_files = None
129132 rdf = ReadDataFiles ()
130133
131-
132134 # A ValueError is raised, but sys.exit is invoked, resulting
133135 # in a SystemExit in the exception block
134136
@@ -141,6 +143,7 @@ def test_read_data_no_valid_files():
141143 load_files = []
142144 rdf .read_data (load_flags , load_files , line_types )
143145
146+
144147def test_only_empty_data (tmp_path , get_xml_loadfile ):
145148 """
146149
@@ -152,12 +155,12 @@ def test_only_empty_data(tmp_path, get_xml_loadfile):
152155 XML_LOADFILE = get_xml_loadfile (tmp_path , EMPTY_DIR )
153156
154157 # Read all of the data from the data files into a dataframe
155- rdf = ReadDataFiles ()
158+ rdf = ReadDataFiles ()
156159
157160 # read in the data files, with options specified by XML flags
158161 rdf .read_data (
159- XML_LOADFILE .flags , XML_LOADFILE .load_files , XML_LOADFILE .line_types
160- )
162+ XML_LOADFILE .flags , XML_LOADFILE .load_files , XML_LOADFILE .line_types
163+ )
161164
162165 # Empty stat_data data frame with no rows and no columns
163166 assert rdf .stat_data .shape [0 ] == 0
@@ -175,7 +178,7 @@ def test_one_empty_data(tmp_path, get_xml_loadfile):
175178 XML_LOADFILE = get_xml_loadfile (tmp_path , ONE_EMPTY_DIR )
176179
177180 # Read all of the data from the data files into a dataframe
178- rdf = ReadDataFiles ()
181+ rdf = ReadDataFiles ()
179182
180183 # read in the data files, with options specified by XML flags
181184 rdf .read_data (
@@ -185,6 +188,7 @@ def test_one_empty_data(tmp_path, get_xml_loadfile):
185188 # Empty stat_data data frame with no rows and no columns
186189 assert rdf .stat_data .shape [0 ] > 0
187190
191+
188192@pytest .mark .parametrize ("get_generic_xml_loadfile" , ["vsdb" ], indirect = True )
189193def test_empty_vsdb (tmp_path , get_generic_xml_loadfile ):
190194 '''
@@ -205,6 +209,7 @@ def test_empty_vsdb(tmp_path, get_generic_xml_loadfile):
205209 assert rdf .stat_data .shape [0 ] == 0
206210 assert rdf .stat_data .shape [1 ] == 0
207211
212+
208213@pytest .mark .parametrize ("get_generic_xml_loadfile" , ["vsdb" ], indirect = True )
209214def test_vsdb (tmp_path , get_generic_xml_loadfile ):
210215 '''
@@ -241,6 +246,7 @@ def test_vsdb_no_equals(tmp_path, get_xml_loadfile):
241246 )
242247 assert rdf .stat_data .shape [0 ] > 0
243248
249+
244250@pytest .mark .parametrize ("get_generic_xml_loadfile" , ['mode_cts' ], indirect = True )
245251def test_empty_mode_cts (tmp_path , get_generic_xml_loadfile ):
246252 '''
@@ -260,6 +266,7 @@ def test_empty_mode_cts(tmp_path, get_generic_xml_loadfile):
260266 assert rdf .stat_data .shape [0 ] == 0
261267 assert rdf .stat_data .shape [1 ] == 0
262268
269+
263270@pytest .mark .parametrize ("get_generic_xml_loadfile" , ['mode_cts' ], indirect = True )
264271def test_empty_mode_no_header (tmp_path , get_generic_xml_loadfile ):
265272 '''
@@ -273,12 +280,11 @@ def test_empty_mode_no_header(tmp_path, get_generic_xml_loadfile):
273280 # Read all of the data from the data files into a dataframe
274281 rdf = ReadDataFiles ()
275282
276-
277283 # read in the data files, with options specified by XML flags
278284 with pytest .raises (SystemExit ):
279- rdf .read_data (
280- XML_LOADFILE .flags , XML_LOADFILE .load_files , XML_LOADFILE .line_types
281- )
285+ rdf .read_data (
286+ XML_LOADFILE .flags , XML_LOADFILE .load_files , XML_LOADFILE .line_types
287+ )
282288
283289
284290 @pytest .mark .parametrize ("get_generic_xml_loadfile" , ['mode_cts' , ' mode_obj' ], indirect = True )
@@ -298,9 +304,11 @@ def test_empty_mode_cts_mode_obj(tmp_path, get_generic_xml_loadfile):
298304 XML_LOADFILE .flags , XML_LOADFILE .load_files , XML_LOADFILE .line_types
299305 )
300306
307+
301308 assert rdf .stat_data .shape [0 ] == 0
302309 assert rdf .stat_data .shape [1 ] == 0
303310
311+
304312@pytest .mark .parametrize ("get_generic_xml_loadfile" , ['mode_cts' ], indirect = True )
305313def test_empty_mode_cts_valid_mod_obj (tmp_path , get_generic_xml_loadfile ):
306314 '''
@@ -324,38 +332,39 @@ def test_empty_mode_cts_valid_mod_obj(tmp_path, get_generic_xml_loadfile):
324332
325333@pytest .mark .parametrize ("get_generic_xml_loadfile" , ['mode_cts' ], indirect = True )
326334def test_empty_mode_obj_valid_mod_cts (tmp_path , get_generic_xml_loadfile ):
327- '''
328- Verify that expected behavior is observed when the mode obj data file is empty
329- but there is a valid mode cts file
335+ '''
336+ Verify that expected behavior is observed when the mode obj data file is empty
337+ but there is a valid mode cts file
330338
331- '''
332- XML_LOADFILE = get_generic_xml_loadfile (tmp_path , MODE_OBJ_EMPTY , 'mode_cts' )
339+ '''
340+ XML_LOADFILE = get_generic_xml_loadfile (tmp_path , MODE_OBJ_EMPTY , 'mode_cts' )
333341
334- # Read all of the data from the data files into a dataframe
335- rdf = ReadDataFiles ()
342+ # Read all of the data from the data files into a dataframe
343+ rdf = ReadDataFiles ()
336344
337- # read in the data files, with options specified by XML flags
338- rdf .read_data (
339- XML_LOADFILE .flags , XML_LOADFILE .load_files , XML_LOADFILE .line_types
340- )
345+ # read in the data files, with options specified by XML flags
346+ rdf .read_data (
347+ XML_LOADFILE .flags , XML_LOADFILE .load_files , XML_LOADFILE .line_types
348+ )
349+
350+ assert rdf .stat_data .shape [0 ] == 0
351+ assert rdf .stat_data .shape [1 ] == 0
341352
342- assert rdf .stat_data .shape [0 ] == 0
343- assert rdf .stat_data .shape [1 ] == 0
344353
345354@pytest .mark .parametrize ("get_generic_xml_loadfile" , ['mtd_2d' ], indirect = True )
346355def test_empty_mtd (tmp_path , get_generic_xml_loadfile ):
347- '''
348- Verify that expected behavior is observed when the mtd file is empty
356+ '''
357+ Verify that expected behavior is observed when the mtd file is empty
349358
350- '''
351- XML_LOADFILE = get_generic_xml_loadfile (tmp_path , MTD_EMPTY , 'mtd_2d' )
359+ '''
360+ XML_LOADFILE = get_generic_xml_loadfile (tmp_path , MTD_EMPTY , 'mtd_2d' )
352361
353- # Read all of the data from the data files into a dataframe
354- rdf = ReadDataFiles ()
355- with pytest .raises (SystemExit ):
356- rdf .read_data (
357- XML_LOADFILE .flags , XML_LOADFILE .load_files , XML_LOADFILE .line_types
358- )
362+ # Read all of the data from the data files into a dataframe
363+ rdf = ReadDataFiles ()
364+ with pytest .raises (SystemExit ):
365+ rdf .read_data (
366+ XML_LOADFILE .flags , XML_LOADFILE .load_files , XML_LOADFILE .line_types
367+ )
359368
360369
361370@pytest .mark .parametrize ("get_generic_xml_loadfile" , ['mtd_2d' ], indirect = True )
@@ -365,15 +374,63 @@ def test_mtd_header_no_data(tmp_path, get_generic_xml_loadfile):
365374 but no header.
366375
367376 '''
368- XML_LOADFILE = get_generic_xml_loadfile (tmp_path , MTD_EMPTY , 'mtd_2d' )
377+ XML_LOADFILE = get_generic_xml_loadfile (tmp_path , MTD_HEADER_NO_DATA , 'mtd_2d' )
369378
370379 # Read all of the data from the data files into a dataframe
371380 rdf = ReadDataFiles ()
372- with pytest .raises (SystemExit ):
373- rdf .read_data (
381+ rdf .read_data (
374382 XML_LOADFILE .flags , XML_LOADFILE .load_files , XML_LOADFILE .line_types
375383 )
376384
385+ # Should produce an empty dataframe
386+ assert rdf .stat_data .shape [0 ] == 0
387+ assert rdf .stat_data .shape [1 ] == 0
388+
389+ @pytest .mark .parametrize ("get_generic_xml_loadfile" , ['mtd_2d' ], indirect = True )
390+ def test_mtd_no_fcst_t_beg (tmp_path , get_generic_xml_loadfile ):
391+ '''
392+ Verify that expected behavior is observed when the mtd file does not
393+ have the fcst_t_beg column. The fcst_t_beg column should be added
394+ with the CN.MV_NULL value.
395+
396+ '''
397+ XML_LOADFILE = get_generic_xml_loadfile (tmp_path , MTD_NO_FCST_T_BEG , 'mtd_2d' )
398+
399+ # Read all of the data from the data files into a dataframe
400+ rdf = ReadDataFiles ()
401+ rdf .read_data (
402+ XML_LOADFILE .flags , XML_LOADFILE .load_files , XML_LOADFILE .line_types
403+ )
404+
405+ # Verify that the missing fcst_t_beg column has been added with CN.MV_NULL
406+ assert rdf .mtd_2d_data ['fcst_t_beg' ][0 ] == CN .MV_NULL
407+
408+ @pytest .mark .parametrize ("get_generic_xml_loadfile" , ['mtd_2d' ], indirect = True )
409+ def test_mtd_intensity_90_last_col (tmp_path , get_generic_xml_loadfile ):
410+ '''
411+ Verify that expected behavior is observed when the mtd file is missing the
412+ intensity_99 column and intensity_90 is the last column. Another
413+ intensity column should be added.
414+
415+ '''
416+ XML_LOADFILE = get_generic_xml_loadfile (tmp_path , MTD_INTENSITY_90_LAST_COL , 'mtd_2d' )
417+
418+ # Read all of the data from the data files into a dataframe
419+ rdf = ReadDataFiles ()
420+ rdf .read_data (
421+ XML_LOADFILE .flags , XML_LOADFILE .load_files , XML_LOADFILE .line_types
422+ )
423+
424+ # verify that a column was added after the intensity_90 column and the
425+ # added column is 'intensity_nn'
426+ columns = rdf .mtd_2d_data .columns .to_list ()
427+ for idx , col in enumerate (columns ):
428+ if col == 'intensity_90' :
429+ idx_intensity_90 = idx
430+
431+ assert len (rdf .mtd_2d_data .iloc [idx_intensity_90 + 1 ]) > 0
432+ assert rdf .mtd_2d_data ['intensity_nn' ].shape [0 ] > 0
433+
377434@pytest .mark .parametrize ("get_generic_xml_loadfile" , ['tcst' ], indirect = True )
378435def test_tcst (tmp_path , get_generic_xml_loadfile ):
379436 '''
0 commit comments