Код: Выделить всё
class Foo:
def bar(self):
print("BAR")
return "BAR"
def apply(self, df: pd.DataFrame):
df["value"] = df.apply(self.bar, axis=1)
Код: Выделить всё
import unittest
from unittest.mock import patch
from my_module import Foo
class TestFoo(unittest.TestCase):
@patch.object(Foo, "bar")
def test_apply(self, mock_bar):
df = pd.DataFrame()
mock_bar.return_value = ["value"]
foo = Foo()
updated_df = foo.apply(df)
self.assertIn("value", updated_df.columns)
mock_bar.assert_called_once()
Подробнее здесь: https://stackoverflow.com/questions/790 ... apply-call