Ejemplo n.º 1
0
    def testSpec_toDict(self):
        x = Spec(description="123", singleNodeOnly=True)
        d = x.toDict()
        self.assertEqual(d["description"], "123")
        self.assertTrue(d["singleNodeOnly"])
        self.assertTrue(d["inputs"] == d["outputs"] == d["parameters"] ==
                        d["commands"] == {})

        x.inputs = dict(i1=InputSpec(dataType="int"),
                        i2=InputSpec(dataType="str", isDefaultInput=True))
        x.outputs = dict(o=OutputSpec(dataType="float", count=8))
        x.parameters = dict(p=ParameterSpec(description="param",
                                            dataType="float",
                                            defaultValue=3.14,
                                            accessMode="Create"))

        d = x.toDict()
        inputs = d["inputs"]
        self.assertEqual(len(inputs), 2)
        i1 = inputs["i1"]
        self.assertEqual(i1["count"], 1)
        self.assertFalse(i1["isDefaultInput"])
        self.assertEqual(i1["description"], "")
        self.assertEqual(i1["dataType"], "int")
        self.assertFalse(i1["required"])
        self.assertTrue(i1["requireSplitterMap"])
        self.assertFalse(i1["regionLevel"])

        i2 = inputs["i2"]
        self.assertEqual(i2["count"], 1)
        self.assertTrue(i2["isDefaultInput"])
        self.assertEqual(i2["description"], "")
        self.assertEqual(i2["dataType"], "str")
        self.assertFalse(i2["required"])
        self.assertTrue(i2["requireSplitterMap"])
        self.assertFalse(i2["regionLevel"])

        outputs = d["outputs"]
        self.assertEqual(len(outputs), 1)
        o = outputs["o"]
        self.assertEqual(o["count"], 8)
        self.assertFalse(o["isDefaultOutput"])
        self.assertEqual(o["description"], "")
        self.assertEqual(o["dataType"], "float")
        self.assertFalse(o["regionLevel"])

        parameters = d["parameters"]
        self.assertEqual(len(parameters), 1)
        p = parameters["p"]
        self.assertEqual(p["description"], "param")
        self.assertEqual(p["dataType"], "float")
        self.assertEqual(p["accessMode"], "Create")
        self.assertEqual(p["defaultValue"], 3.14)
        self.assertEqual(p["count"], 1)
        self.assertEqual(p["constraints"], "")

        self.assertEqual(d["commands"], {})
Ejemplo n.º 2
0
    def testInvalidParameterSpec(self):
        with self.assertRaises(Exception):
            _x = ParameterSpec()

        with self.assertRaises(Exception):
            _x = ParameterSpec(dataType="int",
                               count=4,
                               defaultValue="not an int")

        with self.assertRaises(Exception):
            _x = ParameterSpec(description=555, dataType="int")

        with self.assertRaises(Exception):
            _x = ParameterSpec(dataType="int", accessMode="no such mode")

        with self.assertRaises(Exception):
            _x = ParameterSpec(dataType="int",
                               defaultValue=5,
                               accessMode="Read")
Ejemplo n.º 3
0
    def testValidParameterSpec(self):
        try:
            x = ParameterSpec(dataType="int", accessMode="Read")
            x.invariant()

            x = ParameterSpec(description="description",
                              dataType="int",
                              count=3,
                              defaultValue=-6,
                              accessMode="Create")
            x.invariant()
        except:
            self.fail("Got unexpected exception")
Ejemplo n.º 4
0
  def testValidParameterSpec(self):
    try:
      x = ParameterSpec(dataType="int", accessMode="Read")
      x.invariant()

      x = ParameterSpec(description="description",
                    dataType="int",
                    count=3,
                    defaultValue=-6,
                    accessMode="Create")
      x.invariant()
    except:
      self.fail("Got unexpected exception")