Skip to content

Commit

Permalink
test: adds isolated tests for assemble and regenerate task
Browse files Browse the repository at this point in the history
Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Jul 26, 2023
1 parent 52bbd7e commit fb760f9
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/trestlebot/tasks/test_assemble_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import os
import pathlib
from unittest.mock import Mock, patch

import pytest
from trestle.core.commands.author.catalog import CatalogGenerate
Expand All @@ -27,6 +28,7 @@

from tests import testutils
from trestlebot.tasks.assemble_task import AssembleTask
from trestlebot.tasks.authored.base_authored import AuthorObjectBase
from trestlebot.tasks.authored.types import AuthoredType


Expand All @@ -41,6 +43,33 @@
ssp_md_dir = "md_ssp"


def test_assemble_task_isolated(tmp_trestle_dir: str) -> None:
"""Test the assemble task isolated from AuthoredObject implementation"""
trestle_root = pathlib.Path(tmp_trestle_dir)
md_path = os.path.join(cat_md_dir, test_cat)
args = testutils.setup_for_catalog(trestle_root, test_cat, md_path)
cat_generate = CatalogGenerate()
assert cat_generate._run(args) == 0

mock = Mock(spec=AuthorObjectBase)

assemble_task = AssembleTask(
tmp_trestle_dir,
AuthoredType.CATALOG.value,
cat_md_dir,
"",
)

with patch(
"trestlebot.tasks.authored.types.get_authored_object"
) as mock_get_authored_object:
mock_get_authored_object.return_value = mock

assert assemble_task.execute() == 0

mock.assemble.assert_called_once_with(markdown_path=md_path)


def test_catalog_assemble_task(tmp_trestle_dir: str) -> None:
"""Test catalog assemble at the task level"""
trestle_root = pathlib.Path(tmp_trestle_dir)
Expand Down
29 changes: 29 additions & 0 deletions tests/trestlebot/tasks/test_regenerate_task .py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import argparse
import os
import pathlib
from unittest.mock import Mock, patch

import pytest
from trestle.core.commands.author.ssp import SSPAssemble, SSPGenerate

from tests import testutils
from trestlebot.tasks.authored.base_authored import AuthorObjectBase
from trestlebot.tasks.authored.types import AuthoredType
from trestlebot.tasks.regenerate_task import RegenerateTask

Expand All @@ -39,6 +41,33 @@
ssp_md_dir = "md_ssp"


def test_regenerate_task_isolated(tmp_trestle_dir: str) -> None:
"""Test the regenerate task isolated from AuthoredObject implementation"""
trestle_root = pathlib.Path(tmp_trestle_dir)
md_path = os.path.join(cat_md_dir, test_cat)
_ = testutils.setup_for_catalog(trestle_root, test_cat, md_path)

mock = Mock(spec=AuthorObjectBase)

regenerate_task = RegenerateTask(
tmp_trestle_dir,
AuthoredType.CATALOG.value,
cat_md_dir,
"",
)

with patch(
"trestlebot.tasks.authored.types.get_authored_object"
) as mock_get_authored_object:
mock_get_authored_object.return_value = mock

assert regenerate_task.execute() == 0

mock.regenerate.assert_called_once_with(
model_path=f"catalogs/{test_cat}", markdown_path=cat_md_dir
)


def test_catalog_regenerate_task(tmp_trestle_dir: str) -> None:
"""Test catalog regenerate at the task level"""
trestle_root = pathlib.Path(tmp_trestle_dir)
Expand Down

0 comments on commit fb760f9

Please sign in to comment.