def test_from_str_including_line_with_only_spaces(): input_str = """default_experiment 2016 08 01 00 0 0 """ expected_diag_table = DiagTable("default_experiment", datetime(2016, 8, 1), []) diag_table = DiagTable.from_str(input_str) assert diag_table == expected_diag_table
def diag_table(): return DiagTable( "experiment", datetime(2000, 1, 1), [diag_file("first_diagnostics"), diag_file("second_diagnostics")], )
def test_from_str(): input_str = """default_experiment 2016 08 01 00 0 0 #output files "atmos_static", -1, "hours", 1, "hours", "time", "atmos_dt_atmos", 2, "hours", 1, "hours", "time" #inline comment "empty_file", 2, "hours", 1, "hours", "time" # #output variables # ### # atmos_static ### "dynamics", "zsurf", "HGTsfc", "atmos_static", "all", .false., "none", 2 ### # atmos_dt_atmos ### "dynamics", "us", "UGRDlowest", "atmos_dt_atmos", "all", .false., "none", 2, # inline comment "dynamics", "u850", "UGRD850", "atmos_dt_atmos", "all", .true., "none", 2 """ atmos_static = DiagFileConfig( "atmos_static", -1, "hours", [DiagFieldConfig("dynamics", "zsurf", "HGTsfc")], ) atmos_dt_atmos = DiagFileConfig( "atmos_dt_atmos", 2, "hours", [ DiagFieldConfig("dynamics", "us", "UGRDlowest"), DiagFieldConfig( "dynamics", "u850", "UGRD850", reduction_method="average"), ], ) empty_file = DiagFileConfig("empty_file", 2, "hours", []) expected_diag_table = DiagTable( "default_experiment", datetime(2016, 8, 1), [atmos_static, atmos_dt_atmos, empty_file], ) diag_table = DiagTable.from_str(input_str) assert diag_table == expected_diag_table
def test_DiagTable_dict_round_trip(diag_table): round_tripped_diag_table = DiagTable.from_dict(diag_table.asdict()) assert diag_table == round_tripped_diag_table
def test_DiagTable_string_round_trip(diag_table): round_tripped_diag_table = DiagTable.from_str(str(diag_table)) assert diag_table == round_tripped_diag_table
def test__token_to_str(token, expected_output): output = DiagTable._token_to_str(token) assert output == expected_output
def test__str_to_token(input_, expected_output): output = DiagTable._str_to_token(input_) assert output == expected_output
def test_from_str_raises_config_error(diag_table_str): with pytest.raises(ConfigError): DiagTable.from_str(diag_table_str)