Skip to content

Commit

Permalink
markdown generation test
Browse files Browse the repository at this point in the history
  • Loading branch information
dogversioning committed Feb 27, 2024
1 parent d55d6b6 commit 30a6fe9
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cumulus_library/study_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
48 changes: 48 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" tests for the cli interface to studies """

import builtins
import filecmp
import glob
import io
import os
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions tests/test_data/study_python_valid_generated.md
Original file line number Diff line number Diff line change
@@ -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| |

0 comments on commit 30a6fe9

Please sign in to comment.