How to use default_parser method in Testify

Best Python code snippet using Testify_python

test_parser.py

Source:test_parser.py Github

copy

Full Screen

1import pytest2from aiosumma.parser import default_parser3from aiosumma.parser.elements import (4 Boost,5 Doi,6 Group,7 Minus,8 Phrase,9 Plus,10 Proximity,11 Regex,12 SearchField,13 Url,14 Word,15)16from aiosumma.parser.errors import ParseError17def test_default():18 parsed_query = default_parser.parse('search engine')19 assert parsed_query == Group(Word('search'), Word('engine'))20def test_plus_minus():21 parsed_query = default_parser.parse('-search +engine')22 assert parsed_query == Group(Minus(Word('search')), Plus(Word('engine')))23def test_nested_group_1():24 parsed_query = default_parser.parse('search (cat dog)')25 assert parsed_query == Group(Word('search'), Word('cat'), Word('dog'))26def test_nested_group_2():27 parsed_query = default_parser.parse('(search (cat mouse (dog rhino)))')28 assert parsed_query == Group(Word('search'), Word('cat'), Word('mouse'), Word('dog'), Word('rhino'))29def test_search_field():30 parsed_query = default_parser.parse('title:kolobok')31 assert parsed_query == SearchField('title', Word('kolobok'))32def test_search_field_with_group():33 parsed_query = default_parser.parse('title:(kolobok babushka)')34 assert parsed_query == SearchField('title', Group(Word('kolobok'), Word('babushka')))35def test_group_as_search_field():36 with pytest.raises(ParseError):37 default_parser.parse('(title body):ninja')38def test_plus_minus_group():39 parsed_query = default_parser.parse('+(term1 term2) -(term3 term4)')40 assert parsed_query == Group(Plus(Group(Word('term1'), Word('term2'))), Minus(Group(Word('term3'), Word('term4'))))41def test_large_plus_minus_group():42 parsed_query = default_parser.parse('+(term1 term2 term3 term4 term5) -(term6 term7 term8 term9 term10)')43 assert parsed_query == Group(44 Plus(Group(Word('term1'), Word('term2'), Word('term3'), Word('term4'), Word('term5'))),45 Minus(Group(Word('term6'), Word('term7'), Word('term8'), Word('term9'), Word('term10'))),46 )47def test_not_regex():48 parsed_query = default_parser.parse('pyth.*')49 assert parsed_query == Word('pyth.*')50def test_regex():51 parsed_query = default_parser.parse('title:/pyth.*/')52 assert parsed_query == SearchField('title', Regex('pyth.*'))53def test_free_regex():54 parsed_query = default_parser.parse('/pyth.*/')55 assert parsed_query == Regex('pyth.*')56def test_free_with_slash_regex():57 parsed_query = default_parser.parse('/pyth/.*/')58 assert parsed_query == Group(Regex('pyth'), Word('.*/'))59def test_free_with_escaped_slash_regex():60 parsed_query = default_parser.parse('/pyth\\/.*/')61 assert parsed_query == Regex('pyth/.*')62def test_phrase():63 parsed_query = default_parser.parse('title:"kolobok"')64 assert parsed_query == SearchField('title', Phrase('kolobok'))65def test_free_phrase():66 parsed_query = default_parser.parse('"kolobok"')67 assert parsed_query == Phrase("kolobok")68def test_boost():69 parsed_query = default_parser.parse('title:kolobok^3.0')70 assert parsed_query == Boost(SearchField('title', Word('kolobok')), 3)71def test_boost_group():72 parsed_query = default_parser.parse('(kolobok babushka)^3.0')73 assert parsed_query == Boost(Group(Word('kolobok'), Word('babushka')), 3)74def test_proximity():75 parsed_query = default_parser.parse('"Kolobok babushka"~3')76 assert parsed_query == Proximity(Phrase('Kolobok babushka'), 3)77def test_doi():78 parsed_query = default_parser.parse('10.1385/nmm:9:1:17')79 assert parsed_query == Doi('10.1385/nmm:9:1:17')80def test_url():81 parsed_query = default_parser.parse('https://doi.org/10.1101/2022.05.26.493559')...

Full Screen

Full Screen

test_summa_query.py

Source:test_summa_query.py Github

copy

Full Screen

1import pytest2from aiosumma.errors import UnsupportedQueryError3from aiosumma.parser import default_parser4def test_default():5 parsed_query = default_parser.parse('search engine')6 assert parsed_query.to_summa_query() == {7 'boolean': {'subqueries': [8 {'occur': 'should', 'query': {'match': {'value': 'search'}}},9 {'occur': 'should', 'query': {'match': {'value': 'engine'}}}10 ]}}11def test_plus_minus():12 parsed_query = default_parser.parse('-search +engine')13 assert parsed_query.to_summa_query() == {'boolean': {'subqueries': [14 {'occur': 'must_not', 'query': {'match': {'value': 'search'}}},15 {'occur': 'must', 'query': {'match': {'value': 'engine'}}}16 ]}}17def test_search_field():18 parsed_query = default_parser.parse('title:kolobok')19 assert parsed_query.to_summa_query() == {'term': {'field': 'title', 'value': 'kolobok'}}20def test_search_field_with_group():21 with pytest.raises(UnsupportedQueryError):22 default_parser.parse('title:(kolobok babushka)').to_summa_query()23def test_not_regex():24 parsed_query = default_parser.parse('pyth.*')25 assert parsed_query.to_summa_query() == {'match': {'value': 'pyth.*'}}26def test_regex():27 parsed_query = default_parser.parse('title:/pyth.*/')28 assert parsed_query.to_summa_query() == {'regex': {'field': 'title', 'value': 'pyth.*'}}29def test_free_regex():30 parsed_query = default_parser.parse('/pyth.*/')31 assert parsed_query.to_summa_query() == {'match': {'value': '/pyth.*/'}}32def test_free_with_slash_regex():33 parsed_query = default_parser.parse('/pyth/.*/')34 assert parsed_query.to_summa_query() == {'boolean': {'subqueries': [35 {'occur': 'should', 'query': {'match': {'value': '/pyth/'}}},36 {'occur': 'should', 'query': {'match': {'value': '.*/'}}}37 ]}}38def test_free_with_escaped_slash_regex():39 parsed_query = default_parser.parse('/pyth\\/.*/')40 assert parsed_query.to_summa_query() == {'match': {'value': '/pyth/.*/'}}41def test_phrase():42 parsed_query = default_parser.parse('title:"kolobok"')43 assert parsed_query.to_summa_query() == {'phrase': {'field': 'title', 'value': 'kolobok'}}44def test_free_phrase():45 parsed_query = default_parser.parse('"kolobok"')46 assert parsed_query.to_summa_query() == {'match': {'value': '"kolobok"'}}47def test_boost():48 parsed_query = default_parser.parse('title:kolobok^3.0')49 assert parsed_query.to_summa_query() == {'boost': {50 'query': {'term': {'field': 'title', 'value': 'kolobok'}},51 'score': '3'52 }}53def test_boost_group():54 parsed_query = default_parser.parse('(kolobok babushka)^3.0')55 assert parsed_query.to_summa_query() == {'boost': {'query': {'boolean': {'subqueries': [56 {'occur': 'should', 'query': {'match': {'value': 'kolobok'}}},57 {'occur': 'should', 'query': {'match': {'value': 'babushka'}}}58 ]}}, 'score': '3'}}59def test_proximity():60 parsed_query = default_parser.parse('"Kolobok babushka"~3')...

Full Screen

Full Screen

config.py

Source:config.py Github

copy

Full Screen

1import configparser2import os3import json4parser = configparser.ConfigParser()5parser.read(os.path.realpath("config"))6default_parser = parser[configparser.DEFAULTSECT]7sleep_time = default_parser["sleep_time"]8enable_log_html = default_parser.getboolean("enable_log_html")9html_folder = default_parser["html_folder"]10url = default_parser["url"]11id = json.loads(default_parser["id"])12pwd = default_parser["pwd"]13time = default_parser["time"]14bet_type = default_parser["bet_type"]15api_endpoint = default_parser["api_endpoint"]...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testify automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful