コード例 #1
0
def _validate(file_paths):
    """
    _validate() runs tests on a list of file paths.

    :param file_paths: List of string file paths to test
    :raises ValidationException: if any validation tests fail
    :return: True if all validations pass
    """
    if all([is_not_empty(file_paths)]):
        return True
    else:
        raise ValidationException("File paths did not pass validation.")
コード例 #2
0
def validate_list_not_empty(extensions):
    """
    Returns True if the list provided is not empty.

    :param extensions: a list of string extensions
    :raises ValidationException:
    :return: True if extensions list is not empty. Raises a ValidationException
        otherwise
    """
    if len(extensions) > 0:
        return True
    else:
        raise ValidationException("You must provide at least one extension.")
コード例 #3
0
def validate_no_empty_strings(extensions):
    """
    Returns True if there are no empty strings in the list of extensions.

    :param extensions: a list of string extensions
    :raises ValidationException:
    :return: True if no empty strings in list of extensions, raises a
        ValidationException otherwise
    """
    if "" not in extensions:
        return True
    else:
        raise ValidationException("Empty strings are not valid extensions.")
コード例 #4
0
def validate_two_components(wrapper):
    """
    Make sure that the string defining the wrapper is formatted as two
    'words'. Basically, it should have the format "{open} {close}" with some
    form of white space between the opening and closing patterns. It should
    also have no more than two 'words'

    :param wrapper: String that defines a wrapper
    :raises ValidationException: if wrapper is not formatted correctly
    :return: True if the wrapper is formatted correctly
    """
    if len(wrapper.split()) != 2:
        raise ValidationException("Header demarcation must be of the form \n\t"
                                  "'{startpattern} {stoppattern}'\n"
                                  "(Note the space between the two patterns")
    return True
コード例 #5
0
def no_duplicate_tags(duplicate_tags):
    """
    Tests to make sure that the list of duplicate tags is empty.

    :param duplicate_tags: Dictionary mapping string file path keys to a list of
        tuples. The tuples contain the following information, in order:

        1. The string AnchorHub tag that was repeated
        2. The line in the file that the duplicate was found, as a number
        3. The string generated anchor that first used the repeated tag
    :raises ValidationException: If the list of duplicate tags is not empty
    :return: True if the list of duplicate tags is empty
    """
    if len(duplicate_tags) > 0:
        raise ValidationException("Duplicate tags found")
    else:
        return True
コード例 #6
0
def validate_overwrite_different_input_output(opts):
    """
    Make sure that if overwrite is set to False, the input and output folders
    are not set to the same location.

    :param opts: a namespace containing the attributes 'overwrite', 'input',
        and 'output'
    :raises ValidationException: if 'input' and 'output' point to the same
        directory and 'overwrite' is set to False
    :return: True if 'overwrite' is set to True, or 'input'/'output' are
        separate directories
    """
    if opts.overwrite or path.abspath(opts.input) != path.abspath(opts.output):
        return True
    else:
        raise ValidationException(
            "Input and output directories are the same, "
            "but --overwrite / -X flag is not provided.\n"
            "Do you want to overwrite your input files? "
            "If so, use the following command:\n"
            "\tanchorhub -X " + opts.input)
コード例 #7
0
def _validate(anchors, duplicate_tags, opts):
    """
    Runs set of validations on collected AnchorHub tags and generated anchors

    :param anchors: Dictionary mapping string file path keys to dictionary
        values. The inner dictionaries map string AnchorHub tags to generated
        anchor values
    :param duplicate_tags: Dictionary mapping string file path keys to a list of
        tuples. The tuples contain the following information, in order:

        1. The string AnchorHub tag that was repeated
        2. The line in the file that the duplicate was found, as a number
        3. The string generated anchor that first used the repeated tag
    :param opts: Namespace containing AnchorHub options, usually created by
        command line arguments
    :raises ValidationException: if any of the validations fail
    :return: True if the anchors pass all validation tests
    """
    if all([no_duplicate_tags(duplicate_tags)]):
        return True
    else:
        raise ValidationException("File paths did not pass validation.")