- Timestamp:
- 2013-10-24T18:49:17+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2013/dev_r3987_UKMO4_OBS/NEMOGCM/TOOLS/OBSTOOLS/OOO/ooo/test_nml.py
r4122 r4126 5 5 def version(vn): 6 6 # Converts module version string to int tuple as PEP-440 7 return tuple(map(int, nml.__version__.split(".")))7 return tuple(map(int, vn.split("."))) 8 8 9 9 HEADER = """ … … 16 16 LOGIC = " ln_test = .TRUE. ! Comment\n" 17 17 NUMERIC = " nn_off_idx = 1 2 3\n" 18 FORD= " nn_off_idx=1 2 3\n"18 NOSPACE = " nn_off_idx=1 2 3\n" 19 19 NEGATIVE = " nn_off_idx = -1 -2 -3\n" 20 20 LIST = " off_files = 'a.nc' 'b.nc' 'c.nc' ! Comment\n" … … 28 28 self.logic_text = "\n".join([HEADER, LOGIC, FOOTER]) 29 29 self.numeric_text = "\n".join([HEADER, NUMERIC, FOOTER]) 30 self. ford_text = "\n".join([HEADER, FORD, FOOTER])30 self.nospace_text = "\n".join([HEADER, NOSPACE, FOOTER]) 31 31 self.neg_numeric_text = "\n".join([HEADER, NEGATIVE, FOOTER]) 32 32 self.list_text = "\n".join([HEADER, LIST, FOOTER]) … … 63 63 self.assertDictEqual(data, truth) 64 64 65 def test_ ford_data(self):66 data = nml.variables(self. ford_text)65 def test_nospace_data(self): 66 data = nml.variables(self.nospace_text) 67 67 truth = {"nn_off_idx": "1 2 3"} 68 68 self.assertDictEqual(data, truth) … … 84 84 85 85 def test_replace_variable_comment(self): 86 FIXTURE = " x = y! comment \n"87 RESULT = " x = z! comment \n"86 FIXTURE = " x = 'y' ! comment \n" 87 RESULT = " x = 'z' ! comment \n" 88 88 text = nml.replace(FIXTURE, {"x": "z"}) 89 89 self.assertEqual(text, RESULT) 90 90 91 91 def test_replace_variable_no_comment(self): 92 FIXTURE = " x = y \n" 93 RESULT = " x = z \n" 92 FIXTURE = " x = 'y' \n" 93 RESULT = " x = 'z' \n" 94 text = nml.replace(FIXTURE, {"x": "z"}) 95 self.assertEqual(text, RESULT) 96 97 def test_replace_variable_no_space(self): 98 FIXTURE = " x='y' \n" 99 RESULT = " x='z' \n" 100 text = nml.replace(FIXTURE, {"x": "z"}) 101 self.assertEqual(text, RESULT) 102 103 def test_replace_variable_no_space_comment(self): 104 FIXTURE = " x='y' ! comment \n" 105 RESULT = " x='z' ! comment \n" 94 106 text = nml.replace(FIXTURE, {"x": "z"}) 95 107 self.assertEqual(text, RESULT) … … 160 172 self.char = "foo@bar.com" 161 173 self.num = 10 174 self.mixed_list = ["foo.nc", -1, True] 175 176 def test_should_format_mixed_list(self): 177 data = nml.tostring(self.mixed_list) 178 result = "'foo.nc', -1, .TRUE." 179 self.assertEqual(data, result) 162 180 163 181 def test_should_format_numeric_list(self): … … 173 191 def test_should_format_strings(self): 174 192 data = nml.tostring(self.char) 175 result = self.char193 result = "'%s'" % (self.char,) 176 194 self.assertEqual(data, result) 177 195 … … 180 198 result = str(self.num) 181 199 self.assertEqual(data, result) 200 201 def test_should_not_format_numeric_string(self): 202 input = "3.14159" 203 self.assertEqual(nml.tostring(input), input) 182 204 183 205 def test_should_format_logicals(self): … … 186 208 self.assertEqual(data.upper(), result) 187 209 210 def test_should_not_format_string_of_list_data(self): 211 for input in ["1 2 3", "1, 2, 3", ".TRUE. .FALSE."]: 212 case = nml.tostring(input) 213 self.assertEqual(case, input) 214 188 215 class TestUpdateNamelist(unittest.TestCase): 189 216 def setUp(self): … … 194 221 self.single = """ 195 222 &namone 196 x = y223 x = 'y' 197 224 / 198 225 """ 199 226 self.single_update = """ 200 227 &namone 201 x = z228 x = 'z' 202 229 / 203 230 """ 204 231 205 232 def test_should_append_new_variable_to_namelist(self): 206 trial = nml.update("namone", self.empty, {"x": " y"})233 trial = nml.update("namone", self.empty, {"x": "'y'"}) 207 234 self.assertEqual(trial, self.single) 208 235 209 236 def test_should_update_existing_variables(self): 210 trial = nml.update("namone", self.single, {"x": " z"})237 trial = nml.update("namone", self.single, {"x": "'z'"}) 211 238 self.assertEqual(trial, self.single_update) 212 239
Note: See TracChangeset
for help on using the changeset viewer.