fixed tests failing for typeguard w/ burnettk

This commit is contained in:
jasquat 2023-05-23 15:50:55 -04:00
parent 16e0952686
commit ac73ee47f6
2 changed files with 13 additions and 23 deletions

View File

@ -1,5 +1,6 @@
import glob import glob
import json import json
from typing import Union
import os import os
import re import re
import traceback import traceback
@ -89,6 +90,8 @@ JSON file format:
} }
} }
""" """
class ProcessModelTestRunner: class ProcessModelTestRunner:
"""Generic test runner code. May move into own library at some point. """Generic test runner code. May move into own library at some point.
@ -257,7 +260,7 @@ class ProcessModelTestRunner:
self.bpmn_processes_to_file_mappings[bpmn_process_identifier] = file_norm self.bpmn_processes_to_file_mappings[bpmn_process_identifier] = file_norm
def _execute_task( def _execute_task(
self, spiff_task: SpiffTask, test_case_task_key: str, test_case_task_properties: Optional[dict] self, spiff_task: SpiffTask, test_case_task_key: Optional[str], test_case_task_properties: Optional[dict]
) -> None: ) -> None:
if self.execute_task_callback: if self.execute_task_callback:
self.execute_task_callback(spiff_task, test_case_task_key, test_case_task_properties) self.execute_task_callback(spiff_task, test_case_task_key, test_case_task_properties)
@ -280,10 +283,10 @@ class ProcessModelTestRunner:
return None return None
def _default_execute_task( def _default_execute_task(
self, spiff_task: SpiffTask, test_case_task_key: str, test_case_task_properties: Optional[dict] self, spiff_task: SpiffTask, test_case_task_key: Optional[str], test_case_task_properties: Optional[dict]
) -> None: ) -> None:
if spiff_task.task_spec.manual or spiff_task.task_spec.__class__.__name__ == "ServiceTask": if spiff_task.task_spec.manual or spiff_task.task_spec.__class__.__name__ == "ServiceTask":
if test_case_task_properties and "data" in test_case_task_properties: if test_case_task_key and test_case_task_properties and "data" in test_case_task_properties:
if test_case_task_key not in self.task_data_index: if test_case_task_key not in self.task_data_index:
self.task_data_index[test_case_task_key] = 0 self.task_data_index[test_case_task_key] = 0
task_data_length = len(test_case_task_properties["data"]) task_data_length = len(test_case_task_properties["data"])
@ -309,7 +312,7 @@ class ProcessModelTestRunner:
related_bpmn_files.extend(self._find_related_bpmn_files(new_file)) related_bpmn_files.extend(self._find_related_bpmn_files(new_file))
return related_bpmn_files return related_bpmn_files
def _get_etree_from_bpmn_file(self, bpmn_file: str) -> etree.Element: def _get_etree_from_bpmn_file(self, bpmn_file: str) -> etree._Element:
data = None data = None
with open(bpmn_file, "rb") as f_handle: with open(bpmn_file, "rb") as f_handle:
data = f_handle.read() data = f_handle.read()
@ -340,7 +343,7 @@ class ProcessModelTestRunner:
def _get_relative_path_of_bpmn_file(self, bpmn_file: str) -> str: def _get_relative_path_of_bpmn_file(self, bpmn_file: str) -> str:
return os.path.relpath(bpmn_file, start=self.process_model_directory_path) return os.path.relpath(bpmn_file, start=self.process_model_directory_path)
def _exception_to_test_case_error_details(self, exception: Exception) -> TestCaseErrorDetails: def _exception_to_test_case_error_details(self, exception: Union[Exception, WorkflowTaskException]) -> TestCaseErrorDetails:
error_messages = str(exception).split("\n") error_messages = str(exception).split("\n")
test_case_error_details = TestCaseErrorDetails(error_messages=error_messages) test_case_error_details = TestCaseErrorDetails(error_messages=error_messages)
if isinstance(exception, WorkflowTaskException): if isinstance(exception, WorkflowTaskException):

View File

@ -1,15 +1,12 @@
import os import os
from typing import Any # from typing import Any
from typing import Optional from typing import Optional
import pytest import pytest
from flask import current_app from flask import current_app
from flask import Flask from flask import Flask
from pytest_mock import MockerFixture
from tests.spiffworkflow_backend.helpers.base_test import BaseTest from tests.spiffworkflow_backend.helpers.base_test import BaseTest
from spiffworkflow_backend.models.task import TaskModel # noqa: F401
from spiffworkflow_backend.services.file_system_service import FileSystemService
from spiffworkflow_backend.services.process_model_test_runner_service import NoTestCasesFoundError from spiffworkflow_backend.services.process_model_test_runner_service import NoTestCasesFoundError
from spiffworkflow_backend.services.process_model_test_runner_service import ProcessModelTestRunner from spiffworkflow_backend.services.process_model_test_runner_service import ProcessModelTestRunner
@ -19,7 +16,6 @@ class TestProcessModelTestRunner(BaseTest):
self, self,
app: Flask, app: Flask,
with_db_and_bpmn_file_cleanup: None, with_db_and_bpmn_file_cleanup: None,
with_mocked_root_path: Any,
) -> None: ) -> None:
process_model_test_runner = self._run_model_tests("script-task") process_model_test_runner = self._run_model_tests("script-task")
assert len(process_model_test_runner.test_case_results) == 1 assert len(process_model_test_runner.test_case_results) == 1
@ -28,9 +24,8 @@ class TestProcessModelTestRunner(BaseTest):
self, self,
app: Flask, app: Flask,
with_db_and_bpmn_file_cleanup: None, with_db_and_bpmn_file_cleanup: None,
with_mocked_root_path: Any,
) -> None: ) -> None:
process_model_test_runner = ProcessModelTestRunner(os.path.join(FileSystemService.root_path(), "DNE")) process_model_test_runner = ProcessModelTestRunner(os.path.join(self.root_path(), "DNE"))
with pytest.raises(NoTestCasesFoundError): with pytest.raises(NoTestCasesFoundError):
process_model_test_runner.run() process_model_test_runner.run()
assert process_model_test_runner.all_test_cases_passed(), process_model_test_runner.test_case_results assert process_model_test_runner.all_test_cases_passed(), process_model_test_runner.test_case_results
@ -39,7 +34,6 @@ class TestProcessModelTestRunner(BaseTest):
self, self,
app: Flask, app: Flask,
with_db_and_bpmn_file_cleanup: None, with_db_and_bpmn_file_cleanup: None,
with_mocked_root_path: Any,
) -> None: ) -> None:
process_model_test_runner = self._run_model_tests() process_model_test_runner = self._run_model_tests()
assert len(process_model_test_runner.test_case_results) > 1 assert len(process_model_test_runner.test_case_results) > 1
@ -48,7 +42,6 @@ class TestProcessModelTestRunner(BaseTest):
self, self,
app: Flask, app: Flask,
with_db_and_bpmn_file_cleanup: None, with_db_and_bpmn_file_cleanup: None,
with_mocked_root_path: Any,
) -> None: ) -> None:
process_model_test_runner = self._run_model_tests(parent_directory="expected-to-fail") process_model_test_runner = self._run_model_tests(parent_directory="expected-to-fail")
assert len(process_model_test_runner.test_case_results) == 1 assert len(process_model_test_runner.test_case_results) == 1
@ -57,7 +50,6 @@ class TestProcessModelTestRunner(BaseTest):
self, self,
app: Flask, app: Flask,
with_db_and_bpmn_file_cleanup: None, with_db_and_bpmn_file_cleanup: None,
with_mocked_root_path: Any,
) -> None: ) -> None:
process_model_test_runner = self._run_model_tests(bpmn_process_directory_name="multiple-test-files") process_model_test_runner = self._run_model_tests(bpmn_process_directory_name="multiple-test-files")
assert len(process_model_test_runner.test_case_results) == 3 assert len(process_model_test_runner.test_case_results) == 3
@ -83,7 +75,6 @@ class TestProcessModelTestRunner(BaseTest):
self, self,
app: Flask, app: Flask,
with_db_and_bpmn_file_cleanup: None, with_db_and_bpmn_file_cleanup: None,
with_mocked_root_path: Any,
) -> None: ) -> None:
process_model_test_runner = self._run_model_tests(bpmn_process_directory_name="call-activity") process_model_test_runner = self._run_model_tests(bpmn_process_directory_name="call-activity")
assert len(process_model_test_runner.test_case_results) == 1 assert len(process_model_test_runner.test_case_results) == 1
@ -92,7 +83,6 @@ class TestProcessModelTestRunner(BaseTest):
self, self,
app: Flask, app: Flask,
with_db_and_bpmn_file_cleanup: None, with_db_and_bpmn_file_cleanup: None,
with_mocked_root_path: Any,
) -> None: ) -> None:
process_model_test_runner = self._run_model_tests(bpmn_process_directory_name="service-task") process_model_test_runner = self._run_model_tests(bpmn_process_directory_name="service-task")
assert len(process_model_test_runner.test_case_results) == 1 assert len(process_model_test_runner.test_case_results) == 1
@ -101,7 +91,6 @@ class TestProcessModelTestRunner(BaseTest):
self, self,
app: Flask, app: Flask,
with_db_and_bpmn_file_cleanup: None, with_db_and_bpmn_file_cleanup: None,
with_mocked_root_path: Any,
) -> None: ) -> None:
process_model_test_runner = self._run_model_tests(bpmn_process_directory_name="loopback-to-user-task") process_model_test_runner = self._run_model_tests(bpmn_process_directory_name="loopback-to-user-task")
assert len(process_model_test_runner.test_case_results) == 1 assert len(process_model_test_runner.test_case_results) == 1
@ -113,7 +102,7 @@ class TestProcessModelTestRunner(BaseTest):
test_case_file: Optional[str] = None, test_case_file: Optional[str] = None,
test_case_identifier: Optional[str] = None, test_case_identifier: Optional[str] = None,
) -> ProcessModelTestRunner: ) -> ProcessModelTestRunner:
base_process_model_dir_path_segments = [FileSystemService.root_path(), parent_directory] base_process_model_dir_path_segments = [self.root_path(), parent_directory]
path_segments = base_process_model_dir_path_segments path_segments = base_process_model_dir_path_segments
if bpmn_process_directory_name: if bpmn_process_directory_name:
path_segments = path_segments + [bpmn_process_directory_name] path_segments = path_segments + [bpmn_process_directory_name]
@ -131,9 +120,8 @@ class TestProcessModelTestRunner(BaseTest):
), process_model_test_runner.failing_tests_formatted() ), process_model_test_runner.failing_tests_formatted()
return process_model_test_runner return process_model_test_runner
@pytest.fixture() def root_path(self) -> str:
def with_mocked_root_path(self, mocker: MockerFixture) -> None: return os.path.join(
path = os.path.join(
current_app.instance_path, current_app.instance_path,
"..", "..",
"..", "..",
@ -141,4 +129,3 @@ class TestProcessModelTestRunner(BaseTest):
"data", "data",
"bpmn_unit_test_process_models", "bpmn_unit_test_process_models",
) )
mocker.patch.object(FileSystemService, attribute="root_path", return_value=path)