From 7d8cf4274c15c0396e71111c18b1a33906594a93 Mon Sep 17 00:00:00 2001 From: Justus Kuhlmann Date: Mon, 1 Dec 2025 18:42:53 +0100 Subject: [PATCH] add tests for init and version cli commands --- tests/cli_test.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/cli_test.py diff --git a/tests/cli_test.py b/tests/cli_test.py new file mode 100644 index 0000000..6f3cc09 --- /dev/null +++ b/tests/cli_test.py @@ -0,0 +1,81 @@ +from typer.testing import CliRunner +from corrlib.cli import app +import os +import sqlite3 as sql + + +runner = CliRunner() + + +def test_version(): + result = runner.invoke(app, ["--version"]) + assert result.exit_code == 0 + assert "corrlib" in result.output + + +def test_init_folders(tmp_path): + dataset_path = tmp_path / "test_dataset" + result = runner.invoke(app, ["init", "--dataset", str(dataset_path)]) + assert result.exit_code == 0 + assert os.path.exists(str(dataset_path)) + assert os.path.exists(str(dataset_path / "backlogger.db")) + + +def test_init_db(tmp_path): + dataset_path = tmp_path / "test_dataset" + result = runner.invoke(app, ["init", "--dataset", str(dataset_path)]) + assert result.exit_code == 0 + assert os.path.exists(str(dataset_path / "backlogger.db")) + conn = sql.connect(str(dataset_path / "backlogger.db")) + cursor = conn.cursor() + cursor.execute("SELECT name FROM sqlite_master WHERE type='table';") + tables = cursor.fetchall() + expected_tables = [ + 'projects', + 'backlogs', + ] + table_names = [table[0] for table in tables] + for expected_table in expected_tables: + assert expected_table in table_names + + cursor.execute("SELECT * FROM projects;") + projects = cursor.fetchall() + assert len(projects) == 0 + + cursor.execute("SELECT * FROM backlogs;") + backlogs = cursor.fetchall() + assert len(backlogs) == 0 + + cursor.execute("PRAGMA table_info('projects');") + project_columns = cursor.fetchall() + expected_project_columns = [ + "id", + "aliases", + "customTags", + "owner", + "code", + "created_at", + "updated_at" + ] + project_column_names = [col[1] for col in project_columns] + for expected_col in expected_project_columns: + assert expected_col in project_column_names + + cursor.execute("PRAGMA table_info('backlogs');") + backlog_columns = cursor.fetchall() + expected_backlog_columns = [ + "id", + "name", + "ensemble", + "code", + "path", + "project", + "customTags", + "parameters", + "parameter_file", + "created_at", + "updated_at" + ] + backlog_column_names = [col[1] for col in backlog_columns] + for expected_col in expected_backlog_columns: + assert expected_col in backlog_column_names \ No newline at end of file