def test_add_parse_err(testdb, capsys, mocker): f = os.path.join(TESTS_DATADIR, 'latin_add_parse_err.txt') commands.add('table1', f, '<Latin>:<Français>') commands.show('table1') captured = capsys.readouterr() assert captured.out == \ ' id | col1 | col2 \n'\ '----+---------------------+------------------------------------\n'\ ' 1 | adventus, us, m. | arrivée \n'\ ' 2 | aqua , ae, f | eau \n'\ ' 3 | candidus, a, um | blanc \n'\ ' 4 | sol, solis, m | soleil \n'\ ' 5 | judex, dicis, m. | juge \n'\ ' 6 | judicium, i, n. | jugement, décision \n'\ ' 7 | jus, uris, n | droit \n'\ ' 8 | justitia, ae, f. | justice (vertu) \n'\ ' 9 | juvenis, is , m | homme jeune (30 à45 ans) \n'\ ' 10 | juventus, utis, f. | jeunesse \n'\ ' 11 | labor, oris, m. | peine, souffrance, travail pénible \n'\ ' 12 | lacrima, ae, f. | larme \n' assert captured.err == \ 'WARNING: following lines do not match the pattern '\ '"<Latin>:<Français>" and have been ignored:\n'\ '✘ laetitia, ae, f. la joie\n'\ 'End of ignored lines list\n'
def test_create_with_parse_errors(testdb, capsys, mocker): m = mocker.patch('memini.core.template.create') f = os.path.join(TESTS_DATADIR, 'latin_parse_err.txt') commands.create('latin2', f, '<Latin>:<Français>') m.assert_called_with('latin2') captured = capsys.readouterr() assert captured.err == \ 'WARNING: following lines do not match the pattern '\ '"<Latin>:<Français>" and have been ignored:\n'\ '✘ aedilis, is, m. édile\n'\ '✘ ambitus, us, m. la brigue\n'\ '✘ amicitia, ae, f. amitié\n'\ 'End of ignored lines list\n' commands.show('latin2') captured = capsys.readouterr() assert captured.out == \ ' id | Latin | Français \n'\ '----+----------------------+---------------------\n'\ ' 1 | actio, onis, f. | procès , plaidoirie \n'\ ' 2 | admiratio, onis, f. | admiration \n'\ ' 3 | adventus, us, m. | arrivée \n'\ ' 4 | aetas, atis, f âge | vie \n'\ ' 5 | ambitio, onis, f. | ambition \n'\ ' 6 | amicus, i, m. | ami \n'\ ' 7 | amor, oris, m. | amour \n'\ ' 8 | anima, ae, f. | coeur, âme \n'
def test_show(testdb, capsys): commands.show('table2') captured = capsys.readouterr() assert captured.out == \ " id | col1 | col2 | col3 \n"\ "----+-------+---------------+-----------\n"\ " 1 | begin | began, begun | commencer \n"\ " 2 | break | broke, broken | casser \n"\ " 3 | do | did, done | faire \n"\ " 4 | give | gave, given | donner \n"
def test_update(testdb, capsys): commands.update('table2', ' 2 | take | took, taken | prendre ') commands.show('table2') captured = capsys.readouterr() assert captured.out == \ " id | col1 | col2 | col3 \n"\ "----+--------+---------------+--------------\n"\ " 1 | begin | began, begun | commencer \n"\ " 2 | take | took, taken | prendre \n"\ " 3 | do | did, done | faire \n"\ " 4 | give | gave, given | donner \n"
def test_duplicate(testdb, fs, capsys): fs.create_file(template.path('table1')) commands.duplicate('table1', 'table3') assert os.path.exists(template.path('table1')) assert os.path.exists(template.path('table3')) assert database.table_exists('table1') assert database.table_exists('table3') commands.show('table1') table1_content = capsys.readouterr().out commands.show('table3') table3_content = capsys.readouterr().out assert table1_content == table3_content
def test_create(testdb, capsys, mocker): m = mocker.patch('memini.core.template.create') f = os.path.join(TESTS_DATADIR, 'latin.txt') commands.create('latin', f, '<Latin>:<Français>') m.assert_called_with('latin') commands.show('latin') captured = capsys.readouterr() assert captured.out == \ ' id | Latin | Français \n'\ '----+----------------------+---------------------\n'\ ' 1 | actio, onis, f. | procès , plaidoirie \n'\ ' 2 | admiratio, onis, f. | admiration \n'\ ' 3 | adventus, us, m. | arrivée \n'\ ' 4 | aedilis, is, m. | édile \n'\ ' 5 | aetas, atis, f âge | vie \n'\ ' 6 | ambitio, onis, f. | ambition \n'\ ' 7 | ambitus, us, m. | la brigue \n'\ ' 8 | amicitia, ae, f. | amitié \n'\ ' 9 | amicus, i, m. | ami \n'\ ' 10 | amor, oris, m. | amour \n'\ ' 11 | anima, ae, f. | coeur, âme \n'
def test_merge(mocker, testdb, fs, capsys): f1 = os.path.join(TESTS_DATADIR, 'latin_add.txt') f2 = os.path.join(TESTS_DATADIR, 'latin.txt') fs.add_real_file(f1) fs.add_real_file(f2) # No template for source table: automatic creation def create_fake_template3(*args): fs.create_file(template.path('table3')) # No template for source table: automatic creation def create_fake_template4(*args): fs.create_file(template.path('table4')) # No template for source table: automatic creation def create_fake_template5(*args): fs.create_file(template.path('table5')) mocker.patch('memini.core.template.create', side_effect=create_fake_template3) commands.create('table3', f1, '<Latin>:<Français>') mocker.patch('memini.core.template.create', side_effect=create_fake_template5) commands.create('table5', f2, '<Latin>:<Français>') mocker.patch('memini.core.template.create', side_effect=create_fake_template4) commands.merge(['table1', 'table3'], 'table4') commands.show('table4') captured = capsys.readouterr() assert captured.out == \ ' id | col1 | col2 \n'\ '----+---------------------+------------------------------------\n'\ ' 1 | adventus, us, m. | arrivée \n'\ ' 2 | aqua , ae, f | eau \n'\ ' 3 | candidus, a, um | blanc \n'\ ' 4 | sol, solis, m | soleil \n'\ ' 5 | judex, dicis, m. | juge \n'\ ' 6 | judicium, i, n. | jugement, décision \n'\ ' 7 | jus, uris, n | droit \n'\ ' 8 | justitia, ae, f. | justice (vertu) \n'\ ' 9 | juvenis, is , m | homme jeune (30 à45 ans) \n'\ ' 10 | juventus, utis, f. | jeunesse \n'\ ' 11 | labor, oris, m. | peine, souffrance, travail pénible \n'\ ' 12 | lacrima, ae, f. | larme \n'\ ' 13 | laetitia, ae, f. | la joie \n' os.remove(template.path('table5')) mocker.patch('memini.core.template.create', side_effect=create_fake_template5) commands.merge(['table1'], 'table5') commands.show('table5') captured = capsys.readouterr() assert captured.out == \ ' id | Latin | Français \n'\ '----+----------------------+---------------------\n'\ ' 1 | actio, onis, f. | procès , plaidoirie \n'\ ' 2 | admiratio, onis, f. | admiration \n'\ ' 3 | adventus, us, m. | arrivée \n'\ ' 4 | aedilis, is, m. | édile \n'\ ' 5 | aetas, atis, f âge | vie \n'\ ' 6 | ambitio, onis, f. | ambition \n'\ ' 7 | ambitus, us, m. | la brigue \n'\ ' 8 | amicitia, ae, f. | amitié \n'\ ' 9 | amicus, i, m. | ami \n'\ ' 10 | amor, oris, m. | amour \n'\ ' 11 | anima, ae, f. | coeur, âme \n'\ ' 12 | adventus, us, m. | arrivée \n'\ ' 13 | aqua , ae, f | eau \n'\ ' 14 | candidus, a, um | blanc \n'\ ' 15 | sol, solis, m | soleil \n'
def test_show_nonexistent(testdb): with pytest.raises(NoSuchTableError) as excinfo: commands.show('nonexistent') assert str(excinfo.value) == 'Cannot find a table named "nonexistent"'