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_pass_mixture(self): token = 'S.imple@one+two_3' result = CFVariableMixin.token(token) self.assertEqual(result, token)
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)
def test_pass_simple(self): token = 'simple' result = CFVariableMixin.token(token) self.assertEqual(result, token)
def test_pass_leading_digit(self): token = '123simple' result = CFVariableMixin.token(token) self.assertEqual(result, token)
def test_fail_space(self): result = CFVariableMixin.token('nope nope') self.assertIsNone(result)
def test_fail_colon(self): result = CFVariableMixin.token('nope:') self.assertIsNone(result)
def test_fail_leading_underscore(self): result = CFVariableMixin.token('_nope') self.assertIsNone(result)
def test_fail_leading_at(self): result = CFVariableMixin.token('@nope') self.assertIsNone(result)
def test_none_standard_name(self): cf_var = CFVariableMixin() cf_var.standard_name = None self.assertIsNone(cf_var.standard_name)
def test_passthru_None(self): result = CFVariableMixin.token(None) self.assertIsNone(result)
def test_invalid_standard_name(self): cf_var = CFVariableMixin() emsg = "'not_a_standard_name' is not a valid standard_name" with self.assertRaisesRegexp(ValueError, emsg): cf_var.standard_name = 'not_a_standard_name'
def test_valid_standard_name(self): cf_var = CFVariableMixin() cf_var.standard_name = 'air_temperature' self.assertEqual(cf_var.standard_name, 'air_temperature')
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)
def test_fail_leading_plus(self): result = CFVariableMixin.token("+nope") self.assertIsNone(result)
def setUp(self): 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 = dict()