2 from neco.execution.resource import ResourceManager, ResourceFactory, clsinit
3 from neco.execution.attribute import Attribute
8 class MyResource(ResourceManager):
12 def _register_attributes(cls):
13 cool_attr = Attribute("my_attr", "is a really nice attribute!")
14 cls._register_attribute(cool_attr)
16 def __init__(self, ec, guid):
17 super(MyResource, self).__init__(ec, guid)
20 class AnotherResource(ResourceManager):
21 _rtype = "AnotherResource"
23 def __init__(self, ec, guid):
24 super(AnotherResource, self).__init__(ec, guid)
29 class ResourceFactoryTestCase(unittest.TestCase):
30 def test_add_resource_factory(self):
31 ResourceFactory.register_type(MyResource)
32 ResourceFactory.register_type(AnotherResource)
34 self.assertEquals(MyResource.rtype(), "MyResource")
35 self.assertEquals(len(MyResource._attributes), 1)
37 self.assertEquals(Resource.rtype(), "Resource")
38 self.assertEquals(len(Resource._attributes), 0)
40 self.assertEquals(AnotherResource.rtype(), "AnotherResource")
41 self.assertEquals(len(AnotherResource._attributes), 0)
43 self.assertEquals(len(ResourceFactory.resource_types()), 2)
46 class ResourceManagerTestCase(unittest.TestCase):
47 def test_start_with_condition(self):
50 def test_stop_with_condition(self):
53 def test_set_with_condition(self):
57 if __name__ == '__main__':