33import inspect
44import logging
55import os
6- from typing import Any , Callable
6+ from typing import TYPE_CHECKING , Any , Callable
77from unittest .mock import MagicMock , call , patch
88
99import httpx
1212from odoo_data_flow .lib import mapper
1313from odoo_data_flow .lib .internal .exceptions import SkippingError
1414
15+ if TYPE_CHECKING :
16+ import pytest_mock
17+
1518# Import MapperFunc for type hinting in this test file
1619from odoo_data_flow .lib .mapper import MapperFunc
1720
@@ -70,7 +73,7 @@ def concat_fun(line: LineDict, state: StateDict) -> str:
7073
7174# --- Pytest Fixtures for Patching ---
7275@pytest .fixture (autouse = True )
73- def mock_mapper_dependencies (mocker : MagicMock ) -> None :
76+ def mock_mapper_dependencies (mocker : "pytest_mock.MockerFixture" ) -> None :
7477 """Fixture to mock external dependencies in mapper.py."""
7578 mocker .patch ("odoo_data_flow.lib.mapper.to_m2o" , side_effect = _mock_to_m2o )
7679 mocker .patch (
@@ -105,7 +108,7 @@ def test_val_postprocess_builtin() -> None:
105108 assert mapper_func (LINE_SIMPLE , {}) == "a"
106109
107110
108- def test_val_postprocess_fallback (mocker : MagicMock ) -> None :
111+ def test_val_postprocess_fallback (mocker : "pytest_mock.MockerFixture" ) -> None :
109112 """Test post process fallback.
110113
111114 Tests the val mapper's fallback from a 2-arg to a 1-arg postprocess call.
@@ -280,7 +283,7 @@ def test_binary_url_map_empty() -> None:
280283 assert mapper_func (LINE_SIMPLE , {}) == ""
281284
282285
283- def test_binary_url_map_skip_on_not_found (mocker : MagicMock ) -> None :
286+ def test_binary_url_map_skip_on_not_found (mocker : "pytest_mock.MockerFixture" ) -> None :
284287 """Tests that binary_url_map raises SkippingError when request fails."""
285288 mock_httpx_get = mocker .patch ("odoo_data_flow.lib.mapper.httpx.get" )
286289 mock_httpx_get .side_effect = httpx .RequestError (
@@ -292,7 +295,7 @@ def test_binary_url_map_skip_on_not_found(mocker: MagicMock) -> None:
292295 mapper_func (LINE_SIMPLE , {})
293296
294297
295- def test_binary_url_map_request_exception (mocker : MagicMock ) -> None :
298+ def test_binary_url_map_request_exception (mocker : "pytest_mock.MockerFixture" ) -> None :
296299 """Tests that a warning is logged when a URL request fails and skip=False."""
297300 mock_httpx_get = mocker .patch ("odoo_data_flow.lib.mapper.httpx.get" )
298301 mock_log_warning = mocker .patch ("odoo_data_flow.lib.mapper.log.warning" )
@@ -451,7 +454,7 @@ def test_map_val_m2m_with_non_string_key() -> None:
451454 assert mapper_func ({}, {}) == "One"
452455
453456
454- def test_binary_with_path_prefix (mocker : MagicMock ) -> None :
457+ def test_binary_with_path_prefix (mocker : "pytest_mock.MockerFixture" ) -> None :
455458 """Tests the binary mapper with a path_prefix."""
456459 mock_open = mocker .patch (
457460 "builtins.open" , mocker .mock_open (read_data = b"file_content" )
@@ -470,7 +473,7 @@ def test_m2o_att_name() -> None:
470473 assert result == {"att1" : "prefix.att1" , "att3" : "prefix.att3" }
471474
472475
473- def test_m2o_fun_state_present_but_unused (mocker : MagicMock ) -> None :
476+ def test_m2o_fun_state_present_but_unused (mocker : "pytest_mock.MockerFixture" ) -> None :
474477 """Confirms m2o_fun works correctly when 'state' is provided but not directly used.
475478
476479 Args:
@@ -497,7 +500,7 @@ def test_m2o_fun_state_present_but_unused(mocker: MagicMock) -> None:
497500
498501
499502def test_m2o_fun_with_skip_and_empty_value_state_unused (
500- mocker : MagicMock ,
503+ mocker : "pytest_mock.MockerFixture" ,
501504) -> None :
502505 """Tests m2o_fun with 'skip' when value is empty, confirming state is unused.
503506
@@ -525,7 +528,9 @@ def test_m2o_fun_with_skip_and_empty_value_state_unused(
525528 assert state == {"initial" : "value" }
526529
527530
528- def test_m2o_map_fun_state_passed_to_concat_mapper (mocker : MagicMock ) -> None :
531+ def test_m2o_map_fun_state_passed_to_concat_mapper (
532+ mocker : "pytest_mock.MockerFixture" ,
533+ ) -> None :
529534 """Test m2o_map state management.
530535
531536 Confirms m2o_map passes 'state' to the underlying concat_mapper and
@@ -556,7 +561,9 @@ def test_m2o_map_fun_state_passed_to_concat_mapper(mocker: MagicMock) -> None:
556561 mock_to_m2o .assert_called_once_with ("test_prefix" , "John_Doe_APP" , default = "" )
557562
558563
559- def test_m2o_map_fun_state_modified_by_concat_mapper (mocker : MagicMock ) -> None :
564+ def test_m2o_map_fun_state_modified_by_concat_mapper (
565+ mocker : "pytest_mock.MockerFixture" ,
566+ ) -> None :
560567 """Confirms m2o_map's underlying concat_mapper can modify the state.
561568
562569 Args:
@@ -573,7 +580,7 @@ def test_m2o_map_fun_state_modified_by_concat_mapper(mocker: MagicMock) -> None:
573580
574581
575582def test_m2o_map_fun_with_skip_and_empty_concat_value_state_passed (
576- mocker : MagicMock ,
583+ mocker : "pytest_mock.MockerFixture" ,
577584) -> None :
578585 """Tests m2o_map.
579586
0 commit comments