From 30a6fe93e35b9a591551a236c1bdf924eb183c5d Mon Sep 17 00:00:00 2001 From: Matt Garber Date: Tue, 27 Feb 2024 15:12:50 -0500 Subject: [PATCH] markdown generation test --- cumulus_library/study_parser.py | 3 +- tests/test_cli.py | 48 +++++++++++++++++++ .../test_data/study_python_valid_generated.md | 15 ++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 tests/test_data/study_python_valid_generated.md diff --git a/cumulus_library/study_parser.py b/cumulus_library/study_parser.py index 4b60e0f5..46407310 100644 --- a/cumulus_library/study_parser.py +++ b/cumulus_library/study_parser.py @@ -575,11 +575,12 @@ def run_generate_markdown( tables = [x[0] for x in cursor.execute(query).fetchall()] query = base_templates.get_column_datatype_query( - schema_name=schema, table_name=tables, include_table_names=True + schema_name=schema, table_names=tables, include_table_names=True ) study_df = pandas.DataFrame( cursor.execute(query).fetchall(), columns=["Table", "Column", "Type"] ) + print(self._study_path) with open( self._study_path / f"{self.get_study_prefix()}_generated.md", "w" ) as f: diff --git a/tests/test_cli.py b/tests/test_cli.py index 37356982..3045cb2d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,6 +1,7 @@ """ tests for the cli interface to studies """ import builtins +import filecmp import glob import io import os @@ -193,6 +194,53 @@ def test_generate_sql(mock_path, tmp_path): assert "CREATE TABLE IF NOT EXISTS study_python_valid__table" in query +@mock.patch.dict( + os.environ, + clear=True, +) +@mock.patch("sysconfig.get_path") +def test_generate_md(mock_path, tmp_path): + mock_path.return_value = f"{tmp_path}/study_python_valid/" + with does_not_raise(): + shutil.copytree( + f"{Path(__file__).resolve().parents[0]}/test_data/study_python_valid", + f"{tmp_path}/study_python_valid/", + ) + args = duckdb_args( + [ + "build", + "-t", + "study_python_valid", + "-s", + f"{tmp_path}", + "--database", + "test", + ], + tmp_path, + ) + + cli.main(cli_args=args) + args = duckdb_args( + [ + "generate-md", + "-t", + "study_python_valid", + "-s", + f"{tmp_path}", + "--database", + "test", + ], + tmp_path, + ) + cli.main(cli_args=args) + test_file = f"{tmp_path}/study_python_valid/study_python_valid_generated.md" + ref_file = ( + pathlib.Path(__file__).resolve().parent + / "test_data/study_python_valid_generated.md" + ) + assert filecmp.cmp(test_file, ref_file, shallow=True) + + @mock.patch.dict( os.environ, clear=True, diff --git a/tests/test_data/study_python_valid_generated.md b/tests/test_data/study_python_valid_generated.md new file mode 100644 index 00000000..33dd60d7 --- /dev/null +++ b/tests/test_data/study_python_valid_generated.md @@ -0,0 +1,15 @@ +## study_python_valid base tables + +### study_python_valid__lib_transactions +| Column | Type |Description| +|---------------|---------|-----------| +|study_name |VARCHAR | | +|library_version|VARCHAR | | +|status |VARCHAR | | +|event_time |TIMESTAMP| | + +### study_python_valid__table +|Column| Type |Description| +|------|-------|-----------| +|test |INTEGER| | +