def tearDown(self): # call _reset method deleting clearing Translator for unit testing, # otherwise the second, third, .. tests will use the instance created # in the first test instead of being properly initialized temp = util.VariableTranslator(unittest=True) temp._reset() temp = util.PathManager(unittest=True) temp._reset()
def setUp(self, mock_read_json): # set up translation dictionary without calls to filesystem _ = util.VariableTranslator(unittest=True) _ = util.PathManager(unittest=True)
def setUp(self, mock_read_yaml): # set up translation dictionary without calls to filesystem temp = util.VariableTranslator(unittest_flag = True) temp = util.PathManager(unittest_flag = True)
def test_variabletranslator_no_key(self, mock_read_yaml): temp = util.VariableTranslator(unittest_flag = True) self.assertRaises(AssertionError, temp.toCF, 'B', 'PRECT') self.assertRaises(KeyError, temp.toCF, 'not_CF', 'nonexistent_var') self.assertRaises(AssertionError, temp.fromCF, 'B', 'PRECT') self.assertRaises(KeyError, temp.fromCF, 'not_CF', 'nonexistent_var')
def test_variabletranslator_cf(self, mock_read_yaml): temp = util.VariableTranslator(unittest_flag = True) self.assertEqual(temp.toCF('CF', 'pr_var'), 'pr_var') self.assertEqual(temp.fromCF('CF', 'pr_var'), 'pr_var')
def test_read_model_varnames_multiple(self, mock_read_yaml): # create multiple entries when multiple models specified temp = util.VariableTranslator(unittest_flag = True) self.assertEqual(temp.fromCF('A','B'), 'D') self.assertEqual(temp.fromCF('C','B'), 'D') temp._reset()
def test_read_model_varnames(self, mock_read_yaml): # normal operation - convert string to list temp = util.VariableTranslator(unittest_flag = True) self.assertEqual(temp.fromCF('A','B'), 'D') temp._reset()