Added unittest for exacution/resource.py
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 5 Mar 2013 14:03:11 +0000 (15:03 +0100)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 5 Mar 2013 14:03:11 +0000 (15:03 +0100)
src/neco/execution/attribute.py
src/neco/execution/resource.py
test/execution/resource.py [new file with mode: 0644]

index 9af394b..a24e76d 100644 (file)
@@ -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))
index 80ac444..39f96c6 100644 (file)
@@ -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 (file)
index 0000000..cbe2f95
--- /dev/null
@@ -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()
+