summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py0
-rw-r--r--tests/conftest.py36
-rw-r--r--tests/test_delete_at.py4
-rw-r--r--tests/test_get_rows.py4
-rw-r--r--tests/test_insert.py4
-rw-r--r--tests/test_row_at.py6
-rw-r--r--tests/test_search.py4
7 files changed, 58 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/__init__.py
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..f3dbc41
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,36 @@
+from src.program import Program
+from glob import iglob
+import os
+import pytest
+
+
+@pytest.fixture
+def row_at_program():
+ return Program(args=['-f', './tests/test_table.csv', '-c', 'row-at', '2'])
+
+
+@pytest.fixture
+def get_rows_program():
+ return Program(args=['-f', './tests/test_table.csv', '-c', 'get-rows', '2'])
+
+
+@pytest.fixture
+def insert_program():
+ return Program(args=['-f', './tests/test_table.csv', '-c', 'insert', '1969,Ubik,Philip K. Dick'])
+
+
+@pytest.fixture
+def search_program():
+ return Program(args=['-f', './tests/test_table.csv', '-c', 'search', 'Ten Days that Shook the World'])
+
+
+@pytest.fixture
+def delete_at_program():
+ return Program(args=['-f', './tests/test_table.csv', '-c', 'delete-at', '1'])
+
+
+@pytest.fixture(scope='session', autouse=True)
+def delete_created_csv_files():
+ yield
+ for file in iglob("./new_*.csv"):
+ os.remove(file) \ No newline at end of file
diff --git a/tests/test_delete_at.py b/tests/test_delete_at.py
new file mode 100644
index 0000000..02471d1
--- /dev/null
+++ b/tests/test_delete_at.py
@@ -0,0 +1,4 @@
+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
diff --git a/tests/test_get_rows.py b/tests/test_get_rows.py
new file mode 100644
index 0000000..51b1c43
--- /dev/null
+++ b/tests/test_get_rows.py
@@ -0,0 +1,4 @@
+def test_get_rows(capsys, get_rows_program):
+ get_rows_program.run()
+
+ assert capsys.readouterr()[0] == "('1985', 'Blood Meridian', 'Cormac McCarthy')\n('1851', 'Moby Dick', 'Herman Melville')\n" \ No newline at end of file
diff --git a/tests/test_insert.py b/tests/test_insert.py
new file mode 100644
index 0000000..caaf7ff
--- /dev/null
+++ b/tests/test_insert.py
@@ -0,0 +1,4 @@
+def test_insert(capsys, insert_program):
+ insert_program.run()
+
+ assert capsys.readouterr()[0] == 'Row added!\n' \ No newline at end of file
diff --git a/tests/test_row_at.py b/tests/test_row_at.py
new file mode 100644
index 0000000..6b7c379
--- /dev/null
+++ b/tests/test_row_at.py
@@ -0,0 +1,6 @@
+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
diff --git a/tests/test_search.py b/tests/test_search.py
new file mode 100644
index 0000000..ecdc550
--- /dev/null
+++ b/tests/test_search.py
@@ -0,0 +1,4 @@
+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