|
27 | 27 | from inspire_query_parser.parser import (And, BooleanQuery, ComplexValue, |
28 | 28 | DateValue, EmptyQuery, Expression, |
29 | 29 | GreaterEqualOp, GreaterThanOp, |
| 30 | + GreaterThanDateOp, |
30 | 31 | InspireDateKeyword, InspireKeyword, |
31 | 32 | InvenioKeywordQuery, LessEqualOp, |
32 | 33 | LessThanOp, MalformedQueryWords, |
|
1762 | 1763 | ("", Query([EmptyQuery()])), |
1763 | 1764 | (" ", Query([EmptyQuery()])), |
1764 | 1765 | # G, GE, LT, LE, E queries |
1765 | | - ( |
1766 | | - "date > 2000-10 and < 2000-12", |
1767 | | - Query( |
1768 | | - [ |
1769 | | - Statement( |
1770 | | - BooleanQuery( |
1771 | | - Expression( |
1772 | | - SimpleQuery( |
1773 | | - SpiresDateKeywordQuery( |
1774 | | - InspireDateKeyword("date"), |
1775 | | - DateValue( |
1776 | | - GreaterThanOp(SimpleDateValue("2000-10")) |
1777 | | - ), |
1778 | | - ) |
1779 | | - ) |
1780 | | - ), |
1781 | | - And(), |
1782 | | - Statement( |
1783 | | - Expression( |
1784 | | - SimpleQuery( |
1785 | | - Value(LessThanOp(SimpleDateValue("2000-12"))) |
1786 | | - ) |
1787 | | - ) |
1788 | | - ), |
1789 | | - ) |
1790 | | - ) |
1791 | | - ] |
1792 | | - ), |
1793 | | - ), |
1794 | | - ( |
1795 | | - "date after 10/2000 and before 2000-12", |
1796 | | - Query( |
1797 | | - [ |
1798 | | - Statement( |
1799 | | - BooleanQuery( |
1800 | | - Expression( |
1801 | | - SimpleQuery( |
1802 | | - SpiresDateKeywordQuery( |
1803 | | - InspireDateKeyword("date"), |
1804 | | - DateValue( |
1805 | | - GreaterThanOp(SimpleDateValue("10/2000")) |
1806 | | - ), |
1807 | | - ) |
1808 | | - ) |
1809 | | - ), |
1810 | | - And(), |
1811 | | - Statement( |
1812 | | - Expression( |
1813 | | - SimpleQuery( |
1814 | | - Value(LessThanOp(SimpleDateValue("2000-12"))) |
1815 | | - ) |
1816 | | - ) |
1817 | | - ), |
1818 | | - ) |
1819 | | - ) |
1820 | | - ] |
1821 | | - ), |
1822 | | - ), |
1823 | 1766 | ( |
1824 | 1767 | "date >= nov 2000 and d<=2005", |
1825 | 1768 | Query( |
|
2070 | 2013 | SpiresDateKeywordQuery( |
2071 | 2014 | InspireDateKeyword("date-updated"), |
2072 | 2015 | DateValue( |
2073 | | - GreaterThanOp(SimpleDateValue("yesterday - 2")) |
| 2016 | + GreaterThanDateOp(SimpleDateValue("yesterday - 2")) |
2074 | 2017 | ), |
2075 | 2018 | ) |
2076 | 2019 | ) |
@@ -2335,3 +2278,76 @@ def test_parser_functionality(query_str, expected_parse_tree): |
2335 | 2278 | parser = StatefulParser() |
2336 | 2279 | _, parse_tree = parser.parse(query_str, Query) |
2337 | 2280 | assert parse_tree == expected_parse_tree |
| 2281 | + |
| 2282 | + |
| 2283 | +@pytest.mark.parametrize( |
| 2284 | + ["query_str", "expected_parse_tree"], |
| 2285 | + { |
| 2286 | + ( |
| 2287 | + "date > 2000-10 and < 2000-12", |
| 2288 | + Query( |
| 2289 | + [ |
| 2290 | + Statement( |
| 2291 | + BooleanQuery( |
| 2292 | + Expression( |
| 2293 | + SimpleQuery( |
| 2294 | + SpiresDateKeywordQuery( |
| 2295 | + InspireDateKeyword("date"), |
| 2296 | + DateValue( |
| 2297 | + GreaterThanOp(SimpleDateValue("2000-10")) |
| 2298 | + ), |
| 2299 | + ) |
| 2300 | + ) |
| 2301 | + ), |
| 2302 | + And(), |
| 2303 | + Statement( |
| 2304 | + Expression( |
| 2305 | + SimpleQuery( |
| 2306 | + Value(LessThanOp(SimpleDateValue("2000-12"))) |
| 2307 | + ) |
| 2308 | + ) |
| 2309 | + ), |
| 2310 | + ) |
| 2311 | + ) |
| 2312 | + ] |
| 2313 | + ), |
| 2314 | + ), |
| 2315 | + ( |
| 2316 | + "date after 10/2000 and before 2000-12", |
| 2317 | + Query( |
| 2318 | + [ |
| 2319 | + Statement( |
| 2320 | + BooleanQuery( |
| 2321 | + Expression( |
| 2322 | + SimpleQuery( |
| 2323 | + SpiresDateKeywordQuery( |
| 2324 | + InspireDateKeyword("date"), |
| 2325 | + DateValue( |
| 2326 | + GreaterThanOp(SimpleDateValue("10/2000")) |
| 2327 | + ), |
| 2328 | + ) |
| 2329 | + ) |
| 2330 | + ), |
| 2331 | + And(), |
| 2332 | + Statement( |
| 2333 | + Expression( |
| 2334 | + SimpleQuery( |
| 2335 | + Value(LessThanOp(SimpleDateValue("2000-12"))) |
| 2336 | + ) |
| 2337 | + ) |
| 2338 | + ), |
| 2339 | + ) |
| 2340 | + ) |
| 2341 | + ] |
| 2342 | + ), |
| 2343 | + ), |
| 2344 | + }, |
| 2345 | +) |
| 2346 | +@pytest.mark.xfail( |
| 2347 | + reason="the queries are not correct, should be fixed by https://github.com/cern-sis/issues-inspire/issues/150 " |
| 2348 | +) |
| 2349 | +def test_parser_functionality_regressions(query_str, expected_parse_tree): |
| 2350 | + print("Parsing: " + query_str) |
| 2351 | + parser = StatefulParser() |
| 2352 | + _, parse_tree = parser.parse(query_str, Query) |
| 2353 | + assert parse_tree == expected_parse_tree |
0 commit comments