patch

How to fill_between based on a condition

How to fill_between based on a condition Question: I have a df from 2002 to 2017 that looks like this: link to gdrive with .csv Team,Finish.1_x,Finish.1_y,Win%Detroit,Win%Chicago,Date,GdpDetroit,GdpChicago,D_GDP_Change,C_GDP_Change,detroitdummy,chicagodummy 2002–03,1st,6th,0.61,0.366,2002-01-01,49650,54744,933.0,-27.0,1,0 2003–04,2nd,8th,0.659,0.28,2003-01-01,51101,55273,1451.0,529.0,1,1 2004–05,1st,2nd,0.659,0.573,2004-01-01,50935,56507,-166.0,1234.0,0,1 2005–06,1st,4th[k],0.78,0.5,2005-01-01,52028,57608,1093.0,1101.0,1,1 2006–07,1st,3rd,0.646,0.598,2006-01-01,50576,58717,-1452.0,1109.0,0,1 2007–08,1st,4th,0.72,0.402,2007-01-01,50450,59240,-126.0,523.0,0,1 2008–09,3rd,2nd,0.476,0.5,2008-01-01,47835,57197,-2615.0,-2043.0,0,0 2009–10,5th,3rd,0.329,0.5,2009-01-01,43030,54802,-4805.0,-2395.0,0,0 2010–11,4th,1st,0.366,0.756,2010-01-01,45735,55165,2705.0,363.0,1,1 2012–13,4th,2nd,0.354,0.549,2012-01-01,48469,57254,926.0,1463.0,1,1 2013–14,4th,2nd,0.354,0.585,2013-01-01,48708,56939,239.0,-315.0,1,0 2014–15,5th,2nd,0.39,0.61,2014-01-01,49594,57823,886.0,884.0,1,1 2015–16,3rd,4th,0.537,0.512,2015-01-01,50793,59285,1199.0,1462.0,1,1 2016–17,5th,4th,0.451,0.5,2016-01-01,51578,60191,785.0,906.0,1,1 2017–18,4th,5th,0.476,0.329,2017-01-01,52879,61170,1301.0,979.0,1,1 I am trying to have a chart like this one: with the Date column …

Total answers: 1

Python mock vs unittest.mock patch

Python mock vs unittest.mock patch Question: What is the difference between these imports? from mock import patch vs from unittest.mock import patch Are they the same? Asked By: Woootiness || Source Answers: The mock library has been integrated into the Python standard library from Python version 3.3 on as unittest.mock. They deliver the same functionality. …

Total answers: 2

Title for matplotlib legend

Title for matplotlib legend Question: I know it seems fairly redundant to have a title for a legend, but is it possible using matplotlib? Here’s a snippet of the code I have: import matplotlib.patches as mpatches import matplotlib.pyplot as plt one = mpatches.Patch(facecolor=’#f3f300′, label=’label1′, linewidth = 0.5, edgecolor = ‘black’) two = mpatches.Patch(facecolor=’#ff9700′, label = …

Total answers: 3

Mocking a global variable

Mocking a global variable Question: I’ve been trying to implement some unit tests for a module. An example module named alphabet.py is as follows: import database def length_letters(): return len(letters) def contains_letter(letter): return letter in letters letters = database.get(‘letters’) # returns a list of letters I’d like to mock the response from a database with …

Total answers: 5

python mock patch decorator behaves different for class methods and individual functions

python mock patch decorator behaves different for class methods and individual functions Question: Several times I’ve ran into a problem with unittest.mock.patch decorator. When I tried to mock individual functions from included module, patch didn’t work. However if functions from included module are collected as class methods, patch works perfectly. Partially this question intersects with …

Total answers: 1

Patch – Why won't the relative patch target name work?

Patch – Why won't the relative patch target name work? Question: I’ve imported a class from a module, but when I try to patch the class name without it’s module as a prefix I get a type error: TypeError: Need a valid target to patch. You supplied: ‘MyClass’ For example, the following code gives me …

Total answers: 1

@patch decorator cannot set Provider

@patch decorator cannot set Provider Question: I tried patching a provider class by decorating a test method with @patch: class TestMyUnit(unittest.TestCase): … @patch(provider.Provider,autospec=True) def test_init(self, mock_provider): pass However, when I run the test, I get the error: *@patch(provider.Provider)* *File “buildbdist.win32eggmock.py”, line 1518, in patch* *getter, attribute = _get_target(target)* *File “buildbdist.win32eggmock.py”, line 1367, in _get_target* *target, …

Total answers: 1

Python mock patch a function called by another function

Python mock patch a function called by another function Question: def f1(): return 10, True def f2(): num, stat = f1() return 2*num, stat How do I use python’s mock library to patch f1() and return a custom result so I could test f2()? Edited: Is there something wrong with my test? This doesn’t seem …

Total answers: 2

How to patch a module's internal functions with mock?

How to patch a module's internal functions with mock? Question: By “internal function”, I mean a function that is called from within the same module it is defined in. I am using the mock library, specifically the patch decorators, in my unit tests. They’re Django unit tests, but this should apply to any python tests. …

Total answers: 5