Пример #1
0
def test_invalid_mar_config_parameter_type():
    """Testing mar generation failure with invalid mar configs."""
    mar_config = "invalid_mar_config"
    tmp_dir = tempfile.mkdtemp()

    exception_msg = re.escape(
        f"mar_config must be of "
        f"type <class 'dict'> but received as {type(mar_config)}")
    with pytest.raises(TypeError, match=exception_msg):
        MarGeneration(mar_config=mar_config, mar_save_path=tmp_dir)
Пример #2
0
def test_invalid_mar_save_parameter_type(mar_config):
    """Test mar generation failure with invalid save path.

    Raises:
        TypeError: for passing invalid path type
    """
    mar_save_parameter = ["mar_save_path"]
    exception_msg = re.escape(
        f"mar_save_path must be of "
        f"type <class 'str'> but received as {type(mar_save_parameter)}")
    with pytest.raises(TypeError, match=exception_msg):
        MarGeneration(mar_config=mar_config, mar_save_path=mar_save_parameter)
Пример #3
0
def test_invalid_mar_config_parameter_value():
    """Test mar generation failure with empty mar config.

    Raises:
        ValueError: If mar config is empty.
    """
    mar_config = {}
    tmp_dir = tempfile.mkdtemp()

    exception_msg = re.escape(
        "mar_config is not optional. Received value: {}".format(mar_config))
    with pytest.raises(ValueError, match=exception_msg):
        MarGeneration(mar_config=mar_config, mar_save_path=tmp_dir)
Пример #4
0
def generate_mar_file(config, save_path):
    """Generates a mar file with proper configs
    Args:
        config : mar config dict
        save_path : mar file save path
    """
    MarGeneration(mar_config=config, mar_save_path=save_path)
    mar_path = os.path.join(save_path, "iris_classification.mar")
    config_properties = os.path.join(save_path, "config.properties")
    assert os.path.exists(mar_path)
    assert os.path.exists(config_properties)

    os.remove(mar_path)
    os.remove(config_properties)
Пример #5
0
def test_mar_generation_mandatory_params_missing(mar_config, mandatory_key):
    """Testing Mar Generation with missing mandatory keys.

    Args:
        mandatory_key : mandatory keys in mar config
    Raises:
        Exception : when mandatory keys are missing.
    """
    mar_config.pop(mandatory_key)

    tmp_dir = tempfile.mkdtemp()
    excpetion_msg = re.escape(
        f"Following Mandatory keys are "
        f"missing in the config file ['{mandatory_key}']")
    with pytest.raises(Exception, match=excpetion_msg):
        MarGeneration(mar_config=mar_config, mar_save_path=tmp_dir)
Пример #6
0
        "VERSION":
            "1",
        "EXPORT_PATH":
            CHECKPOINT_DIR,
        "CONFIG_PROPERTIES":
            os.path.join(cifar_dir, "config.properties"),
        "EXTRA_FILES":
            "{},{}".format(
                os.path.join(cifar_dir, "class_mapping.json"),
                os.path.join(cifar_dir, "classifier.py"),
            ),
        "REQUIREMENTS_FILE":
            os.path.join(cifar_dir, "requirements.txt"),
    }

    MarGeneration(mar_config=mar_config, mar_save_path=CHECKPOINT_DIR)

    classes = [
        "airplane",
        "automobile",
        "bird",
        "cat",
        "deer",
        "dog",
        "frog",
        "horse",
        "ship",
        "truck",
    ]

    # print(dir(trainer.ptl_trainer.model.module))
Пример #7
0
        "cifar10_test",
        "MODEL_FILE":
        os.path.join(cifar_dir, "cifar10_train.py"),
        "HANDLER":
        "image_classifier",
        "SERIALIZED_FILE":
        os.path.join(args["checkpoint_dir"], args["model_name"]),
        "VERSION":
        "1",
        "EXPORT_PATH":
        args["checkpoint_dir"],
        "CONFIG_PROPERTIES":
        "https://kubeflow-dataset.s3.us-east-2.amazonaws.com/config.properties",
    }

    MarGeneration(mar_config=mar_config, mar_save_path=args["checkpoint_dir"])

    classes = [
        "airplane",
        "automobile",
        "bird",
        "cat",
        "deer",
        "dog",
        "frog",
        "horse",
        "ship",
        "truck",
    ]

    # print(dir(trainer.ptl_trainer.model.module))
Пример #8
0
def test_mar_invalid_path(mar_config, key):
    mar_config[key] = "dummy"
    with pytest.raises(ValueError, match="No such file or directory"):
        MarGeneration(mar_config=mar_config)