Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add deepcopy to mock args in app_mmocks #453

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ jobs:
with:
version: ${{ matrix.version }}
skip_test: true
- name: List pip deps
run: |
pip list
- name: Install testing deps
run: |
fastkafka docs install_deps
fastkafka testing install_deps
- name: Run nbdev tests
run: |
nbdev_test --timing --do_print
nbdev_test --timing --do_print --file_glob "*_CLI*" # Run CLI tests first because of npm installation clashes with other tests
nbdev_test --timing --do_print --skip_file_glob "*_CLI*"
- name: Test building docs with nbdev-mkdocs
if: matrix.os != 'windows'
run: |
Expand Down
5 changes: 3 additions & 2 deletions fastkafka/_application/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from asyncio import iscoroutinefunction # do not use the version from inspect
from collections import namedtuple
from contextlib import asynccontextmanager
from copy import deepcopy
from datetime import datetime, timedelta
from functools import wraps
from inspect import signature
Expand Down Expand Up @@ -1056,14 +1057,14 @@ def add_mock(
async def async_inner(
*args: Any, f: Callable[..., Any] = f, mock: AsyncMock = mock, **kwargs: Any
) -> Any:
await mock(*args, **kwargs)
await mock(*deepcopy(args), **kwargs)
return await f(*args, **kwargs)

@functools.wraps(f)
def sync_inner(
*args: Any, f: Callable[..., Any] = f, mock: MagicMock = mock, **kwargs: Any
) -> Any:
mock(*args, **kwargs)
mock(*deepcopy(args), **kwargs)
return f(*args, **kwargs)

if inspect.iscoroutinefunction(f):
Expand Down
102 changes: 58 additions & 44 deletions nbs/015_FastKafka.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"from asyncio import iscoroutinefunction # do not use the version from inspect\n",
"from collections import namedtuple\n",
"from contextlib import asynccontextmanager\n",
"from copy import deepcopy\n",
"from datetime import datetime, timedelta\n",
"from functools import wraps\n",
"from inspect import signature\n",
Expand Down Expand Up @@ -1813,7 +1814,7 @@
"[INFO] fastkafka._testing.apache_kafka_broker: Starting zookeeper...\n",
"Port 2181 is already in use\n",
"[INFO] fastkafka._testing.apache_kafka_broker: zookeeper startup failed, generating a new port and retrying...\n",
"[INFO] fastkafka._testing.apache_kafka_broker: zookeeper new port=47889\n",
"[INFO] fastkafka._testing.apache_kafka_broker: zookeeper new port=48943\n",
"[INFO] fastkafka._testing.apache_kafka_broker: Starting kafka...\n",
"[INFO] fastkafka._testing.apache_kafka_broker: Local Kafka broker up and running on 127.0.0.1:15993\n",
"[INFO] __main__: run_in_background() : Adding function 'long_bg_job' as background task\n",
Expand All @@ -1837,14 +1838,14 @@
"[INFO] fastkafka._components.aiokafka_consumer_loop: aiokafka_consumer_loop() finished.\n",
"[INFO] fastkafka._components.aiokafka_consumer_loop: aiokafka_consumer_loop(): Consumer stopped.\n",
"[INFO] fastkafka._components.aiokafka_consumer_loop: aiokafka_consumer_loop() finished.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 99335...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 99335 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 98946...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 98946 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 98338...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 98338 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 97950...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 97950 terminated.\n"
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 1886...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 1886 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 1516...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 1516 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 1088...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 1088 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 718...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 718 terminated.\n"
]
}
],
Expand Down Expand Up @@ -2006,7 +2007,7 @@
"[INFO] fastkafka._testing.apache_kafka_broker: Starting zookeeper...\n",
"Port 2181 is already in use\n",
"[INFO] fastkafka._testing.apache_kafka_broker: zookeeper startup failed, generating a new port and retrying...\n",
"[INFO] fastkafka._testing.apache_kafka_broker: zookeeper new port=41863\n",
"[INFO] fastkafka._testing.apache_kafka_broker: zookeeper new port=34285\n",
"[INFO] fastkafka._testing.apache_kafka_broker: Starting kafka...\n",
"[INFO] fastkafka._testing.apache_kafka_broker: Local Kafka broker up and running on 127.0.0.1:15993\n",
"[INFO] __main__: run_in_background() : Adding function 'long_bg_job' as background task\n",
Expand All @@ -2020,14 +2021,14 @@
"[INFO] __main__: _create_producer() : created producer using the config: '{'bootstrap_servers': '127.0.0.1:15992'}'\n",
"[INFO] __main__: _create_producer() : created producer using the config: '{'bootstrap_servers': '127.0.0.1:15993'}'\n",
"[<aiokafka.producer.producer.AIOKafkaProducer object>, <aiokafka.producer.producer.AIOKafkaProducer object>, <aiokafka.producer.producer.AIOKafkaProducer object>]\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 101365...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 101365 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 100976...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 100976 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 100371...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 100371 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 99983...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 99983 terminated.\n"
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 3518...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 3518 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 3149...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 3149 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 2720...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 2720 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 2350...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 2350 terminated.\n"
]
}
],
Expand Down Expand Up @@ -2123,10 +2124,10 @@
"[INFO] __main__: _shutdown_bg_tasks() : Execution finished for background task 'long_bg_job'\n",
"[INFO] __main__: _shutdown_bg_tasks() : Waiting for background task 'long_bg_job' to finish\n",
"[INFO] __main__: _shutdown_bg_tasks() : Execution finished for background task 'long_bg_job'\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 102393...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 102393 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 102005...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 102005 terminated.\n"
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 4348...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 4348 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 3977...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 3977 terminated.\n"
]
}
],
Expand Down Expand Up @@ -2197,10 +2198,10 @@
"[INFO] fastkafka._testing.apache_kafka_broker: Local Kafka broker up and running on 127.0.0.1:15992\n",
"[INFO] __main__: _create_producer() : created producer using the config: '{'bootstrap_servers': '127.0.0.1:15992'}'\n",
"[INFO] __main__: _create_producer() : created producer using the config: '{'bootstrap_servers': '127.0.0.1:15992'}'\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 103404...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 103404 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 103016...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 103016 terminated.\n"
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 5160...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 5160 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 4791...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 4791 terminated.\n"
]
}
],
Expand Down Expand Up @@ -2261,10 +2262,10 @@
"[INFO] fastkafka._testing.apache_kafka_broker: Local Kafka broker up and running on 127.0.0.1:15992\n",
"[INFO] __main__: _create_producer() : created producer using the config: '{'bootstrap_servers': '127.0.0.1:15992'}'\n",
"[INFO] __main__: _create_producer() : created producer using the config: '{'bootstrap_servers': '127.0.0.1:15992'}'\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 104415...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 104415 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 104027...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 104027 terminated.\n"
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 5975...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 5975 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 5604...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 5604 terminated.\n"
]
}
],
Expand Down Expand Up @@ -2332,10 +2333,10 @@
"[INFO] __main__: _shutdown_bg_tasks() : Execution finished for background task 'bg_task'\n",
"[INFO] __main__: _shutdown_bg_tasks() : Waiting for background task 'bg_task_second' to finish\n",
"[INFO] __main__: _shutdown_bg_tasks() : Execution finished for background task 'bg_task_second'\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 105426...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 105426 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 105038...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 105038 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 6787...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 6787 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 6418...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 6418 terminated.\n",
"ok\n"
]
}
Expand Down Expand Up @@ -2397,10 +2398,10 @@
"[INFO] fastkafka._testing.apache_kafka_broker: <class 'fastkafka.testing.ApacheKafkaBroker'>.start(): returning 127.0.0.1:15992\n",
"[INFO] fastkafka._testing.apache_kafka_broker: ApacheKafkaBroker.start(): exited.\n",
"[INFO] fastkafka._testing.apache_kafka_broker: ApacheKafkaBroker.stop(): entering...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 106441...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 106441 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 106053...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 106053 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 7600...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 7600 terminated.\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Terminating the process 7231...\n",
"[INFO] fastkafka._components._subprocess: terminate_asyncio_process(): Process 7231 terminated.\n",
"[INFO] fastkafka._testing.apache_kafka_broker: ApacheKafkaBroker.stop(): exited.\n"
]
}
Expand Down Expand Up @@ -2638,11 +2639,24 @@
"[INFO] fastkafka._components.asyncapi: Old async specifications at '/tmp/000_FastKafka/asyncapi/spec/asyncapi.yml' does not exist.\n",
"[INFO] fastkafka._components.asyncapi: New async specifications generated at: '/tmp/000_FastKafka/asyncapi/spec/asyncapi.yml'\n",
"[INFO] fastkafka._components.asyncapi: Async docs generated at '/tmp/000_FastKafka/asyncapi/docs'\n",
"[INFO] fastkafka._components.asyncapi: Output of '$ npx -y -p @asyncapi/generator ag /tmp/000_FastKafka/asyncapi/spec/asyncapi.yml @asyncapi/html-template -o /tmp/000_FastKafka/asyncapi/docs --force-write'\u001b[32m\n",
"[INFO] fastkafka._components.asyncapi: Output of '$ npx -y -p @asyncapi/generator ag /tmp/000_FastKafka/asyncapi/spec/asyncapi.yml @asyncapi/html-template -o /tmp/000_FastKafka/asyncapi/docs --force-write'npm WARN deprecated [email protected]: this library is no longer supported\n",
"npm WARN deprecated [email protected]: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.\n",
"npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.\n",
"npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142\n",
"npm WARN deprecated [email protected]: This functionality has been moved to @npmcli/fs\n",
"npm WARN deprecated @npmcli/[email protected]: This functionality has been moved to @npmcli/fs\n",
"npm WARN deprecated [email protected]: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)\n",
"npm WARN deprecated [email protected]: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)\n",
"\u001b[32m\n",
"\n",
"Done! ✨\u001b[0m\n",
"\u001b[33mCheck out your shiny new generated files at \u001b[0m\u001b[35m/tmp/000_FastKafka/asyncapi/docs\u001b[0m\u001b[33m.\u001b[0m\n",
"\n",
"npm notice \n",
"npm notice New minor version of npm available! 9.6.3 -> 9.8.1\n",
"npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.8.1>\n",
"npm notice Run `npm install -g [email protected]` to update!\n",
"npm notice \n",
"\n",
"ok\n"
]
Expand Down Expand Up @@ -2787,14 +2801,14 @@
" async def async_inner(\n",
" *args: Any, f: Callable[..., Any] = f, mock: AsyncMock = mock, **kwargs: Any\n",
" ) -> Any:\n",
" await mock(*args, **kwargs)\n",
" await mock(*deepcopy(args), **kwargs)\n",
" return await f(*args, **kwargs)\n",
"\n",
" @functools.wraps(f)\n",
" def sync_inner(\n",
" *args: Any, f: Callable[..., Any] = f, mock: MagicMock = mock, **kwargs: Any\n",
" ) -> Any:\n",
" mock(*args, **kwargs)\n",
" mock(*deepcopy(args), **kwargs)\n",
" return f(*args, **kwargs)\n",
"\n",
" if inspect.iscoroutinefunction(f):\n",
Expand Down Expand Up @@ -3203,7 +3217,7 @@
"name": "stderr",
"output_type": "stream",
"text": [
"INFO: Started server process [107102]\n",
"INFO: Started server process [8091]\n",
"INFO: Waiting for application startup.\n"
]
},
Expand Down Expand Up @@ -3234,7 +3248,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"INFO: 127.0.0.1:37682 - \"GET /predict HTTP/1.1\" 200 OK\n",
"INFO: 127.0.0.1:35572 - \"GET /predict HTTP/1.1\" 200 OK\n",
"receving messages on app_for_tester\n",
"sending predictions on app_for_tester\n"
]
Expand Down Expand Up @@ -3262,7 +3276,7 @@
"output_type": "stream",
"text": [
"INFO: Application shutdown complete.\n",
"INFO: Finished server process [107102]\n"
"INFO: Finished server process [8091]\n"
]
},
{
Expand Down
Loading