From: Alina Quereilhac Date: Tue, 5 Mar 2013 14:03:11 +0000 (+0100) Subject: Added unittest for exacution/resource.py X-Git-Tag: nepi-3.0.0~122^2~25 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=bac4a9624ee449834d531a211fe7430b571b2c7a;p=nepi.git Added unittest for exacution/resource.py --- diff --git a/src/neco/execution/attribute.py b/src/neco/execution/attribute.py index 9af394b6..a24e76d0 100644 --- a/src/neco/execution/attribute.py +++ b/src/neco/execution/attribute.py @@ -54,7 +54,6 @@ class Attribute(object): def set_value(self, value): if self.is_valid_value(value): self._value = value - self._modified = True else: raise ValueError("Invalid value %s for attribute %s" % (str(value), self.name)) diff --git a/src/neco/execution/resource.py b/src/neco/execution/resource.py index 80ac444b..39f96c68 100644 --- a/src/neco/execution/resource.py +++ b/src/neco/execution/resource.py @@ -108,6 +108,9 @@ class Resource(object): def set_after(self, name, value, time, after_status, guid): pass + def next_step(self): + pass + def stop(self): pass diff --git a/test/execution/resource.py b/test/execution/resource.py new file mode 100644 index 00000000..cbe2f951 --- /dev/null +++ b/test/execution/resource.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python +from neco.execution.resource import Resource, ResourceFactory, clsinit +from neco.execution.attribute import Attribute + +import unittest + +@clsinit +class MyResource(Resource): + _rtype = "MyResource" + + @classmethod + def _register_attributes(cls): + cool_attr = Attribute("my_attr", "is a really nice attribute!") + cls._register_attribute(cool_attr) + + def __init__(self, ec, guid): + super(MyResource, self).__init__(ec, guid) + +@clsinit +class AnotherResource(Resource): + _rtype = "AnotherResource" + + def __init__(self, ec, guid): + super(AnotherResource, self).__init__(ec, guid) + +class EC(object): + pass + + +class ResourceTestCase(unittest.TestCase): + def test_add_resource_factory(self): + ResourceFactory.register_type(MyResource) + ResourceFactory.register_type(AnotherResource) + + self.assertEquals(MyResource.rtype(), "MyResource") + self.assertEquals(len(MyResource._attributes), 1) + + self.assertEquals(Resource.rtype(), "Resource") + self.assertEquals(len(Resource._attributes), 0) + + self.assertEquals(AnotherResource.rtype(), "AnotherResource") + self.assertEquals(len(AnotherResource._attributes), 0) + + self.assertEquals(len(ResourceFactory.resource_types()), 2) + +if __name__ == '__main__': + unittest.main() +