Esempio n. 1
0
 def test_rhs_str_and_rhs_list_fence_double_list(self):
     tdict = {
         "echam": {
             "streams": ["a", "b", "c"],
             "files_with_streams":
             "file_[[streams-->STREAM]][[streams-->OTHER]].nc",
         }
     }
     r = esm_parser.list_to_multikey(
         ["echam", True],
         "file_[[streams-->STREAM]][[streams-->OTHER]].nc",
         tdict,
         [],
         False,
     )
     expected_answer = [
         "file_aa.nc",
         "file_ab.nc",
         "file_ac.nc",
         "file_ba.nc",
         "file_bb.nc",
         "file_bc.nc",
         "file_ca.nc",
         "file_cb.nc",
         "file_cc.nc",
     ]
     self.assertEqual(expected_answer, r)
Esempio n. 2
0
 def test_rhs_str_and_rhs_list_fence(self):
     tdict = {
         "echam": {
             "streams": ["a", "b", "c"],
             "files_with_streams": "file_[[streams-->STREAM]].nc",
         }
     }
     r = esm_parser.list_to_multikey(["echam", True],
                                     "file_[[streams-->STREAM]].nc", tdict,
                                     [], False)
     expected_answer = ["file_a.nc", "file_b.nc", "file_c.nc"]
     self.assertEqual(expected_answer, r)
Esempio n. 3
0
 def test_lhs_str_and_rhs_list_nostr_rhs(self):
     tdict = {
         "echam": {
             "[[streams-->STREAM]]": [True, 1],
             "streams": ["echam", "accw", "co2"],
         }
     }
     r = esm_parser.list_to_multikey(["echam", "[[streams-->STREAM]]"],
                                     [True, 1], tdict, [], False)
     expected_answer = {
         "echam": [True, 1],
         "accw": [True, 1],
         "co2": [True, 1]
     }
     self.assertEqual(r, expected_answer)
Esempio n. 4
0
 def test_lhs_str_and_rhs_list(self):
     tdict = {
         "echam": {
             "[[streams-->STREAM]]": [
                 "restart_one_${expid}_STREAM.nc",
                 "restart_two_${expid}_STREAM.nc",
             ],
             "streams": ["echam", "accw", "co2"],
         }
     }
     r = esm_parser.list_to_multikey(
         ["echam", "[[streams-->STREAM]]"],
         [
             "restart_one_${expid}_STREAM.nc",
             "restart_two_${expid}_STREAM.nc"
         ],
         tdict,
         [],
         False,
     )
     expected_answer = {
         "echam": [
             "restart_one_${expid}_echam.nc",
             "restart_one_${expid}_accw.nc",
             "restart_one_${expid}_co2.nc",
             "restart_two_${expid}_echam.nc",
             "restart_two_${expid}_accw.nc",
             "restart_two_${expid}_co2.nc",
         ],
         "accw": [
             "restart_one_${expid}_echam.nc",
             "restart_one_${expid}_accw.nc",
             "restart_one_${expid}_co2.nc",
             "restart_two_${expid}_echam.nc",
             "restart_two_${expid}_accw.nc",
             "restart_two_${expid}_co2.nc",
         ],
         "co2": [
             "restart_one_${expid}_echam.nc",
             "restart_one_${expid}_accw.nc",
             "restart_one_${expid}_co2.nc",
             "restart_two_${expid}_echam.nc",
             "restart_two_${expid}_accw.nc",
             "restart_two_${expid}_co2.nc",
         ],
     }
     self.assertEqual(r, expected_answer)
Esempio n. 5
0
 def test_lhs_str_and_rhs_str(self):
     tdict = {
         "echam": {
             "[[streams-->STREAM]]": "restart_${expid}_STREAM.nc",
             "streams": ["echam", "accw", "co2"],
         }
     }
     r = esm_parser.list_to_multikey(
         ["echam", "[[streams-->STREAM]]"],
         "restart_${expid}_STREAM.nc",
         tdict,
         [],
         False,
     )
     self.assertEqual(
         r,
         {
             "echam": "restart_${expid}_echam.nc",
             "accw": "restart_${expid}_accw.nc",
             "co2": "restart_${expid}_co2.nc",
         },
     )
Esempio n. 6
0
 def test_double_list(self):
     tdict = {
         "echam": {
             "[[streams-->STREAM]]_[[streams-->OTHER]]":
             "f_STREAM_OTHER.nc",
             "streams": ["echam", "accw", "co2"],
         }
     }
     r = esm_parser.list_to_multikey(
         ["echam", "[[streams-->STREAM]]_[[streams-->OTHER]]"],
         "f_STREAM_OTHER.nc",
         tdict,
         [],
         False,
     )
     # Expected answer in pretty format:
     # accw_accw: f_accw_accw.nc
     # accw_co2: f_accw_co2.nc
     # accw_echam: f_accw_echam.nc
     # co2_accw: f_co2_accw.nc
     # co2_co2: f_co2_co2.nc
     # co2_echam: f_co2_echam.nc
     # echam_accw: f_echam_accw.nc
     # echam_co2: f_echam_co2.nc
     # echam_echam: f_echam_echam.nc
     expected_answer = {
         "echam_echam": "f_echam_echam.nc",
         "echam_accw": "f_echam_accw.nc",
         "echam_co2": "f_echam_co2.nc",
         "accw_echam": "f_accw_echam.nc",
         "accw_accw": "f_accw_accw.nc",
         "accw_co2": "f_accw_co2.nc",
         "co2_echam": "f_co2_echam.nc",
         "co2_accw": "f_co2_accw.nc",
         "co2_co2": "f_co2_co2.nc",
     }
     self.assertEqual(r, expected_answer)
Esempio n. 7
0
 def test_lhs_bool(self):
     tdict = {"echam": {"forcing": {True: "lala"}}}
     r = esm_parser.list_to_multikey(["echam", "forcing", True], "lala",
                                     tdict, [], False)
     self.assertEqual(r, {True: "lala"})
Esempio n. 8
0
 def test_rhs_not_str(self):
     tdict = {"echam": {42: 42}}
     r = esm_parser.list_to_multikey(["echam", 42], 42, tdict, [], False)
     self.assertEqual(r, 42)
Esempio n. 9
0
 def test_lhs_no_fence(self):
     tdict = {"echam": {"42": "rhs for 42"}}
     r = esm_parser.list_to_multikey(["echam", "42"], "rhs for 42", tdict,
                                     [], False)
     self.assertEqual(r, {"42": "rhs for 42"})
Esempio n. 10
0
 def test_skips_first_block_if_lhs_isnt_str(self):
     r = esm_parser.list_to_multikey(["computer", "ncores", 63], 63,
                                     {"computer": {
                                         "ncores": 63
                                     }}, [], False)
     self.assertEqual(r, 63)
Esempio n. 11
0
 def test_skips_func_if_bad_tree(self):
     r = esm_parser.list_to_multikey([None], "something",
                                     {"config": "lala"}, [], False)
     self.assertEqual(r, "something")