patch

Testing aiohttp client with unittest.mock.patch

倾然丶 夕夏残阳落幕 提交于 2021-02-20 09:19:53
问题 I've written a simple HTTP client using aiohttp and I'm trying to test it by patching aiohttp.ClientSession and aiohttp.ClientResponse . However, it appears as though the unittest.mock.patch decorator is not respecting my asynchronous code. At a guess, I would say it's some kind of namespacing mismatch. Here's a minimal example: from aiohttp import ClientSession async def is_ok(url:str) -> bool: async with ClientSession() as session: async with session.request("GET", url) as response: return

Testing aiohttp client with unittest.mock.patch

天大地大妈咪最大 提交于 2021-02-20 09:18:29
问题 I've written a simple HTTP client using aiohttp and I'm trying to test it by patching aiohttp.ClientSession and aiohttp.ClientResponse . However, it appears as though the unittest.mock.patch decorator is not respecting my asynchronous code. At a guess, I would say it's some kind of namespacing mismatch. Here's a minimal example: from aiohttp import ClientSession async def is_ok(url:str) -> bool: async with ClientSession() as session: async with session.request("GET", url) as response: return

Proper mime-type for patch files

不想你离开。 提交于 2021-02-18 10:44:06
问题 Anybody know what the "proper" mime-type for patch files would be? I have been using application/octet-stream because I don't see anything better at iana.org. Is application/octet-stream correct, or is there something else that fits better? Why is there no application/patch type? Obviously, one possible answer is text/plain , but I have seen many patch files which include data which is not purely text. Is text/plain the best choice if you know for a fact all content is text, or is it better

Python unittest patch mock entier class

依然范特西╮ 提交于 2021-02-11 13:14:33
问题 I have a class that I want to patch in my unittests. class OriginalClass(): def method_a(): # do something def method_b(): # do another thing Now I created another class to patch it with, so the code for patching it is like class MockClass(OriginalClass): def method_a(): # This will override the original method and return custom response for testing. patcher = patch('OriginalClass', new=MockClass) mock_instance = patcher.start() This works exactly as I want it to and I can return whatever

Python unittest patch mock entier class

邮差的信 提交于 2021-02-11 13:11:42
问题 I have a class that I want to patch in my unittests. class OriginalClass(): def method_a(): # do something def method_b(): # do another thing Now I created another class to patch it with, so the code for patching it is like class MockClass(OriginalClass): def method_a(): # This will override the original method and return custom response for testing. patcher = patch('OriginalClass', new=MockClass) mock_instance = patcher.start() This works exactly as I want it to and I can return whatever

Load tensorflow images and create patches

我与影子孤独终老i 提交于 2021-02-04 08:11:30
问题 I am using image_dataset_from_directory to load a very large RGB imagery dataset from disk into a Dataset. For example, dataset = tf.keras.preprocessing.image_dataset_from_directory( <directory>, label_mode=None, seed=1, subset='training', validation_split=0.1) The Dataset has, say, 100000 images grouped into batches of size 32 yielding a tf.data.Dataset with spec (batch=32, width=256, height=256, channels=3) I would like to extract patches from the images to create a new tf.data.Dataset with

adding hatches to seaborn heatmap plot

心不动则不痛 提交于 2021-01-29 08:21:22
问题 Is there a way to hatch particular 'cells' in a seaborn heatmap, which e.g. fullfill a condition? I already tried it with masked arrays and matplotlib pcolor, but it turned out that it hatched the wrong cells. import numpy as np import seaborn as sns import matplotlib.pyplot as plt flights = sns.load_dataset("flights") flights = flights.pivot("month", "year", "passengers") zm = np.ma.masked_less(flights.values, 200) x= np.arange(0,12) y= np.arange(0,12) sns.heatmap(flights,linewidth=.1) plt

Use kubectl patch to add DNS Rewrite Rule to CoreDNS Configmap

﹥>﹥吖頭↗ 提交于 2021-01-29 05:07:10
问题 I want to use the kubectl patch command to add a DNS rewrite rule to the coredns configmap, as described at Custom DNS Entries For Kubernetes. The default config map looks like this: apiVersion: v1 data: Corefile: | .:53 { log errors health kubernetes cluster.local in-addr.arpa ip6.arpa { pods insecure upstream fallthrough in-addr.arpa ip6.arpa ttl 30 } prometheus :9153 forward . /etc/resolv.conf cache 30 loop reload loadbalance } kind: ConfigMap .... and I want to add the line rewrite name

Interactive patch from external .diff file

两盒软妹~` 提交于 2021-01-29 04:20:56
问题 Is there a command or program for Linux that allows to patch the source code interactively, printing every chunk on the screen and waiting for acknowledgement before applying it to the file? Something like git add -p , but taking the changes from another .diff file? 回答1: You can always write script in shell/ruby/python that reads that file line by line and prompts adding diff between file signatures. It can accept name of diff file as parameter or you can put two hashes and make a patch

How to send form containing files via jQuery ajax using PATCH method to Laravel 5?

旧街凉风 提交于 2021-01-27 22:51:50
问题 This is my code: //routes.php Route::match(['post', 'patch'],'/slide/{id}', function() { dd(request()->all()); }); //form <form id="form" enctype="multipart/form-data"> <input type="text" name="title"> <input type="file" name="image"> </form> //js $('#form').on('submit',(function(e) { $.ajax({ type: "PATCH", url:'/slide/' + id, data: new FormData(this), cache: false, contentType: false, processData: false }).done(function(r) { console.log(r); }); })); When I use POST method everything is fine