Exemple #1
0
 def __check_type_of_field(self, field_name):
     """
     This function checks each given field values and determines the "type" of values.
     These could be in the form of "source:..., template:...", which means we need to
     iterate through source file and extract the fields. The other type is where fields
     are manually iterated in the config file, in the form of 1..., 2..., 3...
     :return: source_type (iterable, non_iterable), source (source_path, None), template (template_path, None)
     """
     # If True it means we have to extract data from iterable.
     try:
         if ('source' and 'template') in self.content[field_name]:
             source_type = 'iterable'
             source = self.content[field_name]['source']
             template = self.content[field_name]['template']
             sexists, _, sourcef, source_io_object = check_if_path_exists(source)
             texists, _, templatef, template_io_object = check_if_path_exists(template)
             
             if sexists and texists:
                 pass
             else:
                 # TODO logging!
                 raise SystemExit("%s and %s does not exist" % (source, template))
         
         else:
             source_type = 'non_iterable'
             source_io_object = io.StringIO()
             template_io_object = io.StringIO()
         
         return source_type, source_io_object, template_io_object
     except KeyError:
         # It means that yaml does not contain this field (e.g. Station, or Observable).
         # That is because metadata are PROBABLY stored in input files (preamble)
         return None, None, None
Exemple #2
0
def test_check_if_path_exists_non_existing_folder():
    # Tests a non-existing folder
    test_filename4 = os.path.join(test_resources, 'doesnt_exist_folder')
    test_output4 = check_if_path_exists(test_filename4)
    desired_output4 = (False, None, None, None)

    assert test_output4 == desired_output4
Exemple #3
0
def test_check_if_path_exists_existing_folder():
    # Tests an existing folder
    test_filename3 = os.path.join(test_resources, 'inputs')
    test_output3 = check_if_path_exists(test_filename3)
    desired_output3 = (True, InputType.FOLDER, test_filename3, None)

    assert test_output3 == desired_output3
Exemple #4
0
def test_check_if_path_exists_non_existing_file():
    # Tests a non-existing file
    test_filename2 = os.path.join(test_resources, 'inputs',
                                  'it_doesnt_exist.gr')
    test_output2 = check_if_path_exists(test_filename2)
    desired_output2 = (False, None, None, None)

    assert test_output2 == desired_output2
Exemple #5
0
def test_check_if_path_exists_correct():
    # Tests an existing file
    test_filename1 = os.path.join(test_resources, 'inputs', 'Agmip.csv')
    test_exists, test_typ, test_filename, _ = check_if_path_exists(
        test_filename1)
    desired_output1 = (True, InputType.FILE, test_filename1)

    assert (test_exists, test_typ, test_filename) == desired_output1
Exemple #6
0
def handle_input_files(filename):
    if filename == "":
        # User didn't provide a template... Are we going to check every template?
        pass
    else:
        exists, file_type, file_path, file_object = check_if_path_exists(filename=filename)
        if exists:
            return file_path, file_object
        else:
            click.echo("%s does not exist" % filename)
            raise SystemExit(0)