Repository: staticdev/irpf-cei (language: python)

Issue:
Fix release workflow
- It is looking for commits on `master` and not `main`.


Discussion / hints:

Fix patch:
diff --git a/mypy.ini b/mypy.ini
index 4f82307..29e93bf 100644
--- a/mypy.ini
+++ b/mypy.ini
@@ -28,5 +28,8 @@ ignore_missing_imports = True
 [mypy-pandas.*]
 ignore_missing_imports = True
 
+[mypy-pytest_mock]
+ignore_missing_imports = True
+
 [mypy-xlrd]
 ignore_missing_imports = True


Test patch:
diff --git a/tests/test_cei.py b/tests/test_cei.py
index 1114d6c..e379a2a 100644
--- a/tests/test_cei.py
+++ b/tests/test_cei.py
@@ -1,13 +1,11 @@
 """Test cases for the CEI module."""
 import datetime
 import os
-from unittest.mock import Mock
-from unittest.mock import patch
 
 import numpy as np
 import pandas as pd
 import pytest
-from pytest_mock import MockFixture
+from pytest_mock import MockerFixture
 
 from irpf_cei import cei
 
@@ -19,7 +17,7 @@ def test_date_parse() -> None:
 
 
 @pytest.fixture
-def mock_pandas_read_excel(mocker: MockFixture) -> Mock:
+def mock_pandas_read_excel(mocker: MockerFixture) -> MockerFixture:
     """Fixture for mocking pandas.read_excel."""
     mock = mocker.patch("pandas.read_excel")
     header = pd.DataFrame(
@@ -37,7 +35,7 @@ def mock_pandas_read_excel(mocker: MockFixture) -> Mock:
     return mock
 
 
-def test_read_xls(mock_pandas_read_excel: Mock) -> None:
+def test_read_xls(mock_pandas_read_excel: MockerFixture) -> None:
     """Call read_excel."""
     cei.read_xls("my.xls")
     mock_pandas_read_excel.assert_called_once()
@@ -59,29 +57,29 @@ def test_round_down_money_one_digit() -> None:
 
 
 @pytest.fixture
-def cwd(fs: Mock, monkeypatch: Mock) -> None:
+def cwd(fs: MockerFixture, monkeypatch: MockerFixture) -> None:
     """Fixture for pyfakefs fs."""
     fs.cwd = "/path"
     monkeypatch.setenv("HOME", "/home")
 
 
-def test_get_xls_filename_not_found(fs: Mock, cwd: Mock) -> None:
+def test_get_xls_filename_not_found(fs: MockerFixture, cwd: MockerFixture) -> None:
     """Raise `SystemExit` when file is not found."""
     with pytest.raises(SystemExit):
         assert cei.get_xls_filename()
 
 
-def test_get_xls_filename_current_folder(fs: Mock, cwd: Mock) -> None:
+def test_get_xls_filename_current_folder(fs: MockerFixture, cwd: MockerFixture) -> None:
     """Return filename found in current folder."""
     fs.create_file("/path/InfoCEI.xls")
     assert cei.get_xls_filename() == "InfoCEI.xls"
 
 
-@patch("os.path.expanduser", return_value="/home")
 def test_get_xls_filename_download_folder(
-    mock_os_expanduser: Mock, fs: Mock, cwd: Mock
+    mocker: MockerFixture, fs: MockerFixture, cwd: MockerFixture
 ) -> None:
     """Return filename found in downloads folder."""
+    mocker.patch("os.path.expanduser", return_value="/home")
     path = os.path.join("/home", "Downloads", "InfoCEI.xls")
     fs.create_file(path)
     assert cei.get_xls_filename() == path
@@ -108,7 +106,7 @@ def test_validate_period_wrong_start_finish() -> None:
     )
 
 
-def test_validate_header_empty_file(fs: Mock, cwd: Mock) -> None:
+def test_validate_header_empty_file(fs: MockerFixture, cwd: MockerFixture) -> None:
     """Raise `SystemExit` from empty file."""
     path = os.path.join("path", "InfoCEI.xls")
     fs.create_file(path)
@@ -117,7 +115,7 @@ def test_validate_header_empty_file(fs: Mock, cwd: Mock) -> None:
 
 
 @pytest.fixture
-def mock_validate_period(mocker: MockFixture) -> Mock:
+def mock_validate_period(mocker: MockerFixture) -> MockerFixture:
     """Fixture for mocking irpf_cei.cei.validate_period."""
     mock = mocker.patch("irpf_cei.cei.validate_period")
     mock.return_value = 2019
@@ -125,7 +123,7 @@ def mock_validate_period(mocker: MockFixture) -> Mock:
 
 
 def test_validate_header(
-    mock_pandas_read_excel: MockFixture, mock_validate_period: MockFixture
+    mock_pandas_read_excel: MockerFixture, mock_validate_period: MockerFixture
 ) -> None:
     """Return year and institution."""
     assert cei.validate_header("/my/path/InfoCEI.xls") == (2019, "INSTITUTION")
@@ -203,15 +201,13 @@ def test_group_trades() -> None:
     pd.testing.assert_frame_equal(result_df, expected_df)
 
 
-@patch("irpf_cei.b3.get_trading_rate", return_value=0.000275)
-@patch(
-    "irpf_cei.b3.get_emoluments_rates",
-    return_value=[0.00004105, 0.00004105, 0.00004105],
-)
-def test_calculate_taxes_2019(
-    mock_get_emoluments_rates: Mock, mock_get_trading_rate: Mock
-) -> None:
+def test_calculate_taxes_2019(mocker: MockerFixture) -> None:
     """Return calculated taxes."""
+    mocker.patch("irpf_cei.b3.get_trading_rate", return_value=0.000275)
+    mocker.patch(
+        "irpf_cei.b3.get_emoluments_rates",
+        return_value=[0.00004105, 0.00004105, 0.00004105],
+    )
     df = pd.DataFrame(
         {
             "Data Negócio": [
@@ -321,30 +317,31 @@ def test_average_price() -> None:
     pd.testing.assert_frame_equal(result_df, expected_df)
 
 
-@patch("irpf_cei.cei.buy_sell_columns")
-@patch("irpf_cei.cei.group_buys_sells")
-@patch("irpf_cei.cei.average_price", return_value=pd.DataFrame())
 def test_goods_and_rights(
-    mock_average_price: Mock, mock_groups_buys_sells: Mock, mock_buy_sell_columns: Mock
+    mocker: MockerFixture,
 ) -> None:
     """Return a DataFrame."""
+    mocker.patch("irpf_cei.cei.buy_sell_columns")
+    mocker.patch("irpf_cei.cei.group_buys_sells")
+    mocker.patch("irpf_cei.cei.average_price", return_value=pd.DataFrame())
+
     df = cei.goods_and_rights(pd.DataFrame())
     assert type(df) is pd.DataFrame
 
 
-@patch("builtins.print")
-def test_output_taxes(mock_print: Mock) -> None:
+def test_output_taxes(mocker: MockerFixture) -> None:
     """Print out taxes."""
+    mock_print = mocker.patch("builtins.print")
+
     cei.output_taxes(pd.DataFrame())
     mock_print.assert_called_once()
 
 
-@patch("irpf_cei.formatting.get_currency_format")
-@patch("builtins.print")
-def test_output_goods_and_rights(
-    mock_print: Mock, mock_get_currency_format: Mock
-) -> None:
+def test_output_goods_and_rights(mocker: MockerFixture) -> None:
     """Print out goods and rights."""
+    mocker.patch("irpf_cei.formatting.get_currency_format")
+    mock_print = mocker.patch("builtins.print")
+
     df = pd.DataFrame(
         {
             "Código": ["BOVA11", "PETR4"],
diff --git a/tests/test_formatting.py b/tests/test_formatting.py
index be5c46e..552714e 100644
--- a/tests/test_formatting.py
+++ b/tests/test_formatting.py
@@ -1,28 +1,27 @@
 """Test cases for formatting module."""
 import locale
-from unittest.mock import Mock
-from unittest.mock import patch
 
 import numpy as np
+from pytest_mock import MockerFixture
 
 from irpf_cei import formatting
 
 
-@patch("locale.setlocale")
-def test_set_locale_success(mock_locale_setlocale: Mock) -> None:
+def test_set_locale_success(mocker: MockerFixture) -> None:
     """Return empty string."""
+    mocker.patch("locale.setlocale")
     assert formatting.set_locale() == ""
 
 
-@patch("locale.setlocale", side_effect=locale.Error())
-def test_set_locale_error(mock_locale_setlocale: Mock) -> None:
+def test_set_locale_error(mocker: MockerFixture) -> None:
     """Return pt_BR locale."""
+    mocker.patch("locale.setlocale", side_effect=locale.Error())
     assert formatting.set_locale() == "pt_BR.utf8"
 
 
-@patch("locale.currency")
-def test_get_currency_format(mock_locale_currency: Mock) -> None:
+def test_get_currency_format(mocker: MockerFixture) -> None:
     """Give no error."""
+    mocker.patch("locale.currency")
     assert formatting.get_currency_format()
 
 
diff --git a/tests/test_main.py b/tests/test_main.py
index 21e5fc0..36ce206 100644
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -1,27 +1,24 @@
 """Test cases for the __main__ module."""
-from unittest.mock import Mock
-from unittest.mock import patch
-
 import click.testing
 import pytest
-from pytest_mock import MockFixture
+from pytest_mock import MockerFixture
 
 from irpf_cei import __main__
 
 
-@patch(
-    "inquirer.prompt",
-    side_effect=[{"trades": []}, {"": "Não"}, {"trades": []}, {"": "Sim"}],
-)
-def test_select_trades_empty(mock_inquirer_prompt: Mock) -> None:
+def test_select_trades_empty(mocker: MockerFixture) -> None:
     """It returns empty list."""
+    mocker.patch(
+        "inquirer.prompt",
+        side_effect=[{"trades": []}, {"": "Não"}, {"trades": []}, {"": "Sim"}],
+    )
     trades = [("trade 1", 0), ("trade 2", 1)]
     assert __main__.select_trades(trades) == []
 
 
-@patch("inquirer.prompt", return_value={"trades": [1]})
-def test_select_trades_some_selected(mock_inquirer_prompt: Mock) -> None:
+def test_select_trades_some_selected(mocker: MockerFixture) -> None:
     """It returns list with id 1."""
+    mocker.patch("inquirer.prompt", return_value={"trades": [1]})
     trades = [("trade 1", 0), ("trade 2", 1)]
     assert __main__.select_trades(trades) == [1]
 
@@ -33,13 +30,13 @@ def runner() -> click.testing.CliRunner:
 
 
 @pytest.fixture
-def mock_cei_get_xls_filename(mocker: MockFixture) -> Mock:
+def mock_cei_get_xls_filename(mocker: MockerFixture) -> MockerFixture:
     """Fixture for mocking cei.get_xls_filename."""
     return mocker.patch("irpf_cei.cei.get_xls_filename")
 
 
 @pytest.fixture
-def mock_cei_validate_header(mocker: MockFixture) -> Mock:
+def mock_cei_validate_header(mocker: MockerFixture) -> MockerFixture:
     """Fixture for mocking cei.validate."""
     mock = mocker.patch("irpf_cei.cei.validate_header")
     mock.return_value = 2019, "ABC"
@@ -47,76 +44,76 @@ def mock_cei_validate_header(mocker: MockFixture) -> Mock:
 
 
 @pytest.fixture
-def mock_cei_read_xls(mocker: MockFixture) -> Mock:
+def mock_cei_read_xls(mocker: MockerFixture) -> MockerFixture:
     """Fixture for mocking cei.read_xls."""
     return mocker.patch("irpf_cei.cei.read_xls")
 
 
 @pytest.fixture
-def mock_cei_clean_table_cols(mocker: MockFixture) -> Mock:
+def mock_cei_clean_table_cols(mocker: MockerFixture) -> MockerFixture:
     """Fixture for mocking cei.clean_table_cols."""
     return mocker.patch("irpf_cei.cei.clean_table_cols")
 
 
 @pytest.fixture
-def mock_cei_group_trades(mocker: MockFixture) -> Mock:
+def mock_cei_group_trades(mocker: MockerFixture) -> MockerFixture:
     """Fixture for mocking cei.group_trades."""
     return mocker.patch("irpf_cei.cei.group_trades")
 
 
 @pytest.fixture
-def mock_select_trades(mocker: MockFixture) -> Mock:
+def mock_select_trades(mocker: MockerFixture) -> MockerFixture:
     """Fixture for mocking __main__.select_trades."""
     return mocker.patch("irpf_cei.__main__.select_trades")
 
 
 @pytest.fixture
-def mock_cei_get_trades(mocker: MockFixture) -> Mock:
+def mock_cei_get_trades(mocker: MockerFixture) -> MockerFixture:
     """Fixture for mocking cei.get_trades."""
     return mocker.patch("irpf_cei.cei.get_trades")
 
 
 @pytest.fixture
-def mock_cei_calculate_taxes(mocker: MockFixture) -> Mock:
+def mock_cei_calculate_taxes(mocker: MockerFixture) -> MockerFixture:
     """Fixture for mocking cei.calculate_taxes."""
     return mocker.patch("irpf_cei.cei.calculate_taxes")
 
 
 @pytest.fixture
-def mock_cei_output_taxes(mocker: MockFixture) -> Mock:
+def mock_cei_output_taxes(mocker: MockerFixture) -> MockerFixture:
     """Fixture for mocking cei.output_taxes."""
     return mocker.patch("irpf_cei.cei.output_taxes")
 
 
 @pytest.fixture
-def mock_cei_goods_and_rights(mocker: MockFixture) -> Mock:
+def mock_cei_goods_and_rights(mocker: MockerFixture) -> MockerFixture:
     """Fixture for mocking cei.goods_and_rights."""
     return mocker.patch("irpf_cei.cei.goods_and_rights")
 
 
 @pytest.fixture
-def mock_cei_output_goods_and_rights(mocker: MockFixture) -> Mock:
+def mock_cei_output_goods_and_rights(mocker: MockerFixture) -> MockerFixture:
     """Fixture for mocking cei.output_goods_and_rights."""
     return mocker.patch("irpf_cei.cei.output_goods_and_rights")
 
 
-@patch("irpf_cei.formatting.set_locale", return_value="")
 def test_main_succeeds(
-    mock_formatting_set_locale: Mock,
+    mocker: MockerFixture,
     runner: click.testing.CliRunner,
-    mock_cei_get_xls_filename: Mock,
-    mock_cei_validate_header: Mock,
-    mock_cei_read_xls: Mock,
-    mock_cei_clean_table_cols: Mock,
-    mock_cei_group_trades: Mock,
-    mock_select_trades: Mock,
-    mock_cei_get_trades: Mock,
-    mock_cei_calculate_taxes: Mock,
-    mock_cei_output_taxes: Mock,
-    mock_cei_goods_and_rights: Mock,
-    mock_cei_output_goods_and_rights: Mock,
+    mock_cei_get_xls_filename: MockerFixture,
+    mock_cei_validate_header: MockerFixture,
+    mock_cei_read_xls: MockerFixture,
+    mock_cei_clean_table_cols: MockerFixture,
+    mock_cei_group_trades: MockerFixture,
+    mock_select_trades: MockerFixture,
+    mock_cei_get_trades: MockerFixture,
+    mock_cei_calculate_taxes: MockerFixture,
+    mock_cei_output_taxes: MockerFixture,
+    mock_cei_goods_and_rights: MockerFixture,
+    mock_cei_output_goods_and_rights: MockerFixture,
 ) -> None:
     """Exit with a status code of zero."""
+    mocker.patch("irpf_cei.formatting.set_locale", return_value="")
     result = runner.invoke(__main__.main)
     assert result.output.startswith("Nome do arquivo: ")
     mock_cei_calculate_taxes.assert_called_once()
@@ -126,23 +123,23 @@ def test_main_succeeds(
     assert result.exit_code == 0
 
 
-@patch("irpf_cei.formatting.set_locale", return_value="xyz")
 def test_main_locale_fail(
-    mock_formatting_set_locale: Mock,
+    mocker: MockerFixture,
     runner: click.testing.CliRunner,
-    mock_cei_get_xls_filename: Mock,
-    mock_cei_validate_header: Mock,
-    mock_cei_read_xls: Mock,
-    mock_cei_clean_table_cols: Mock,
-    mock_cei_group_trades: Mock,
-    mock_select_trades: Mock,
-    mock_cei_get_trades: Mock,
-    mock_cei_calculate_taxes: Mock,
-    mock_cei_output_taxes: Mock,
-    mock_cei_goods_and_rights: Mock,
-    mock_cei_output_goods_and_rights: Mock,
+    mock_cei_get_xls_filename: MockerFixture,
+    mock_cei_validate_header: MockerFixture,
+    mock_cei_read_xls: MockerFixture,
+    mock_cei_clean_table_cols: MockerFixture,
+    mock_cei_group_trades: MockerFixture,
+    mock_select_trades: MockerFixture,
+    mock_cei_get_trades: MockerFixture,
+    mock_cei_calculate_taxes: MockerFixture,
+    mock_cei_output_taxes: MockerFixture,
+    mock_cei_goods_and_rights: MockerFixture,
+    mock_cei_output_goods_and_rights: MockerFixture,
 ) -> None:
     """Exit with `SystemExit` when locale not found."""
+    mocker.patch("irpf_cei.formatting.set_locale", return_value="xyz")
     result = runner.invoke(__main__.main)
     assert result.output.startswith("Erro: locale xyz não encontrado")
     assert type(result.exception) == SystemExit