Esempio n. 1
0
    def test_files_method(self):
        ''' A file creator .files method should only return files that are valid combinations exist. '''

        cons_set = set([Constraint('model', ['ACCESS1-0', 'ACCESS1-3']),
                        Constraint('experiment', ['rcp45', 'rcp85'])])
        
        this_file_creator = FileCreator("/a/fake/pattern/%model%_%experiment%.nc",
                                        extra_constraints=cons_set)
        
        # Now tell the file creator which files are real!
        # ACCESS1-3 has no rcp85 experiment in this case.
        file_1 = this_file_creator.get_files({'model': 'ACCESS1-0',
                                              'experiment': 'rcp45'},
                                             check=False, update=True)
        
        file_2 = this_file_creator.get_files({'model': 'ACCESS1-0',
                                              'experiment': 'rcp85'},
                                             check=False, update=True)

        file_3 = this_file_creator.get_files({'model': 'ACCESS1-3',
                                              'experiment': 'rcp45'},
                                             check=False, update=True)

        # Ensure that the FileCreator has returned a file
        # for each combination.
        for file_thing in [file_1, file_2, file_3]:
            self.assertTrue(file_thing)

        all_files = [file_thing for file_thing in this_file_creator.files]
        # There should only be 3 valid file combinations returned.
        self.assertEqual(len(all_files), 3)
Esempio n. 2
0
    def test_files_method(self):
        ''' A file creator .files method should only return files that are valid combinations exist. '''

        cons_set = set([
            Constraint('model', ['ACCESS1-0', 'ACCESS1-3']),
            Constraint('experiment', ['rcp45', 'rcp85'])
        ])

        this_file_creator = FileCreator(
            "/a/fake/pattern/%model%_%experiment%.nc",
            extra_constraints=cons_set)

        # Now tell the file creator which files are real!
        # ACCESS1-3 has no rcp85 experiment in this case.
        file_1 = this_file_creator.get_files(
            {
                'model': 'ACCESS1-0',
                'experiment': 'rcp45'
            },
            check=False,
            update=True)

        file_2 = this_file_creator.get_files(
            {
                'model': 'ACCESS1-0',
                'experiment': 'rcp85'
            },
            check=False,
            update=True)

        file_3 = this_file_creator.get_files(
            {
                'model': 'ACCESS1-3',
                'experiment': 'rcp45'
            },
            check=False,
            update=True)

        # Ensure that the FileCreator has returned a file
        # for each combination.
        for file_thing in [file_1, file_2, file_3]:
            self.assertTrue(file_thing)

        all_files = [file_thing for file_thing in this_file_creator.files]
        # There should only be 3 valid file combinations returned.
        self.assertEqual(len(all_files), 3)
    def test_multi_model(self):
        """ Test for the case when there are groups on Constraints.

        This seems to fail when people use FileCreators.
        """

        institute_model_pattern = "/fake/%variable%_%model%_%institute%.file"
        in_constraints = [Constraint('model', ['model_1', 'model_2']),
                          Constraint('variable', ['variable_1']),
                          Constraint('institute', ['institute_1', 'institute_2'])]
        test_filecreator = FileCreator(institute_model_pattern, in_constraints)

        # Set the valid combinations.
        dummy_file_1 = test_filecreator.get_files({'model': 'model_1',
                                                   'institute': 'institute_1'},
                                                  update=True)
        dummy_file_2 = test_filecreator.get_files({'model': 'model_2',
                                                   'institute': 'institute_2'},
                                                  update=True)

        # Now create a FileCreator to use as output.
        output_pattern = "/an/output/fake/%variable%_%model%_%institute%.file"
        out_constraints = [Constraint('model', ['model_1', 'model_2']),
                           Constraint('variable', ['variable_1']),
                           Constraint('institute', ['institute_1', 'institute_2'])]
        test_output_filecreator = FileCreator(output_pattern, out_constraints)

        print("Valid input combinations are: {0}".format(test_filecreator.valid_combinations))
        self.assertEqual(2, len(test_filecreator.valid_hashes))

        test_argument_creator = ArgumentCreator([test_filecreator],
                                                test_output_filecreator)

        outputs = [combination for combination in test_argument_creator]

        print("Output is: {0}".format(outputs))

        # There should only be two outputs - not 4!
        self.assertEqual(len(outputs), 2)