예제 #1
0
def test_wrongfiletype_validate_single_file():
    """
    Tests that if there is no filetype for the filename passed
    in, an error is thrown
    """
    entitylist = [WRONG_NAME_ENT]
    expected_error = ('----------------ERRORS----------------\n'
                      'Your filename is incorrect! Please change your '
                      'filename before you run the validator or specify '
                      '--filetype if you are running the validator locally')

    with patch.object(validate.GenieValidationHelper,
                      "determine_filetype",
                      return_value=None) as mock_determine_filetype:
        validator = validate.GenieValidationHelper(
            syn=syn,
            project_id=None,
            center=CENTER,
            entitylist=entitylist,
            format_registry={'wrong': Mock()})
        valid, message = validator.validate_single_file()

        assert message == expected_error
        assert not valid
        mock_determine_filetype.assert_called_once_with()
예제 #2
0
def test_perfect_determine_filetype(filename_fileformat_map):
    '''
    Tests determining of file type through filenames
    Parameters are passed in from filename_fileformat_map
    '''
    (filepath_list, fileformat) = filename_fileformat_map
    validator = validate.GenieValidationHelper(syn, center, filepath_list)

    assert validator.determine_filetype() == fileformat
예제 #3
0
def test_wrongfilename_noerror_determine_filetype():
    '''
    Tests None is passed back when wrong filename is passed
    when raise_error flag is False
    '''
    filepathlist = ['wrong.txt']
    validator = validate.GenieValidationHelper(syn,
                                               center=center,
                                               filepathlist=filepathlist)

    assert validator.file_type is None
예제 #4
0
def test_filetype_validate_single_file():
    '''
    Tests that if filetype is passed in that an error is thrown
    if it is an incorrect filetype
    '''
    filepathlist = ['clinical.txt']
    center = "SAGE"
    expected_error = "----------------ERRORS----------------\nYour filename is incorrect! Please change your filename before you run the validator or specify --filetype if you are running the validator locally"
    validator = validate.GenieValidationHelper(syn, center, filepathlist)

    valid, message, filetype = validator.validate_single_file()
    assert message == expected_error
예제 #5
0
def test_perfect_determine_filetype():
    """
    Tests determining of file type through filenames
    Parameters are passed in from filename_fileformat_map
    """
    filetype = "clincial"
    ent_list = [SAMPLE_ENT]
    with patch.object(FileFormat, "validateFilename", return_value=filetype):
        validator = validate.GenieValidationHelper(
            syn,
            None,
            CENTER,
            ent_list,
            format_registry={filetype: FileFormat})
        assert validator.determine_filetype() == filetype
예제 #6
0
def test_wrongfilename_noerror_determine_filetype():
    '''
    Tests None is passed back when wrong filename is passed
    when raise_error flag is False
    '''
    ent_list = [WRONG_NAME_ENT]
    with patch.object(FileFormat,
                      "validateFilename",
                      side_effect=AssertionError):
        validator = validate.GenieValidationHelper(
            syn,
            project_id=None,
            center=CENTER,
            entitylist=ent_list,
            format_registry={"wrong": FileFormat})
        assert validator.file_type is None
예제 #7
0
def test_wrongfiletype_validate_single_file():
    '''
    Tests that if there is no filetype for the filename passed
    in, an error is thrown
    '''
    filepathlist = ['clinical.txt']
    center = "SAGE"
    expected_error = '----------------ERRORS----------------\nYour filename is incorrect! Please change your filename before you run the validator or specify --filetype if you are running the validator locally'

    with mock.patch("genie.validate.GenieValidationHelper.determine_filetype",
                    return_value=None) as mock_determine_filetype:
        validator = validate.GenieValidationHelper(syn=syn,
                                                   center=center,
                                                   filepathlist=filepathlist)
        valid, message, filetype = validator.validate_single_file()

        assert message == expected_error
        mock_determine_filetype.assert_called_once_with()
예제 #8
0
def test_valid_validate_single_file():
    """
    Tests that all the functions are run in validate single
    file workflow and all the right things are returned
    """
    entitylist = [CLIN_ENT]
    error_string = ''
    warning_string = ''
    expected_valid = True
    expected_message = "valid message here!"
    expected_filetype = "clinical"
    project_ent = Mock(id='syn1234')
    with patch.object(syn, "get", return_value=project_ent),\
         patch.object(validate.GenieValidationHelper,
                      "determine_filetype",
                      return_value=expected_filetype) as mock_determine_ftype,\
         patch.object(FileFormat, "validate",
                      return_value=(expected_valid, error_string,
                                    warning_string)) as mock_genie_class,\
         patch.object(validate, "collect_errors_and_warnings",
                      return_value=expected_message) as mock_determine:
        validator = validate.GenieValidationHelper(
            syn,
            project_id="syn1234",
            center=CENTER,
            entitylist=entitylist,
            format_registry={'clinical': FileFormat})
        valid, message = validator.validate_single_file(oncotree_link=None,
                                                        nosymbol_check=False)

        assert valid == expected_valid
        assert message == expected_message
        assert validator.file_type == expected_filetype

        mock_determine_ftype.assert_called_once_with()

        mock_genie_class.assert_called_once_with(filePathList=[CLIN_ENT.path],
                                                 oncotree_link=None,
                                                 nosymbol_check=False,
                                                 project_id='syn1234')

        mock_determine.assert_called_once_with(error_string, warning_string)
예제 #9
0
def test_valid_validate_single_file():
    '''
    Tests that all the functions are run in validate single
    file workflow and all the right things are returned
    '''
    filepathlist = ['clinical.txt']
    error_string = ''
    warning_string = ''
    center = 'SAGE'
    expected_valid = True
    expected_message = "valid message here!"
    expected_filetype = "clinical"


    with mock.patch(
            "genie.validate.GenieValidationHelper.determine_filetype",
            return_value=expected_filetype) as mock_determine_filetype,\
        mock.patch(
            "genie.clinical.clinical.validate",
            return_value=(expected_valid, error_string, warning_string)) as mock_genie_class,\
        mock.patch(
            "genie.validate.collect_errors_and_warnings",
            return_value=expected_message) as mock_determine:

        validator = validate.GenieValidationHelper(syn,
                                                   center=center,
                                                   filepathlist=filepathlist)

        valid, message, filetype = validator.validate_single_file(
            oncotree_link=None, nosymbol_check=False)

        assert valid == expected_valid
        assert message == expected_message
        assert filetype == expected_filetype

        mock_determine_filetype.assert_called_once_with()

        mock_genie_class.assert_called_once_with(filePathList=filepathlist,
                                                 oncotree_link=None,
                                                 nosymbol_check=False)

        mock_determine.assert_called_once_with(error_string, warning_string)
예제 #10
0
def test_filetype_validate_single_file():
    """
    Tests that if filetype is passed in that an error is thrown
    if it is an incorrect filetype
    """
    entitylist = [WRONG_NAME_ENT]
    expected_error = ("----------------ERRORS----------------\n"
                      "Your filename is incorrect! Please change your "
                      "filename before you run the validator or specify "
                      "--filetype if you are running the validator locally")

    with patch.object(FileFormat,
                      "validateFilename",
                      side_effect=AssertionError):
        validator = validate.GenieValidationHelper(
            syn,
            None,
            CENTER,
            entitylist,
            format_registry={'wrong': FileFormat})

        valid, message = validator.validate_single_file()
        assert message == expected_error
        assert not valid