Exemplo n.º 1
0
def test_search_a_key_with_colon():
    data = pybibs.read_string("""
        @article{Gurion:2019,
        }
        """)
    results = list(query.search(data, ["Gurion:"]))
    assert len(results) == 1
Exemplo n.º 2
0
def test_search_match_details():
    data = pybibs.read_string("""
        @book{tolkien1937hobit,
            year = {1937},
            title = {The Hobbit},
            author = {Tolkien, John R. R.},
        }
        """)
    results = list(query.search(data, ["tolkien", "hobbit"]))
    assert "tolkien" in results[0].match["key"]
    assert ("author", set(["Tolkien"])) in results[0].match["fields"].items()
    assert ("title", set(["Hobbit"])) in results[0].match["fields"].items()
Exemplo n.º 3
0
def test_search_specific_field_with_capital_letter():
    """Issue #27"""
    data = pybibs.read_string("""
        @book{asimov1951foundation,
            year = {1951},
            title = {Foundation},
            author = {Asimov, Izaac}
        }
        """)
    results = list(query.search(data, ["author:asimov"]))
    assert len(results) == 1
    assert results[0].entry["fields"]["title"] == "Foundation"
Exemplo n.º 4
0
def test_search_with_capitalized_search_term():
    """Issue #28"""
    data = pybibs.read_string("""
        @book{asimov1951foundation,
            year = {1951},
            title = {Foundation},
            author = {Asimov, Izaac}
        }
        """)
    results = list(query.search(data, ["ASIMOV"]))
    assert len(results) == 1
    assert results[0].entry["fields"]["title"] == "Foundation"
Exemplo n.º 5
0
def test_search_specific_field():
    data = pybibs.read_string("""
        @book{tolkien1937hobit,
            year = {1937},
            title = {The Hobbit},
            author = {Tolkien, John R. R.},
        }

        @article{1937history,
            title = {What happened in 1937?},
        }
        """)
    results = list(query.search(data, ["year:1937"]))
    assert len(results) == 1
    assert results[0].entry["fields"]["title"] == "The Hobbit"
Exemplo n.º 6
0
def test_search_single_term():
    data = pybibs.read_string("""
        @book{tolkien1937hobit,
            year = {1937},
            title = {The Hobbit},
            author = {Tolkien, John R. R.},
        }

        @book{asimov1951foundation,
            year = {1951},
            title = {Foundation},
            author = {Asimov, Izaac}
        }
        """)
    results = list(query.search(data, ["asimov"]))
    assert len(results) == 1
    assert results[0].entry["fields"]["title"] == "Foundation"
Exemplo n.º 7
0
def test_search_multiple_search_terms():
    data = pybibs.read_string("""
        @book{tolkien1937hobit,
            year = {1937},
            title = {The Hobbit},
            author = {Tolkien, John R. R.},
        }

        @trilogy{tolkien1954lord,
            title={The Lord of the Rings},
            author={Tolkien, John Ronald Reuel},
            year={1954},
        }
        """)
    results = list(query.search(data, ["tolkien", "hobbit"]))
    assert len(results) == 1
    assert results[0].entry["fields"]["title"] == "The Hobbit"
Exemplo n.º 8
0
def test_search_or_get_key_with_many_colons():
    """Issue #66"""
    data = pybibs.read_string("""
        @article{key:with:many:colons,
            title = {Key with many colons},
        }

        @book{tolkien1937hobit,
            year = {1937},
            title = {The Hobbit},
            author = {Tolkien, John R. R.},
        }
        """)
    results = list(query.search(data, "key:with:many:colons"))
    assert len(results) == 1

    search_result = query.get(data, "key:with:many:colons")
    assert search_result.entry["fields"]["title"] == "Key with many colons"
Exemplo n.º 9
0
def test_search_multiple_terms_are_anded():
    data = pybibs.read_string("""
        @book{tolkien1937hobit,
            year = {1937},
            title = {The Hobbit},
            author = {Tolkien, John R. R.},
        }

        @trilogy{tolkien1954lord,
            title={The Lord of the Rings},
            author={Tolkien, John Ronald Reuel},
            year={1954},
        }

        @book{asimov1951foundation,
            year = {1951},
            title = {Foundation},
            author = {Asimov, Izaac}
        }
        """)
    results = list(query.search(data, ["tolkien", "type:book"]))
    assert len(results) == 1
    assert results[0].entry["fields"]["title"] == "The Hobbit"
Exemplo n.º 10
0
def test_search_specific_field(data):
    results = list(query.search(data, ["year:1937"]))
    assert len(results) == 1
    assert results[0].entry["fields"]["title"] == "The Hobbit"
Exemplo n.º 11
0
def test_search_single_term(data):
    results = list(query.search(data, ["asimov"]))
    assert len(results) == 1
    assert results[0].entry["fields"]["title"] == "Foundation"
Exemplo n.º 12
0
def test_search_multiple_terms_are_anded(data):
    results = list(query.search(data, ["tolkien", "type:book"]))
    assert len(results) == 1
    assert results[0].entry["fields"]["title"] == "The Hobbit"
Exemplo n.º 13
0
def test_search_specific_field_with_capital_letter(data):
    """Issue #27"""
    results = list(query.search(data, ["author:asimov"]))
    assert len(results) == 1
    assert results[0].entry["fields"]["title"] == "Foundation"
Exemplo n.º 14
0
def test_search_invalid_search_term(data):
    with pytest.raises(Exception, match="Invalid search term") as e:
        list(query.search(data, "a:b:c"))
Exemplo n.º 15
0
def test_search_with_capitalized_search_term(data):
    """Issue #28"""
    results = list(query.search(data, ["ASIMOV"]))
    assert len(results) == 1
    assert results[0].entry["fields"]["title"] == "Foundation"
Exemplo n.º 16
0
def test_search_a_key_with_colon(data):
    results = list(query.search(data, ["Gurion:"]))
    assert len(results) == 1
Exemplo n.º 17
0
def test_search_match_details(data):
    results = list(query.search(data, ["tolkien", "hobbit"]))
    assert len(results) == 1
    assert "tolkien" in results[0].match["key"]
    assert ("title", set(["Hobbit"])) in results[0].match["fields"].items()
Exemplo n.º 18
0
def test_search_multiple_search_terms(data):
    results = list(query.search(data, ["tolkien", "hobbit"]))
    assert len(results) == 1
    assert results[0].entry["fields"]["title"] == "The Hobbit"