From 031f1da47546ebf12f6e74467fcf4824ea4a26a3 Mon Sep 17 00:00:00 2001 From: kaliko Date: Tue, 7 Jun 2016 16:33:01 +0200 Subject: [PATCH] More robust Meta Object Controls name attribute is str type --- sima/lib/meta.py | 4 +++- tests/test_meta.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sima/lib/meta.py b/sima/lib/meta.py index 069a904..2877b2f 100644 --- a/sima/lib/meta.py +++ b/sima/lib/meta.py @@ -82,7 +82,9 @@ class Meta: self.__aliases = set() self.log = logging.getLogger(__name__) if 'name' not in kwargs or not kwargs.get('name'): - raise MetaException('Need a "name" argument') + raise MetaException('Need a "name" argument (str type)') + elif not isinstance(kwargs.get('name'), str): + raise MetaException('"name" argument not a string') else: self.__name = kwargs.pop('name') if 'mbid' in kwargs and kwargs.get('mbid'): diff --git a/tests/test_meta.py b/tests/test_meta.py index acdec38..a615a18 100644 --- a/tests/test_meta.py +++ b/tests/test_meta.py @@ -20,7 +20,7 @@ class TestMetaObject(unittest.TestCase): for args in [ {'mbid':VALID}, {'name': None}, - {}, + {'name': 42}, ]: with self.assertRaises(MetaException, msg='{} does not raise an except.'.format(args)): -- 2.39.5