Exemplo n.º 1
0
    def _add_meta_info(self, eopatch, request_params, service_type):
        """ Adds any missing metadata info to EOPatch """

        for param, eoparam in zip(
            ['time', 'time_difference', 'maxcc'],
            ['time_interval', 'time_difference', 'maxcc']):
            if eoparam not in eopatch.meta_info:
                if param == 'time':
                    value = request_params[param]
                    eopatch.meta_info[eoparam] = value if isinstance(
                        value, str) else [
                            iso_to_datetime(parse_time(x)) if isinstance(
                                x, str) else x for x in value
                        ]
                else:
                    eopatch.meta_info[eoparam] = request_params[param]

        if 'service_type' not in eopatch.meta_info:
            eopatch.meta_info['service_type'] = service_type.value

        for param in ['size_x', 'size_y']:
            if param not in eopatch.meta_info:
                eopatch.meta_info[param] = getattr(self, param)

        if eopatch.bbox is None:
            eopatch.bbox = request_params['bbox']
Exemplo n.º 2
0
    def test_parse_time(self):
        test_pairs = [
            ('2015.4.12', '2015-04-12'),
            ('2015.4.12T12:32:14', '2015-04-12T12:32:14'),
            (datetime.date(year=2015, month=2, day=3), '2015-02-03'),
            (datetime.datetime(year=2015, month=2, day=3), '2015-02-03T00:00:00')
        ]

        for idx, (input_time, exp_time) in enumerate(test_pairs):
            with self.subTest(msg='Test case {}'.format(idx + 1)):
                parsed_time = time_utils.parse_time(input_time)
                self.assertEqual(parsed_time, exp_time, 'Expected {}, got {}'.format(exp_time, parsed_time))
Exemplo n.º 3
0
def test_parse_time(time_input, params, expected_output):
    parsed_time = time_utils.parse_time(time_input, **params)
    assert parsed_time == expected_output