From d4d62c6efb5f22c4a935a0a5feb6ec13b7c82f2b Mon Sep 17 00:00:00 2001 From: HombreLaser Date: Wed, 13 Mar 2024 19:53:36 -0600 Subject: Add missing tests --- tests/test_delete_at.py | 11 ++++++++++- tests/test_insert.py | 14 +++++++++++++- tests/test_row_at.py | 11 ++++++++++- tests/test_search.py | 12 +++++++++++- 4 files changed, 44 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/test_delete_at.py b/tests/test_delete_at.py index 02471d1..662afd9 100644 --- a/tests/test_delete_at.py +++ b/tests/test_delete_at.py @@ -1,4 +1,13 @@ +from src.program import Program + + def test_delete_at(capsys, delete_at_program): delete_at_program.run() - assert capsys.readouterr()[0] == 'Row at 1 deleted\n' \ No newline at end of file + assert capsys.readouterr()[0] == 'Row at 1 deleted\n' + + +def test_delete_at_out_of_bounds(capsys): + Program(args=['-f', './tests/test_table.csv', '-c', 'delete-at', '5']).run() + + assert capsys.readouterr()[0] == "Couldn't find row at 5\n" \ No newline at end of file diff --git a/tests/test_insert.py b/tests/test_insert.py index caaf7ff..384ae49 100644 --- a/tests/test_insert.py +++ b/tests/test_insert.py @@ -1,4 +1,16 @@ +from src.program import Program +from src.exceptions import IncompatibleRowLengthError +import pytest + + def test_insert(capsys, insert_program): insert_program.run() - assert capsys.readouterr()[0] == 'Row added!\n' \ No newline at end of file + assert capsys.readouterr()[0] == 'Row added!\n' + + +def test_out_of_bounds_insert(capsys): + Program(args=['-f', './tests/test_table.csv', '-c', 'insert', '1,2,3,4']).run() + + assert capsys.readouterr()[0] == 'Incompatible row length, got 4, expected 3\n' + diff --git a/tests/test_row_at.py b/tests/test_row_at.py index 6b7c379..82e3270 100644 --- a/tests/test_row_at.py +++ b/tests/test_row_at.py @@ -1,6 +1,15 @@ +from src.program import Program + + def test_row_at(capsys, row_at_program): row_at_program.run() assert capsys.readouterr()[0].startswith( "('1919', 'Ten Days that Shook the World', 'John Reed')" - ) \ No newline at end of file + ) + + +def test_out_of_bounds_row_at(capsys): + Program(args=['-f', './tests/test_table.csv', '-c', 'row-at', '5']).run() + + assert capsys.readouterr()[0] == 'None\n' \ No newline at end of file diff --git a/tests/test_search.py b/tests/test_search.py index ecdc550..f126f7e 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -1,4 +1,14 @@ +from src.program import Program + + def test_search(capsys, search_program): search_program.run() - assert capsys.readouterr()[0] == "('1919', 'Ten Days that Shook the World', 'John Reed')\n" \ No newline at end of file + assert capsys.readouterr()[0] == "('1919', 'Ten Days that Shook the World', 'John Reed')\n" + + +def test_failed_search(capsys): + Program(args=['-f', './tests/test_table.csv', '-c', + 'search', "This book isn't on the table"]).run() + + assert capsys.readouterr()[0] == 'Not found!\n' -- cgit v1.2.3