class Test_name(tests.IrisTest): def setUp(self): # None token CFVariableMixin self.cf_var = CFVariableMixin() self.cf_var.standard_name = None self.cf_var.long_name = None self.cf_var.var_name = None self.cf_var.attributes = {} self.default = CFVariableMixin._DEFAULT_NAME # bad token CFVariableMixin self.cf_bad = CFVariableMixin() self.cf_bad.standard_name = None self.cf_bad.long_name = 'nope nope' self.cf_bad.var_name = None self.cf_bad.attributes = {'STASH': 'nope nope'} def test_standard_name(self): token = 'air_temperature' self.cf_var.standard_name = token result = self.cf_var.name() self.assertEqual(result, token) def test_long_name(self): token = 'long_name' self.cf_var.long_name = token result = self.cf_var.name() self.assertEqual(result, token) def test_var_name(self): token = 'var_name' self.cf_var.var_name = token result = self.cf_var.name() self.assertEqual(result, token) def test_stash(self): token = 'stash' self.cf_var.attributes['STASH'] = token result = self.cf_var.name() self.assertEqual(result, token) def test_default(self): result = self.cf_var.name() self.assertEqual(result, self.default) def test_token_long_name(self): token = 'long_name' self.cf_bad.long_name = token result = self.cf_bad.name(token=True) self.assertEqual(result, token) def test_token_var_name(self): token = 'var_name' self.cf_bad.var_name = token result = self.cf_bad.name(token=True) self.assertEqual(result, token) def test_token_stash(self): token = 'stash' self.cf_bad.attributes['STASH'] = token result = self.cf_bad.name(token=True) self.assertEqual(result, token) def test_token_default(self): result = self.cf_var.name(token=True) self.assertEqual(result, self.default) def test_fail_token_default(self): emsg = 'Cannot retrieve a valid name token' with self.assertRaisesRegexp(ValueError, emsg): self.cf_var.name(default='_nope', token=True)
class Test_name(tests.IrisTest): def setUp(self): # None token CFVariableMixin self.cf_var = CFVariableMixin() self.cf_var.standard_name = None self.cf_var.long_name = None self.cf_var.var_name = None self.cf_var.attributes = {} self.default = CFVariableMixin._DEFAULT_NAME # bad token CFVariableMixin self.cf_bad = CFVariableMixin() self.cf_bad.standard_name = None self.cf_bad.long_name = "nope nope" self.cf_bad.var_name = None self.cf_bad.attributes = {"STASH": "nope nope"} def test_standard_name(self): token = "air_temperature" self.cf_var.standard_name = token result = self.cf_var.name() self.assertEqual(result, token) def test_long_name(self): token = "long_name" self.cf_var.long_name = token result = self.cf_var.name() self.assertEqual(result, token) def test_var_name(self): token = "var_name" self.cf_var.var_name = token result = self.cf_var.name() self.assertEqual(result, token) def test_stash(self): token = "stash" self.cf_var.attributes["STASH"] = token result = self.cf_var.name() self.assertEqual(result, token) def test_default(self): result = self.cf_var.name() self.assertEqual(result, self.default) def test_token_long_name(self): token = "long_name" self.cf_bad.long_name = token result = self.cf_bad.name(token=True) self.assertEqual(result, token) def test_token_var_name(self): token = "var_name" self.cf_bad.var_name = token result = self.cf_bad.name(token=True) self.assertEqual(result, token) def test_token_stash(self): token = "stash" self.cf_bad.attributes["STASH"] = token result = self.cf_bad.name(token=True) self.assertEqual(result, token) def test_token_default(self): result = self.cf_var.name(token=True) self.assertEqual(result, self.default) def test_fail_token_default(self): emsg = "Cannot retrieve a valid name token" with self.assertRaisesRegex(ValueError, emsg): self.cf_var.name(default="_nope", token=True)