Пример #1
0
    def test_validator(self):
        def validate(value):
            if not isinstance(value, int):
                return "Not int"
            return None

        spec = plumpy.ValueSpec("valid_with_validator", validator=validate)

        self.assertIsNone(spec.validate(5))
        self.assertIsNotNone(spec.validate('s'))
Пример #2
0
    def test_required(self):
        spec = plumpy.ValueSpec("required_value", required=True)

        self.assertIsNotNone(spec.validate(plumpy.UNSPECIFIED))
        self.assertIsNone(spec.validate(5))
Пример #3
0
    def test_validate(self):
        spec = plumpy.ValueSpec("required_value", valid_type=int)

        self.assertIsNone(spec.validate(5))
        self.assertIsNotNone(spec.validate('a'))
Пример #4
0
    def test_required(self):
        s = plumpy.ValueSpec("required_value", required=True)

        self.assertFalse(s.validate(plumpy.UNSPECIFIED)[0])
        self.assertTrue(s.validate(5)[0])
Пример #5
0
    def test_validator(self):
        s = plumpy.ValueSpec("valid_with_validator",
                             validator=lambda x: isinstance(x, int))

        self.assertTrue(s.validate(5)[0])
        self.assertFalse(s.validate('s')[0])
Пример #6
0
    def test_validate(self):
        s = plumpy.ValueSpec("required_value", valid_type=int)

        self.assertTrue(s.validate(5)[0])
        self.assertFalse(s.validate('a')[0])