Yang
11/07/2022, 4:55 PM@op
def mock_extract_vdata(metric):
data = pd.DataFrame({
"orgpermid": [0, 1, 2],
"rawdata0": [1, 1.2, 2.2]
})
return data
def test_graph():
with (
patch("esg.assets.pai.pai_graph.extract_valid_data",
new=mock_extract_vdata)):
result = pai_graph.pai_metrics.execute_in_process(
input_values={
"fiscal_year": 2020,
"allfindata": allfindata},
resources={
"esg_outputter": mock_esg_outputter.configured({})})
but it still called the real op.rex
11/09/2022, 5:09 PMchris
11/10/2022, 12:08 AMcompute_fn
of the op like so:
@op
def mock_extract_vdata(metric):
data = pd.DataFrame({
"orgpermid": [0, 1, 2],
"rawdata0": [1, 1.2, 2.2]
})
return data
def test_graph():
with (
patch("esg.assets.pai.pai_graph.extract_valid_data.compute_fn",
new=mock_extract_vdata.compute_fn)):
result = pai_graph.pai_metrics.execute_in_process(
input_values={
"fiscal_year": 2020,
"allfindata": allfindata},
resources={
"esg_outputter": mock_esg_outputter.configured({})})
Might have the mocking syntax a bit messed up there, but something like that should work I thinkYang
11/10/2022, 7:19 AMcan't set attribute
elif autospec is not None:
# spec is ignored, new *must* be default, spec_set is treated
# as a boolean. Should we check spec is not None and that spec_set
# is a bool?
if new is not DEFAULT:
raise TypeError(
"autospec creates the mock for you. Can't specify "
"autospec and new."
)
if original is DEFAULT:
raise TypeError("Can't use 'autospec' with create=True")
spec_set = bool(spec_set)
if autospec is True:
autospec = original
new = create_autospec(autospec, spec_set=spec_set,
_name=self.attribute, **kwargs)
elif kwargs:
# can't set keyword args when we aren't creating the mock
# XXXX If new is a Mock we could call new.configure_mock(**kwargs)
raise TypeError("Can't pass kwargs to a mock we aren't creating")
new_attr = new
self.temp_original = original
self.is_local = local
self._exit_stack = contextlib.ExitStack()
try:
> setattr(self.target, self.attribute, new_attr)
E AttributeError: can't set attribute
/opt/homebrew/Caskroom/miniforge/base/envs/py39_env_x86/lib/python3.9/site-packages/mock/mock.py:1511: AttributeError
chris
11/11/2022, 1:30 AMYang
11/11/2022, 4:03 PMchris
11/17/2022, 8:29 PM