コード例 #1
0
ファイル: test_hal.py プロジェクト: vishalbelsare/minifold
def test_hal_predicate_and():
    p1 = BinaryPredicate("authFullName_s", "==", "Natalya Rozhnova")
    p2 = BinaryPredicate("producedDateY_i", "IN", (2015, 2017))
    p3 = BinaryPredicate(p1, "&&", p2)
    obtained = HAL.binary_predicate_to_hal(p3)
    expected = "authFullName_s:(%22Natalya%20Rozhnova%22)&fq=producedDateY_i:[2015%20TO%202017]"
    assert obtained == expected
コード例 #2
0
def test_google_scholar_where_year():
    entries = SCHOLAR.query(
        Query(filters=BinaryPredicate(
            BinaryPredicate("authors", "CONTAINS", "Marc-Olivier Buob"), "&&",
            BinaryPredicate(BinaryPredicate("year", "<=", 2018), "&&",
                            BinaryPredicate("year", ">=", 2016)))))
    assert len(entries) == 5
コード例 #3
0
def test_query_select_where():
    query = Query(attributes=["a", "c", "d"],
                  filters=BinaryPredicate(BinaryPredicate("a", "<=", 100),
                                          "&&", BinaryPredicate("b", ">", 20)))

    expected = [{
        "a": 100,
        "c": 300,
        "d": None
    }, {
        "a": 100,
        "c": None,
        "d": 400
    }]

    for cache_connector in CACHE_CONNECTORS:
        Log.info("Clearing cache" + ("-" * 80))
        cache_connector.clear_query(query)

        Log.info("Non-cached query" + ("-" * 80))
        Log.info("Check if not cached")
        assert cache_connector.is_cached(query) == False

        Log.info("Query")
        result = cache_connector.query(query)
        assert result == expected

        Log.info("Cached query" + ("-" * 80))
        Log.info("Check if cached")
        assert cache_connector.is_cached(query) == True

        Log.info("Query")
        result = cache_connector.query(query)
        assert result == expected
コード例 #4
0
def test_count_connector():
    entries_connector = EntriesConnector(ENTRIES)
    count_connector = CountConnector(entries_connector)
    assert count_connector.query(Query()) == 4
    assert count_connector.query(
        Query(filters=BinaryPredicate("c", ">", 20))) == 2
    assert count_connector.query(
        Query(filters=BinaryPredicate("c", ">", 1000))) == 0
コード例 #5
0
ファイル: test_rename.py プロジェクト: vishalbelsare/minifold
def test_rename_select_where():
    query = Query(
        attributes = ["A", "C", "D"],
        filters    = BinaryPredicate(BinaryPredicate("A", "<=", 100), "&&", BinaryPredicate("b", ">", 20))
    )
    obtained = RENAME_CONNECTOR.query(query)

    assert obtained == [
        {"A": 100, "C": 300,  "D": None},
        {"A": 100, "C": None, "D": 400}
    ]
コード例 #6
0
ファイル: test_where.py プロジェクト: sawdog/minifold
def test_where_on_entries_connector():
    entries_connector = EntriesConnector(ENTRIES)
    obtained = entries_connector.query(
        Query(
            filters = BinaryPredicate(
                BinaryPredicate("a", "<=", 10),
                "&&",
                BinaryPredicate("c", ">", 0)
            )
        )
    )
    assert obtained == EXPECTED
コード例 #7
0
def test_dblp_researcher():
    attributes = ["title", "authors", "year"]
    year = 2008
    fullname = "Marc-Olivier Buob"

    entries = DBLP.query(
        Query(object="publication",
              attributes=attributes,
              filters=BinaryPredicate(
                  BinaryPredicate("year", "==", year), "&&",
                  BinaryPredicate("authors", "==", fullname))))
    assert len(entries) == 2
    assert len(entries[0]["authors"]) == 1
    assert len(entries[1]["authors"]) == 3
コード例 #8
0
def test_dblp_publication():
    attributes = ["title", "authors", "year"]
    year = 2016
    fullname = "Marc-Olivier Buob"

    entries = DBLP.query(
        Query(object="publication",
              attributes=attributes,
              filters=BinaryPredicate(
                  BinaryPredicate("year", "==", year), "&&",
                  BinaryPredicate("authors", "==", fullname))))
    assert len(entries) > 0
    for entry in entries:
        assert set(entry.keys()) == set(attributes)
        assert entry["year"] == year
コード例 #9
0
ファイル: test_hal.py プロジェクト: vishalbelsare/minifold
def test_hal_query():
    year = 2016
    fullname = "Natalya Rozhnova"
    query = Query(
        object     = "publication",
        attributes = DEFAULT_ATTRIBUTES,
        filters    = \
            BinaryPredicate(
                BinaryPredicate("authFullName_s", "==", fullname),
                "&&",
                BinaryPredicate("producedDateY_i", "IN", (year - 1, year + 1))
            )
    )
    obtained = HAL.query_to_hal(query)
    expected = "https://api.archives-ouvertes.fr/search/?q=*:*&fl=title_s,authFullName_s,producedDateY_i,uri_s&fq=authFullName_s:(%22Natalya%20Rozhnova%22)&fq=producedDateY_i:[2015%20TO%202017]&rows=2000&sort=submittedDate_tdate+desc&wt=json"
    assert obtained == expected
コード例 #10
0
def test_rename_select_where():
    rename_connector = RenameConnector(MAP_RENAME, EntriesConnector(ENTRIES))
    query = Query(attributes=["A", "C", "D"],
                  filters=BinaryPredicate(BinaryPredicate("A", "<=", 100),
                                          "&&", BinaryPredicate("B", ">", 20)))
    result = rename_connector.query(query)

    assert result == [{
        "A": 100,
        "C": 300,
        "D": None
    }, {
        "A": 100,
        "C": None,
        "D": 400
    }]
コード例 #11
0
def test_query_select_where():
    entries_connector = EntriesConnector(ENTRIES)
    q = Query(attributes=["a", "c", "d"],
              filters=BinaryPredicate(BinaryPredicate("a", "<=", 100), "&&",
                                      BinaryPredicate("b", ">", 20)))
    result = entries_connector.query(q)

    assert result == [{
        'a': 100,
        'c': 300,
        'd': None
    }, {
        'a': 100,
        'c': None,
        'd': 400
    }]
コード例 #12
0
def test_json_select_where():
    connector = JsonConnector(JSON_CONTENT)
    john_lastnames = {
        entry["lastname"] \
        for entry in connector.query(
            Query(
                attributes = ["lastname"],
                filters    = BinaryPredicate("firstname", "==", "John")
            )
        )
    }
    assert john_lastnames == {"Doe", "Connor"}
コード例 #13
0
def test_lt():
    assert BinaryPredicate("a", "<", 0)(ENTRY) is False
    assert BinaryPredicate("a", "<", 1)(ENTRY) is False
    assert BinaryPredicate("a", "<", 3)(ENTRY) is True
    assert BinaryPredicate("a", operator.__lt__, 0)(ENTRY) is False
    assert BinaryPredicate("a", operator.__lt__, 1)(ENTRY) is False
    assert BinaryPredicate("a", operator.__lt__, 3)(ENTRY) is True
コード例 #14
0
def test_gt():
    assert BinaryPredicate("a", ">", 0)(ENTRY) == True
    assert BinaryPredicate("a", ">", 1)(ENTRY) == False
    assert BinaryPredicate("a", ">", 3)(ENTRY) == False
    assert BinaryPredicate("a", operator.__gt__, 0)(ENTRY) == True
    assert BinaryPredicate("a", operator.__gt__, 1)(ENTRY) == False
    assert BinaryPredicate("a", operator.__gt__, 3)(ENTRY) == False
コード例 #15
0
def test_ge():
    assert BinaryPredicate("a", ">=", 0)(ENTRY) is True
    assert BinaryPredicate("a", ">=", 1)(ENTRY) is True
    assert BinaryPredicate("a", ">=", 3)(ENTRY) is False
    assert BinaryPredicate("a", operator.__ge__, 0)(ENTRY) is True
    assert BinaryPredicate("a", operator.__ge__, 1)(ENTRY) is True
    assert BinaryPredicate("a", operator.__ge__, 3)(ENTRY) is False
コード例 #16
0
def test_eq():
    assert BinaryPredicate("a", "==", 0)(ENTRY) == False
    assert BinaryPredicate("a", "==", 1)(ENTRY) == True
    assert BinaryPredicate("a", "==", 3)(ENTRY) == False
    assert BinaryPredicate("a", operator.__eq__, 0)(ENTRY) == False
    assert BinaryPredicate("a", operator.__eq__, 1)(ENTRY) == True
    assert BinaryPredicate("a", operator.__eq__, 3)(ENTRY) == False
コード例 #17
0
def test_ne():
    assert BinaryPredicate("a", "!=", 0)(ENTRY) == True
    assert BinaryPredicate("a", "!=", 1)(ENTRY) == False
    assert BinaryPredicate("a", "!=", 3)(ENTRY) == True
    assert BinaryPredicate("a", operator.__ne__, 0)(ENTRY) == True
    assert BinaryPredicate("a", operator.__ne__, 1)(ENTRY) == False
    assert BinaryPredicate("a", operator.__ne__, 3)(ENTRY) == True
コード例 #18
0
ファイル: test_hal.py プロジェクト: vishalbelsare/minifold
def test_lincs_laboratory():
    year = 2016
    attributes = ["authFullName_s", "title_s", "producedDateY_i"]

    entries = HAL.query(
        Query(object="lincs",
              attributes=attributes,
              filters=BinaryPredicate("producedDateY_i", "==", year)))

    assert len(entries) > 0
    for entry in entries:
        assert set(entry.keys()) == set(attributes)
        assert entry["producedDateY_i"] == year
コード例 #19
0
ファイル: test_hal.py プロジェクト: vishalbelsare/minifold
def test_lincs_laboratory_with_aliases():
    hal_with_aliases = RenameConnector(HAL_ALIASES, HAL)
    year = 2016
    attributes = ["authors", "title", "year"]

    entries = hal_with_aliases.query(
        Query(object="lincs",
              attributes=attributes,
              filters=BinaryPredicate("year", "==", year)))

    assert len(entries) > 0
    for entry in entries:
        assert set(entry.keys()) == set(attributes)
        assert entry["year"] == year
コード例 #20
0
def test_google_scholar_limit():
    entries = SCHOLAR.query(
        Query(filters=BinaryPredicate("authors", "CONTAINS",
                                      "Marc-Olivier Buob"),
              limit=2))
    assert len(entries) == 2
コード例 #21
0
def test_conference():
    for conference in CONFERENCES:
        entries = DBLP.query(
            Query(object="conference",
                  filters=BinaryPredicate("conference", "==", conference)))
コード例 #22
0
ファイル: test_hal.py プロジェクト: vishalbelsare/minifold
def test_hal_predicate_equals():
    p1 = BinaryPredicate("authFullName_s", "==", "Natalya Rozhnova")
    obtained = HAL.binary_predicate_to_hal(p1)
    expected = "authFullName_s:(%22Natalya%20Rozhnova%22)"
    assert obtained == expected
コード例 #23
0
def test_includes():
    assert BinaryPredicate("a", "IN", {1, 2, 3})(ENTRY) == True
    assert BinaryPredicate("a", "IN", {4, 5, 6})(ENTRY) == False
コード例 #24
0
def test_set():
    assert BinaryPredicate("a", "<=", {1, 2, 3})(ENTRY2)    == True
    assert BinaryPredicate("a", "<=", {1, 2, 3, 4})(ENTRY2) == True
    assert BinaryPredicate("a", "<=", {2, 3, 4})(ENTRY2)    == False
    assert BinaryPredicate("a", "<=", {2, 3})(ENTRY2)       == False

    assert BinaryPredicate("a", "<", {1, 2, 3})(ENTRY2)    == False
    assert BinaryPredicate("a", "<", {1, 2, 3, 4})(ENTRY2) == True
    assert BinaryPredicate("a", "<", {2, 3, 4})(ENTRY2)    == False
    assert BinaryPredicate("a", "<", {2, 3})(ENTRY2)       == False

    assert BinaryPredicate("a", ">=", {1, 2, 3})(ENTRY2)    == True
    assert BinaryPredicate("a", ">=", {1, 2, 3, 4})(ENTRY2) == False
    assert BinaryPredicate("a", ">=", {2, 3, 4})(ENTRY2)    == False
    assert BinaryPredicate("a", ">=", {2, 3})(ENTRY2)       == True

    assert BinaryPredicate("a", ">", {1, 2, 3})(ENTRY2)    == False
    assert BinaryPredicate("a", ">", {1, 2, 3, 4})(ENTRY2) == False
    assert BinaryPredicate("a", ">", {2, 3, 4})(ENTRY2)    == False
    assert BinaryPredicate("a", ">", {2, 3})(ENTRY2)       == True

    assert BinaryPredicate("a", "==", {1, 2, 3})(ENTRY2)    == True
    assert BinaryPredicate("a", "==", {1, 2, 3, 4})(ENTRY2) == False
    assert BinaryPredicate("a", "==", {2, 3, 4})(ENTRY2)    == False
    assert BinaryPredicate("a", "==", {2, 3})(ENTRY2)       == False

    assert BinaryPredicate("a", "!=", {1, 2, 3})(ENTRY2)    == False
    assert BinaryPredicate("a", "!=", {1, 2, 3, 4})(ENTRY2) == True
    assert BinaryPredicate("a", "!=", {2, 3, 4})(ENTRY2)    == True
    assert BinaryPredicate("a", "!=", {2, 3})(ENTRY2)       == True
コード例 #25
0
def test_clause():
    t1 = BinaryPredicate("a", "==", 1)
    f1 = BinaryPredicate("a", "!=", 1)
    t2 = BinaryPredicate("b", "==", 2)
    f2 = BinaryPredicate("b", "!=", 2)
    check_clause(t1, f1, t2, f2)
コード例 #26
0
def check_clause(t1, f1, t2, f2):
    assert BinaryPredicate(t1, "AND", t2)(ENTRY) == True
    assert BinaryPredicate(t1, "AND", f2)(ENTRY) == False
    assert BinaryPredicate(f1, "AND", t2)(ENTRY) == False
    assert BinaryPredicate(f1, "AND", f2)(ENTRY) == False

    assert BinaryPredicate(t1, "&&", t2)(ENTRY) == True
    assert BinaryPredicate(t1, "&&", f2)(ENTRY) == False
    assert BinaryPredicate(f1, "&&", t2)(ENTRY) == False
    assert BinaryPredicate(f1, "&&", f2)(ENTRY) == False

    assert BinaryPredicate(t1, "OR", t2)(ENTRY) == True
    assert BinaryPredicate(t1, "OR", f2)(ENTRY) == True
    assert BinaryPredicate(f1, "OR", t2)(ENTRY) == True
    assert BinaryPredicate(f1, "OR", f2)(ENTRY) == False

    assert BinaryPredicate(t1, "||", t2)(ENTRY) == True
    assert BinaryPredicate(t1, "||", f2)(ENTRY) == True
    assert BinaryPredicate(f1, "||", t2)(ENTRY) == True
    assert BinaryPredicate(f1, "||", f2)(ENTRY) == False
コード例 #27
0
def test_contains():
    assert BinaryPredicate("a", "CONTAINS", 1)(ENTRY2) == True
    assert BinaryPredicate("a", "CONTAINS", 4)(ENTRY2) == False
コード例 #28
0
ファイル: test_hal.py プロジェクト: vishalbelsare/minifold
def test_hal_predicate_in():
    p2 = BinaryPredicate("producedDateY_i", "IN", (2015, 2017))
    obtained = HAL.binary_predicate_to_hal(p2)
    expected = "producedDateY_i:[2015%20TO%202017]"
    assert obtained == expected