rally/tests/unit/common/plugin/test_meta.py
Boris Pavlovic 31e43bc112 Further improvment of plugin base
*) Introduce meta class that allows to bind meta data to class
   Like we have for context order and hidden, for scenarios validation
   types and so on.

   In near future all plugin will use meta stuff for storing
   infomration required for: validation, types, rally-info stuff

*) Make base Plugin class subclass of MetaMixin

*) Rename plugin -> configure decorator

*) Make configure() and deprecated() work for all objects
  (not only subclasses of Plugin)

*) Add from_func decorator that makes functional look like plugin

*) Add support of plugins namespace

Change-Id: I160a0021bc0e2da9aa43e26286c4e0491340fa51
2015-06-09 16:54:13 +03:00

65 lines
1.8 KiB
Python

# Copyright 2015: Mirantis Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from rally.common.plugin import meta
from tests.unit import test
class TestMetaMixinTestCase(test.TestCase):
def test_meta_is_inited(self):
class Meta(meta.MetaMixin):
pass
self.assertRaises(ReferenceError, Meta._meta_is_inited)
self.assertFalse(Meta._meta_is_inited(raise_exc=False))
Meta._meta_init()
self.assertTrue(Meta._meta_is_inited())
self.assertTrue(Meta._meta_is_inited(raise_exc=False))
def test_meta_set_and_get(self):
class Meta(meta.MetaMixin):
pass
Meta._meta_init()
Meta._meta_set("aaa", 42)
self.assertEqual(Meta._meta_get("aaa"), 42)
def test_meta_get_default(self):
class Meta(meta.MetaMixin):
pass
Meta._meta_init()
self.assertEqual(Meta._meta_get("b", 42), 42)
def test_meta_get_if_is_not_inited(self):
class Meta(meta.MetaMixin):
pass
self.assertRaises(ReferenceError, Meta._meta_get, "any")
def test_meta_set_if_is_not_inited(self):
class Meta(meta.MetaMixin):
pass
self.assertRaises(ReferenceError, Meta._meta_set, "a", 1)