예제 #1
0
def test_table_data_is_iterable_by_rows():
    presidents = TableData(db_path, "presidents")
    names, ages, countries = [], [], []
    for president in presidents:
        names.append(president["name"])
        ages.append(president["age"])
        countries.append(president["country"])
    assert names == ["Yeltsin", "Trump", "Big Man Tyrone"]
    assert ages == [999, 1337, 101]
    assert countries == ["Russia", "US", "Kekistan"]
    presidents.close()
예제 #2
0
def test_context_manager_table_data_length():
    with TableData(db_path, "presidents") as presidents:
        assert len(presidents) == 3
예제 #3
0
def test_table_data_get_item():
    presidents = TableData(db_path, "presidents")
    assert presidents["Trump"] == ("Trump", 1337, "US")
    presidents.close()
예제 #4
0
def test_table_data_contains():
    presidents = TableData(db_path, "presidents")
    assert "Trump" in presidents
    assert "Lincoln" not in presidents
    presidents.close()
예제 #5
0
def test_table_data_length():
    presidents = TableData(db_path, "presidents")
    assert len(presidents) == 3
    presidents.close()
예제 #6
0
def test_context_manager_table_data_get_item():
    with TableData(db_path, "presidents") as presidents:
        assert presidents["Trump"] == ("Trump", 1337, "US")
예제 #7
0
def test_context_manager_table_data_contains():
    with TableData(db_path, "presidents") as presidents:
        assert "Trump" in presidents
        assert "Lincoln" not in presidents