예제 #1
0
 def test_safe_normalize_path_exception(self):
     """Test the method of safe_normalize_path with invalid prefix"""
     key = 'path'
     path = '/a/b'
     prefix = ['invalid']
     with pytest.raises(ValidationError) as info:
         safe_normalize_path(path, key, prefix, False, True)
     assert "The path is invalid!" in str(info.value)
예제 #2
0
def validate_path(summary_path):
    """
    Verify the summary path is valid or not.

    Args:
        summary_path (str): The summary path which is a dir.

    Raises:
        LineageParamValueError: If the input param value is invalid.
        LineageDirNotExistError: If the summary path is invalid.
    """
    try:
        summary_path = safe_normalize_path(summary_path,
                                           "summary_path",
                                           None,
                                           check_absolute_path=True)
    except ValidationError:
        log.error("The summary path is invalid.")
        raise LineageParamValueError("The summary path is invalid.")
    if not os.path.isdir(summary_path):
        log.error("The summary path does not exist or is not a dir.")
        raise LineageDirNotExistError(
            "The summary path does not exist or is not a dir.")

    return summary_path
예제 #3
0
    def test_safe_normalize_path(self, mock_validate_and_normalize_path,
                                 prefix):
        """Test the method of safe_normalize_path."""
        key = 'path'
        path = '/a/b'
        mock_validate_and_normalize_path.return_value = os.path.realpath(path)

        assert safe_normalize_path(path, key, prefix, False,
                                   True) == os.path.realpath(path)
예제 #4
0
def validate_file_path(file_path, allow_empty=False):
    """
    Verify that the file_path is valid.

    Args:
        file_path (str): Input file path.
        allow_empty (bool): Whether file_path can be empty.

    Raises:
        MindInsightException: If the parameters are invalid.
    """
    try:
        if allow_empty and not file_path:
            return
        safe_normalize_path(file_path,
                            raise_key='dataset_path',
                            safe_prefixes=None)
    except ValidationError as error:
        log.error(str(error))
        raise MindInsightException(error=LineageErrors.PARAM_FILE_PATH_ERROR,
                                   message=str(error))
예제 #5
0
    def _normalize_path(self, param_name, path):
        """Normalize config path."""
        path = os.path.realpath(path)
        try:
            path = safe_normalize_path(path,
                                       param_name,
                                       None,
                                       check_absolute_path=True)
        except ValidationError:
            logger.error("The %r is invalid.", param_name)
            raise ParamValueError("The %r is invalid." % param_name)

        return path
 def __init__(self, file_path):
     file_path = safe_normalize_path(file_path, 'lineage_summary_path', None)
     super(LineageSummaryAnalyzer, self).__init__(file_path)