def _generate_date_with_wildcard_query(self, date_value):
        """Helper for generating a date keyword query containing a wildcard.

        Returns:
            (dict): The date query containing the wildcard or an empty dict in case the date value is malformed.

        The policy followed here is quite conservative on what it accepts as valid input. Look into
        :meth:`inspire_query_parser.utils.visitor_utils._truncate_wildcard_from_date` for more information.
        """
        if date_value.endswith(ast.GenericValue.WILDCARD_TOKEN):
            try:
                date_value = _truncate_wildcard_from_date(date_value)
            except ValueError:
                # Drop date query.
                return {}

            return self._generate_range_queries(self.KEYWORD_TO_ES_FIELDNAME['date'],
                                                {ES_RANGE_EQ_OPERATOR: date_value})
        else:
            # Drop date query with wildcard not as suffix, e.g. 2000-1*-31
            return {}
def test_truncate_wildcard_from_date_throws_with_unsupported_separator():
    date = '2018_1*'
    with raises(ValueError):
        _truncate_wildcard_from_date(date)
def test_truncate_wildcard_from_date_throws_on_wildcard_in_year():
    date = '201*'
    with raises(ValueError):
        _truncate_wildcard_from_date(date)
def test_truncate_wildcard_from_date_with_wildcard(date, expected_date):
    assert _truncate_wildcard_from_date(date) == expected_date