From ac73ee47f6db82a2668ad2d47a05e13116a825ad Mon Sep 17 00:00:00 2001 From: jasquat Date: Tue, 23 May 2023 15:50:55 -0400 Subject: [PATCH] fixed tests failing for typeguard w/ burnettk --- .../process_model_test_runner_service.py | 13 +++++++---- .../unit/test_process_model_test_runner.py | 23 ++++--------------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_test_runner_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_test_runner_service.py index 4b833139a..fc683ff56 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_test_runner_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_model_test_runner_service.py @@ -1,5 +1,6 @@ import glob import json +from typing import Union import os import re import traceback @@ -89,6 +90,8 @@ JSON file format: } } """ + + class ProcessModelTestRunner: """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 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: if self.execute_task_callback: self.execute_task_callback(spiff_task, test_case_task_key, test_case_task_properties) @@ -280,10 +283,10 @@ class ProcessModelTestRunner: return None 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: 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: self.task_data_index[test_case_task_key] = 0 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)) 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 with open(bpmn_file, "rb") as f_handle: data = f_handle.read() @@ -340,7 +343,7 @@ class ProcessModelTestRunner: def _get_relative_path_of_bpmn_file(self, bpmn_file: str) -> str: 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") test_case_error_details = TestCaseErrorDetails(error_messages=error_messages) if isinstance(exception, WorkflowTaskException): diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model_test_runner.py b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model_test_runner.py index 094cf777e..bdf8633a7 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model_test_runner.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_model_test_runner.py @@ -1,15 +1,12 @@ import os -from typing import Any +# from typing import Any from typing import Optional import pytest from flask import current_app from flask import Flask -from pytest_mock import MockerFixture 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 ProcessModelTestRunner @@ -19,7 +16,6 @@ class TestProcessModelTestRunner(BaseTest): self, app: Flask, with_db_and_bpmn_file_cleanup: None, - with_mocked_root_path: Any, ) -> None: process_model_test_runner = self._run_model_tests("script-task") assert len(process_model_test_runner.test_case_results) == 1 @@ -28,9 +24,8 @@ class TestProcessModelTestRunner(BaseTest): self, app: Flask, with_db_and_bpmn_file_cleanup: None, - with_mocked_root_path: Any, ) -> 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): process_model_test_runner.run() assert process_model_test_runner.all_test_cases_passed(), process_model_test_runner.test_case_results @@ -39,7 +34,6 @@ class TestProcessModelTestRunner(BaseTest): self, app: Flask, with_db_and_bpmn_file_cleanup: None, - with_mocked_root_path: Any, ) -> None: process_model_test_runner = self._run_model_tests() assert len(process_model_test_runner.test_case_results) > 1 @@ -48,7 +42,6 @@ class TestProcessModelTestRunner(BaseTest): self, app: Flask, with_db_and_bpmn_file_cleanup: None, - with_mocked_root_path: Any, ) -> None: process_model_test_runner = self._run_model_tests(parent_directory="expected-to-fail") assert len(process_model_test_runner.test_case_results) == 1 @@ -57,7 +50,6 @@ class TestProcessModelTestRunner(BaseTest): self, app: Flask, with_db_and_bpmn_file_cleanup: None, - with_mocked_root_path: Any, ) -> None: 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 @@ -83,7 +75,6 @@ class TestProcessModelTestRunner(BaseTest): self, app: Flask, with_db_and_bpmn_file_cleanup: None, - with_mocked_root_path: Any, ) -> None: process_model_test_runner = self._run_model_tests(bpmn_process_directory_name="call-activity") assert len(process_model_test_runner.test_case_results) == 1 @@ -92,7 +83,6 @@ class TestProcessModelTestRunner(BaseTest): self, app: Flask, with_db_and_bpmn_file_cleanup: None, - with_mocked_root_path: Any, ) -> None: process_model_test_runner = self._run_model_tests(bpmn_process_directory_name="service-task") assert len(process_model_test_runner.test_case_results) == 1 @@ -101,7 +91,6 @@ class TestProcessModelTestRunner(BaseTest): self, app: Flask, with_db_and_bpmn_file_cleanup: None, - with_mocked_root_path: Any, ) -> None: 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 @@ -113,7 +102,7 @@ class TestProcessModelTestRunner(BaseTest): test_case_file: Optional[str] = None, test_case_identifier: Optional[str] = None, ) -> 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 if 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() return process_model_test_runner - @pytest.fixture() - def with_mocked_root_path(self, mocker: MockerFixture) -> None: - path = os.path.join( + def root_path(self) -> str: + return os.path.join( current_app.instance_path, "..", "..", @@ -141,4 +129,3 @@ class TestProcessModelTestRunner(BaseTest): "data", "bpmn_unit_test_process_models", ) - mocker.patch.object(FileSystemService, attribute="root_path", return_value=path)