patch

How to permanently mock return value of a function in python unittest

半世苍凉 提交于 2021-01-27 17:45:57
问题 I have a function # foo.py NUM_SHARDS = 10 def get_shard(shard_key: int) -> int return (shard_key % NUM_SHARDS) + 1 I want to mock this function such that whenever this function is called, it returns a certain value. I've tried patching like such # test.py @mock.patch('foo.get_shard', return_value=11) def testSomething(self, patched_func): patched_func() # >> 11 ... OK so this is fine but get_shard(4) # >> 5 .... Original impl being executed I want to deeply modify this function to always

Extract coordinates enclosed by a matplotlib patch.

谁说我不能喝 提交于 2021-01-18 04:35:42
问题 I have created an ellipse using matplotlib.patches.ellipse as shown below: patch = mpatches.Ellipse(center, major_ax, minor_ax, angle_deg, fc='none', ls='solid', ec='g', lw='3.') What I want is a list of all the integer coordinates enclosed inside this patch. I.e. If I was to plot this ellipse along with every integer point on the same grid, how many of those points are enclosed in the ellipse? I have tried seeing if I can extract the equation of the ellipse so I can loop through each point

Is it possible to apply a patch to external code in Cargo.toml?

只愿长相守 提交于 2020-12-13 03:01:10
问题 I read the Cargo manual about the patch option but it is still unclear to me. Is it possible to instruct Cargo: Get the code from this repository. Apply this patch file (my_cool_change.patch) to that code. Is making my own fork of the project the only way to do it? 回答1: It is not possible to instruct Cargo to do something like "take version 1.2.3 of crate foo-bar from crates.io and apply these arbitrary changes to the source code before compiling it". The Cargo documentation is not lying to

Is it possible to apply a patch to external code in Cargo.toml?

喜欢而已 提交于 2020-12-13 02:56:35
问题 I read the Cargo manual about the patch option but it is still unclear to me. Is it possible to instruct Cargo: Get the code from this repository. Apply this patch file (my_cool_change.patch) to that code. Is making my own fork of the project the only way to do it? 回答1: It is not possible to instruct Cargo to do something like "take version 1.2.3 of crate foo-bar from crates.io and apply these arbitrary changes to the source code before compiling it". The Cargo documentation is not lying to

Linux diff创建补丁以及patch打补丁

淺唱寂寞╮ 提交于 2020-11-17 11:09:33
首先介绍一下diff和patch。在这里不会把man在线文档上所有的选项都介绍一下,那样也没有必要。在99%的时间里,我们只会用到几个选项。所以必须学会这几个选项。 1、diff -------------------- NAME diff - find differences between two files SYNOPSIS diff [options] from-file to-file -------------------- 简单的说,diff的功能就是用来比较两个文件的不同,然后记录下来,也就是所谓的diff补丁。 语法格式: diff 【选项】 源文件(夹) 目的文件(夹) 就是要给源文件(夹)打个补丁,使之变成目的文件(夹),术语也就是“升级”。下面介绍三个最为常用选项: -r 是一个递归选项,设置了这个选项,diff会将两个不同版本源代码目录中的所有对应文件全部都进行一次比较,包括子目录文件。 -N 选项确保补丁文件将正确地处理已经创建或删除文件的情况。 -u 选项以统一格式创建补丁文件,这种格式比缺省格式更紧凑些。 常用命令,在某文件夹下,对比两个文件(夹): diff -urN [old_directory] [new_directory] 2、patch ------------------ NAME patch - apply a diff file