Exemplo n.º 1
0
    def test_io_config_default(self):
        config_dict = {
            "name": "input1",
            "description": "some text",
            "type": types.BOOL,
            "isOptional": True,
            "value": True,
        }
        config = V1IO.from_dict(config_dict)
        assert_equal_dict(config.to_dict(), config_dict)
        expected_repr = OrderedDict(
            (("name", "input1"), ("type", "bool"), ("value", True)))
        assert config.get_repr_from_value(None) == expected_repr
        assert config.get_repr() == expected_repr

        config_dict = {
            "name": "input1",
            "description": "some text",
            "type": types.FLOAT,
            "isOptional": True,
            "value": 3.4,
        }
        config = V1IO.from_dict(config_dict)
        assert_equal_dict(config.to_dict(), config_dict)
        expected_repr = OrderedDict(
            (("name", "input1"), ("type", "float"), ("value", 3.4)))
        assert config.get_repr_from_value(None) == expected_repr
        assert config.get_repr() == expected_repr
Exemplo n.º 2
0
    def test_io_config_types(self):
        config_dict = {
            "name": "input1",
            "description": "some text",
            "type": types.INT
        }
        config = V1IO.from_dict(config_dict)
        assert_equal_dict(config.to_dict(), config_dict)
        expected_repr = OrderedDict(
            (("name", "input1"), ("type", "int"), ("value", 3)))
        assert config.get_repr_from_value(3) == expected_repr
        assert config.get_repr() == OrderedDict(
            (("name", "input1"), ("type", "int")))

        config_dict = {
            "name": "input1",
            "description": "some text",
            "type": types.S3
        }
        config = V1IO.from_dict(config_dict)
        assert_equal_dict(config.to_dict(), config_dict)
        expected_repr = OrderedDict(
            (("name", "input1"), ("type", types.S3), ("value", "s3://foo")))
        assert config.get_repr_from_value("s3://foo") == expected_repr
        assert config.get_repr() == OrderedDict(
            (("name", "input1"), ("type", types.S3)))
Exemplo n.º 3
0
    def test_wrong_io_config_default(self):
        with self.assertRaises(ValidationError):
            V1IO.from_dict({
                "name": "input1",
                "type": types.FLOAT,
                "value": "foo"
            })

        with self.assertRaises(ValidationError):
            V1IO.from_dict({"name": "input1", "type": types.GCS, "value": 234})
Exemplo n.º 4
0
    def test_wrong_io_config_flag(self):
        with self.assertRaises(ValidationError):
            V1IO.from_dict({
                "name": "input1",
                "type": types.S3,
                "isFlag": True
            })

        with self.assertRaises(ValidationError):
            V1IO.from_dict({
                "name": "input1",
                "type": types.FLOAT,
                "isFlag": True
            })
Exemplo n.º 5
0
    def test_value_non_typed_input(self):
        config_dict = {"name": "input1"}
        config = V1IO.from_dict(config_dict)
        assert config.validate_value("foo") == "foo"
        assert config.validate_value(1) == 1
        assert config.validate_value(True) is True

        expected_repr = OrderedDict((("name", "input1"), ("value", "foo")))
        assert config.get_repr_from_value("foo") == expected_repr
        assert config.get_repr() == OrderedDict(name="input1")
Exemplo n.º 6
0
    def test_io_config_default_and_required(self):
        config_dict = {
            "name": "input1",
            "description": "some text",
            "type": types.BOOL,
            "value": True,
            "isOptional": True,
        }
        config = V1IO.from_dict(config_dict)
        assert_equal_dict(config.to_dict(), config_dict)

        config_dict = {
            "name": "input1",
            "description": "some text",
            "type": types.STR,
            "value": "foo",
        }
        with self.assertRaises(ValidationError):
            V1IO.from_dict(config_dict)
Exemplo n.º 7
0
    def test_value_typed_input(self):
        config_dict = {"name": "input1", "type": types.BOOL}
        config = V1IO.from_dict(config_dict)
        with self.assertRaises(ValidationError):
            config.validate_value("foo")
        with self.assertRaises(ValidationError):
            config.validate_value(1)
        with self.assertRaises(ValidationError):
            config.validate_value(None)

        assert config.validate_value(True) is True
Exemplo n.º 8
0
 def test_io_config_flag(self):
     config_dict = {
         "name": "input1",
         "description": "some text",
         "type": types.BOOL,
         "isFlag": True,
     }
     config = V1IO.from_dict(config_dict)
     assert_equal_dict(config.to_dict(), config_dict)
     expected_repr = OrderedDict(
         (("name", "input1"), ("type", "bool"), ("value", False)))
     assert config.get_repr_from_value(False) == expected_repr
Exemplo n.º 9
0
 def test_io_config_required(self):
     config_dict = {
         "name": "input1",
         "description": "some text",
         "type": "float",
         "isOptional": False,
     }
     config = V1IO.from_dict(config_dict)
     assert_equal_dict(config.to_dict(), config_dict)
     expected_repr = OrderedDict(
         (("name", "input1"), ("type", "float"), ("value", 1.1)))
     assert config.get_repr_from_value(1.1) == expected_repr
     assert config.get_repr() == OrderedDict(
         (("name", "input1"), ("type", "float")))
Exemplo n.º 10
0
    def test_io_name_blacklist(self):
        config_dict = {"name": "params"}
        with self.assertRaises(ValidationError):
            V1IO.from_dict(config_dict)

        config_dict = {"name": "globals"}
        with self.assertRaises(ValidationError):
            V1IO.from_dict(config_dict)

        config_dict = {"name": "connections"}
        with self.assertRaises(ValidationError):
            V1IO.from_dict(config_dict)
Exemplo n.º 11
0
    def test_value_typed_input_with_default(self):
        config_dict = {
            "name": "input1",
            "type": types.INT,
            "value": 12,
            "isOptional": True,
        }
        config = V1IO.from_dict(config_dict)
        with self.assertRaises(ValidationError):
            config.validate_value("foo")

        assert config.validate_value(1) == 1
        assert config.validate_value(0) == 0
        assert config.validate_value(-1) == -1
        assert config.validate_value(None) == 12
        expected_repr = OrderedDict(
            (("name", "input1"), ("type", "int"), ("value", 12)))
        assert config.get_repr_from_value(None) == expected_repr
        assert config.get_repr() == expected_repr
Exemplo n.º 12
0
 def test_io_config_desc(self):
     # test desc
     config_dict = {"name": "input1", "description": "some text"}
     config = V1IO.from_dict(config_dict)
     assert_equal_dict(config.to_dict(), config_dict)
Exemplo n.º 13
0
 def test_io_config_optionals(self):
     config_dict = {"name": "input1"}
     config = V1IO.from_dict(config_dict)
     assert_equal_dict(config.to_dict(), config_dict)
Exemplo n.º 14
0
 def test_unsupported_io_config_type(self):
     with self.assertRaises(ValidationError):
         V1IO.from_dict({"name": "input1", "type": "something"})
Exemplo n.º 15
0
 def test_wrong_io_config(self):
     # No name
     with self.assertRaises(ValidationError):
         V1IO.from_dict({})