Ejemplo n.º 1
0
    def test_with_xml(self):
        kwargs = self.kwargs.copy()
        kwargs.update({
            'from_date': datetime.date(2018, 1, 1),
            'to_date': datetime.date(2018, 12, 31)
        })
        dataset = Dataset(**kwargs)
        files_dekad = sorted(self.files_dekad[:])
        # Add and .xml at the begin and at the end
        files_dekad = [files_dekad[0][:-3] + 'xml'
                       ] + files_dekad + [files_dekad[-1][:-3] + 'xml']
        dataset.get_filenames = lambda **my_kwargs: files_dekad
        dataset._clean_cache()

        # Note: the .missing (permanent missing) are not counted as 'missing'
        completeness = dataset.get_dataset_normalized_info()
        self.assertEqual(completeness['missingfiles'], 3)
Ejemplo n.º 2
0
    def test_product_no_dates(self):
        kwargs = {
            'product_code': "fewsnet-rfe",
            'version': "2.0",
            'sub_product_code': "1monmax",
            'mapset': 'FEWSNET-Africa-8km',
        }
        files = [
            "0101_fewsnet-rfe_1monmax_FEWSNET-Africa-8km_2.0.tif",
            "0201_fewsnet-rfe_1monmax_FEWSNET-Africa-8km_2.0.tif",
            "0301_fewsnet-rfe_1monmax_FEWSNET-Africa-8km_2.0.tif",
            "0401_fewsnet-rfe_1monmax_FEWSNET-Africa-8km_2.0.tif",
            "0501_fewsnet-rfe_1monmax_FEWSNET-Africa-8km_2.0.tif",
            "0601_fewsnet-rfe_1monmax_FEWSNET-Africa-8km_2.0.tif",
            "0701_fewsnet-rfe_1monmax_FEWSNET-Africa-8km_2.0.tif",
            "0801_fewsnet-rfe_1monmax_FEWSNET-Africa-8km_2.0.tif",
            "0901_fewsnet-rfe_1monmax_FEWSNET-Africa-8km_2.0.tif",
            "1001_fewsnet-rfe_1monmax_FEWSNET-Africa-8km_2.0.tif",
            "1101_fewsnet-rfe_1monmax_FEWSNET-Africa-8km_2.0.tif",
            "1201_fewsnet-rfe_1monmax_FEWSNET-Africa-8km_2.0.tif",
        ]

        dataset = Dataset(**kwargs)
        dataset.get_filenames = lambda **my_kwargs: files
        dataset._clean_cache()

        completeness = dataset.get_dataset_normalized_info()
        self.assertEqual(completeness['totfiles'], 12)
        self.assertEqual(completeness['missingfiles'], 0)
        self.assertEqual(completeness['intervals'][0]['todate'], '12-01')
        self.assertEqual(completeness['intervals'][0]['fromdate'], '01-01')
        self.assertEqual(completeness['firstdate'], '01-01')
        self.assertEqual(completeness['lastdate'], '12-01')
        current_date = datetime.date(2014, 1, 1)
        last_date = datetime.date(2015, 1, 1)
        for i in range(12):
            current_date = dataset.next_date(current_date)
        self.assertEqual(last_date, current_date)