Exemple #1
0
def test_add_overwrite_element():
    cards = CardDB(index='id')
    card2 = {'id': 2, 'a': 1, 'b': 'c'}
    cards.add(card2)
    assert len(cards) == 1
    assert cards[2] == card2
    cards.add({'id': 2, 'a': 2})
    assert cards[2] == {'id': 2, 'a': 2, 'b': 'c'}
Exemple #2
0
def test_add_nonunique():
    cards = CardDB(index='id')
    card2a = {'id': 2, 'a': 1, 'b': 'c'}
    card2b = {'id': 2, 'a': 2, 'b': 'f'}
    cards.add(card2a)
    cards.add(card2b)
    assert len(cards) == 1
    assert cards[2] == card2b
Exemple #3
0
def test_save(s3fn):
    cards = CardDB(index='id', s3filename=s3fn)
    assert not S3FS.exists(s3fn)
    card0 = {'id': 0, 'a': 1, 'b': 'c', 'd': 4.5}
    card3 = {'id': 3, 'a': 2, 'b': 'e', 'd': 8.5}
    card7 = {'id': 7, 'a': 2, 'b': 'c', 'd': -4.2}
    cards.add(card0)
    cards.add(card3)
    cards.add(card7)
    assert len(cards) == 3
    cards.remove(card3)
    cards.save()
    assert S3FS.exists(s3fn)
    with S3FS.open(s3fn, 'r') as f:
        df = pd.read_csv(f)
    assert cards._df.equals(df)
    cards2 = CardDB(index='id', s3filename=s3fn)
    assert cards._df.equals(cards2._df)
Exemple #4
0
def test_add_invalid_index():
    card2 = {'i': 2, 'a': 1, 'b': 'c'}
    cards = CardDB(index='id')
    with pytest.raises(IndexError):
        cards.add(card2)
Exemple #5
0
def test_add():
    card2 = {'id': 2, 'a': 1, 'b': 'c'}
    cards = CardDB(index='id')
    cards.add(card2)
    assert len(cards) == 1