def test_passing_params_to_no_io_overrides_polyaxonfiles_raises(self):
     polyaxonfile = PolyaxonFile(
         os.path.abspath("tests/fixtures/plain/simple_job.yml"))
     with self.assertRaises(PolyaxonfileError):
         polyaxonfile.get_op_specification(params={
             "flag": True,
             "loss": "some-loss"
         })
    def test_required_inputs_with_params(self):
        plxfile = PolyaxonFile(
            os.path.abspath("tests/fixtures/typing/required_inputs.yml"))
        spec = plxfile.specification
        with self.assertRaises(PolyaxonfileError):
            spec.apply_context()

        assert spec.config.inputs[0].value is None
        assert spec.config.inputs[1].value is None
        spec.apply_params(params={"loss": "bar", "flag": False})
        assert spec.config.inputs[0].value == "bar"
        assert spec.config.inputs[1].value is False
        spec = spec.apply_context()
        spec = spec.apply_container_contexts()
        assert spec.version == 0.6
        assert spec.tags == ["foo", "bar"]
        assert spec.container.image == "my_image"
        assert spec.container.command == ["/bin/sh", "-c"]
        assert spec.container.args == "video_prediction_train --loss=bar "
        assert spec.environment is None
        assert spec.is_component

        plxfile = PolyaxonFile(
            os.path.abspath("tests/fixtures/typing/required_inputs.yml"))
        spec = plxfile.specification
        assert spec.config.inputs[0].value is None
        assert spec.config.inputs[1].value is None
        spec.apply_params(params={"loss": "bar", "flag": True})
        assert spec.config.inputs[0].value == "bar"
        assert spec.config.inputs[1].value is True
        spec = spec.apply_context()
        spec = spec.apply_container_contexts()
        assert spec.version == 0.6
        assert spec.tags == ["foo", "bar"]
        assert spec.container.image == "my_image"
        assert spec.container.command == ["/bin/sh", "-c"]
        assert spec.container.args == "video_prediction_train --loss=bar --flag"
        assert spec.environment is None
        assert spec.is_component

        # Adding extra value raises
        with self.assertRaises(PolyaxonfileError):
            spec.validate_params(params={
                "loss": "bar",
                "flag": True,
                "value": 1.1
            })
        with self.assertRaises(PolyaxonfileError):
            polyaxonfile = PolyaxonFile(
                os.path.abspath("tests/fixtures/typing/required_inputs.yml"))
            polyaxonfile.get_op_specification(params={
                "loss": "bar",
                "value": 1.1
            })

        # Adding non valid params raises
        with self.assertRaises(PolyaxonfileError):
            spec.validate_params(params={"value": 1.1})
Exemple #3
0
def check_polyaxonfile(polyaxonfile,
                       params=None,
                       profile=None,
                       queue=None,
                       nocache=None,
                       log=True):
    if not polyaxonfile:
        polyaxonfile = PolyaxonFile.check_default_path(path=".")
    if not polyaxonfile:
        polyaxonfile = ""

    polyaxonfile = to_list(polyaxonfile)
    exists = [os.path.isfile(f) for f in polyaxonfile]

    parsed_params = None
    if params:
        parsed_params = parse_params(params)

    if not any(exists):
        Printer.print_error("Polyaxonfile is not present, "
                            "please run {}".format(constants.INIT_COMMAND))
        sys.exit(1)

    try:
        plx_file = PolyaxonFile(polyaxonfile)
        plx_file = plx_file.get_op_specification(params=parsed_params,
                                                 profile=profile,
                                                 queue=queue,
                                                 nocache=nocache)
        if log:
            Printer.print_success("Polyaxonfile valid")
        return plx_file
    except Exception as e:
        handle_cli_error(e, message="Polyaxonfile is not valid.")
        sys.exit(1)
 def test_passing_wrong_params_raises(self):
     with self.assertRaises(PolyaxonfileError):
         polyaxonfile = PolyaxonFile(
             os.path.abspath("tests/fixtures/plain/simple_job.yml"))
         polyaxonfile.get_op_specification(params="foo")
    def test_required_inputs_with_params(self):
        run_config = V1CompiledOperation.read([
            reader.read(
                os.path.abspath("tests/fixtures/typing/required_inputs.yml")),
            {
                "kind": "compiled_operation"
            },
        ])

        with self.assertRaises(ValidationError):
            CompiledOperationSpecification.apply_context(run_config)

        assert run_config.inputs[0].value is None
        assert run_config.inputs[1].value is None
        run_config.apply_params(params={
            "loss": {
                "value": "bar"
            },
            "flag": {
                "value": False
            }
        })
        assert run_config.inputs[0].value == "bar"
        assert run_config.inputs[1].value is False
        run_config = CompiledOperationSpecification.apply_context(run_config)
        run_config = CompiledOperationSpecification.apply_run_contexts(
            run_config)
        assert run_config.version == 1.05
        assert run_config.tags == ["foo", "bar"]
        assert run_config.run.container.image == "my_image"
        assert run_config.run.container.command == ["/bin/sh", "-c"]
        assert run_config.run.container.args == "video_prediction_train --loss=bar "

        run_config = V1CompiledOperation.read([
            reader.read(
                os.path.abspath("tests/fixtures/typing/required_inputs.yml")),
            {
                "kind": "compiled_operation"
            },
        ])

        assert run_config.inputs[0].value is None
        assert run_config.inputs[1].value is None
        run_config.apply_params(params={
            "loss": {
                "value": "bar"
            },
            "flag": {
                "value": True
            }
        })
        assert run_config.inputs[0].value == "bar"
        assert run_config.inputs[1].value is True
        run_config = CompiledOperationSpecification.apply_context(run_config)
        run_config = CompiledOperationSpecification.apply_run_contexts(
            run_config)
        assert run_config.version == 1.05
        assert run_config.tags == ["foo", "bar"]
        assert run_config.run.container.image == "my_image"
        assert run_config.run.container.command == ["/bin/sh", "-c"]
        assert (run_config.run.container.args ==
                "video_prediction_train --loss=bar --flag")

        # Adding extra value raises
        with self.assertRaises(ValidationError):
            run_config.validate_params(
                params={
                    "loss": {
                        "value": "bar"
                    },
                    "flag": {
                        "value": True
                    },
                    "value": {
                        "value": 1.1
                    },
                })
        with self.assertRaises(ValidationError):
            polyaxonfile = PolyaxonFile(
                os.path.abspath("tests/fixtures/typing/required_inputs.yml"))
            polyaxonfile.get_op_specification(params={
                "loss": {
                    "value": "bar"
                },
                "value": {
                    "value": 1.1
                }
            }, )

        # Adding non valid params raises
        with self.assertRaises(ValidationError):
            run_config.validate_params(params={"value": {"value": 1.1}})