コード例 #1
0
def test_insert_rows(testdb):
    insert_rows('table1', [('spes, ei f', 'espoir')])
    assert get_table('table1') \
        == [('1', 'adventus,  us, m.', 'arrivée'),
            ('2', 'aqua , ae, f', 'eau'),
            ('3', 'candidus,  a, um', 'blanc'),
            ('4', 'sol, solis, m', 'soleil'),
            ('5', 'spes, ei f', 'espoir')]
    with pytest.raises(NoSuchTableError) as excinfo:
        insert_rows('table3', [('spes, ei', 'f', 'espoir')])
    assert str(excinfo.value) == 'Cannot find a table named "table3"'
    with pytest.raises(ColumnsDoNotMatchError) as excinfo:
        insert_rows('table1', [('spes, ei', 'f', 'espoir')])
    assert str(excinfo.value) == '"\'spes, ei\', \'f\', \'espoir\'" '\
        'requires 3 columns, but "table1" has 2 columns ("col1" and "col2").'
    insert_rows('table1', [('amor,  oris, m.', 'amour'),
                           ('anima,  ae, f.', 'coeur, âme'),
                           ('hiems, mis,f', 'hiver')])
    assert get_table('table1') \
        == [('1', 'adventus,  us, m.', 'arrivée'),
            ('2', 'aqua , ae, f', 'eau'),
            ('3', 'candidus,  a, um', 'blanc'),
            ('4', 'sol, solis, m', 'soleil'),
            ('5', 'spes, ei f', 'espoir'),
            ('6', 'amor,  oris, m.', 'amour'),
            ('7', 'anima,  ae, f.', 'coeur, âme'),
            ('8', 'hiems, mis,f', 'hiver')]
コード例 #2
0
def test_remove_rows(testdb):
    with pytest.raises(NoSuchRowError) as excinfo:
        remove_rows('table1', '2-5')
    assert str(excinfo.value) == 'Cannot find a row number 5 in "table1"'
    remove_rows('table1', '1-3')
    assert get_table('table1') \
        == [('1', 'sol, solis, m', 'soleil')]
コード例 #3
0
def test_sort_table(testdb):
    sort_table('table1', 2)
    assert table_exists('table1')
    assert not table_exists('table1_copy')
    assert get_table('table1') \
        == [('1', 'adventus,  us, m.', 'arrivée'),
            ('2', 'candidus,  a, um', 'blanc'),
            ('3', 'aqua , ae, f', 'eau'),
            ('4', 'sol, solis, m', 'soleil')]
    with pytest.raises(NoSuchColumnError) as excinfo:
        sort_table('table1', 3)
    assert str(excinfo.value) == 'Cannot find a column number 3 in "table1"'
    sort_table('table2', 3)
    assert get_table('table2', include_headers=True) \
        == [('id', 'col1', 'col2', 'col3'),
            ('1', 'break', 'broke, broken', 'casser'),
            ('2', 'begin', 'began, begun', 'commencer'),
            ('3', 'give', 'gave, given', 'donner'),
            ('4', 'do', 'did, done', 'faire')]
コード例 #4
0
def test_update_table(testdb):
    update_table('table1', 3, ['spes, ei f', 'espoir'])
    assert get_table('table1') == \
        [('1', 'adventus,  us, m.', 'arrivée'),
         ('2', 'aqua , ae, f', 'eau'),
         ('3', 'spes, ei f', 'espoir'),
         ('4', 'sol, solis, m', 'soleil')]
    with pytest.raises(ColumnsDoNotMatchError) as excinfo:
        update_table('table1', 3, ['spes, ei', 'f', 'espoir'])
    assert str(excinfo.value) == '"[\'spes, ei\', \'f\', \'espoir\']" '\
        'requires 3 columns, but "table1" has 2 columns ("col1" and "col2").'
コード例 #5
0
def test_remove_row(testdb):
    with pytest.raises(NoSuchTableError) as excinfo:
        remove_row('table3', 2)
    assert str(excinfo.value) == 'Cannot find a table named "table3"'
    with pytest.raises(NoSuchRowError) as excinfo:
        remove_row('table1', 7)
    assert str(excinfo.value) == 'Cannot find a row number 7 in "table1"'
    remove_row('table1', 2)
    assert get_table('table1') \
        == [('1', 'adventus,  us, m.', 'arrivée'),
            ('2', 'candidus,  a, um', 'blanc'),
            ('3', 'sol, solis, m', 'soleil')]
コード例 #6
0
def test_create_table(testdb, mocker):
    create_table('table3', ['infinitif', 'passé', 'français'], [
        ('bieten', 'bot, hat geboten', 'offrir'),
        ('bleiben', 'blieb, ist geblieben', 'rester'),
        ('gelingen', 'gelang, ist gelungen', 'réussir'),
        ('schmelzen', 'schmolz, ist geschmolzen', 'fondre'),
        ('ziegen', 'zog, hat OU ist gezogen', 'tirer OU déménager'),
    ])
    assert list_tables() == ['table1', 'table2', 'table3']
    assert get_table('table3') \
        == [('1', 'bieten', 'bot, hat geboten', 'offrir'),
            ('2', 'bleiben', 'blieb, ist geblieben', 'rester'),
            ('3', 'gelingen', 'gelang, ist gelungen', 'réussir'),
            ('4', 'schmelzen', 'schmolz, ist geschmolzen', 'fondre'),
            ('5', 'ziegen', 'zog, hat OU ist gezogen', 'tirer OU déménager'),
            ]
コード例 #7
0
def test_merge_tables(testdb):
    with pytest.raises(ColumnsDoNotMatchError) as excinfo:
        merge_tables('table1', 'table2')
    assert str(excinfo.value) == '"table1" requires 2 columns, but "table2" '\
        'has 3 columns ("col1", "col2" and "col3").'
    create_table('table3', ['col3', 'col4'], [('spes, ei f', 'espoir'),
                                              ('amor,  oris, m.', 'amour'),
                                              ('anima,  ae, f.', 'coeur, âme'),
                                              ('hiems, mis,f', 'hiver')])
    merge_tables('table1', 'table3')
    assert get_table('table3') \
        == [('1', 'spes, ei f', 'espoir'),
            ('2', 'amor,  oris, m.', 'amour'),
            ('3', 'anima,  ae, f.', 'coeur, âme'),
            ('4', 'hiems, mis,f', 'hiver'),
            ('5', 'adventus,  us, m.', 'arrivée'),
            ('6', 'aqua , ae, f', 'eau'),
            ('7', 'candidus,  a, um', 'blanc'),
            ('8', 'sol, solis, m', 'soleil')
            ]
コード例 #8
0
def test_get_table(testdb):
    assert get_table('table2') \
        == [('1', 'begin', 'began, begun', 'commencer'),
            ('2', 'break', 'broke, broken', 'casser'),
            ('3', 'do', 'did, done', 'faire'),
            ('4', 'give', 'gave, given', 'donner')]
    assert get_table('table2', include_headers=True) \
        == [('id', 'col1', 'col2', 'col3'),
            ('1', 'begin', 'began, begun', 'commencer'),
            ('2', 'break', 'broke, broken', 'casser'),
            ('3', 'do', 'did, done', 'faire'),
            ('4', 'give', 'gave, given', 'donner')]
    with pytest.raises(NoSuchTableError) as excinfo:
        get_table('table3')
    assert str(excinfo.value) == 'Cannot find a table named "table3"'
    with pytest.raises(NoSuchColumnError) as excinfo:
        get_table('table1', sort=3)
    assert str(excinfo.value) == 'Cannot find a column number 3 in "table1"'
    assert get_table('table2', include_headers=True, sort=3) \
        == [('id', 'col1', 'col2', 'col3'),
            ('2', 'break', 'broke, broken', 'casser'),
            ('1', 'begin', 'began, begun', 'commencer'),
            ('4', 'give', 'gave, given', 'donner'),
            ('3', 'do', 'did, done', 'faire')]