對mock的進一步理解

2021-08-19 16:21:20 字數 2842 閱讀 4972

get_judgedoc_shinfo_time_node_api.side_effect = self.__side_effect_judgedoc_shinfo('2009-12-11')

def__side_effect_judgedoc_shinfo(self, verify_open_from):

1) time_map_judgedoc_shinfo = self.__get_time_map_judgedoc_shinfo() 2)

definner_effect(*arg):

4) start_time = arg[1] 5)

self.assertequal(verify_open_from, start_time) 6)

to_time = arg[2] 7)

return time_map_judgedoc_shinfo[to_time] 8)

return inner_effect 3)

執行順序:1)——7),根據return特性,一旦return,就直接跳出程式;因此,進一步理解,return inner_effect的時候,其實也將get_judgedoc_shinfo_time_node_api.side_effect中的get_judgedoc_shinfo_time_node_api 引數*arg傳給了inner_effect,因此,定義inner_effect的時候,還可以這樣定義inner_effect(*arg),

@staticmethod

def__get_time_map_judgedoc_shinfo():"""

裁判文書

"""return ]}

},'2014-02-12'

: ]}},

'2015-02-12'

: , ,]}

}}

疑問1:*arg中的引數是何時傳進去的,難道是 get_judgedoc_shinfo_time_node_api.side_effect = self.__side_effect_judgedoc_shinfo('2009-12-11')通過右邊的式子傳進去的??

還是通過 time_map_judgedoc_shinfo = self.__get_time_map_judgedoc_shinfo()傳進去的;

疑問2:return time_map_judgedoc_shinfo[to_time]中的to_time是跟 def

__get_time_map_judgedoc_shinfo():

return...中的時間保持一致的吧?那這麼說*arg中的引數是通過def

__get_time_map_judgedoc_shinfo():確定的咯??

解:*arg是根據com_data解析得到的,返回的左區間與右區間兩個時間值,然後根據切割點數,進行切割,有三個時間點,因此以2015-2-12號為起點向後數到2013-2-12,時間注意其規律,因此好幾個api返回的時間節點都是這樣的:2015-2-12,2014-2-12,2013-2-12;

下面assert函式進行最後的測試驗證:

def__assert_normal(self, feature_tme_svc, first_time, second_time, last_time):"""

常規檢查

"""# -- when

res = feature_tme_svc.get_time_features(company_name=u'北京龍盛源小額貸款****', node_num=3)

#這一步,會走所用mock後的api,

# -- then

assert res.time_map_features[last_time]

k = res.time_map_features[last_time]

print(type(k))

self.t_u.print_domain(res)

self.assertequal(3, len(res.time_map_features.keys()))

self.assertequal(2, res.time_map_features[last_time].address_change_cnt)

self.assertequal(6, res.time_map_features[last_time].established_years)

self.assertequal(0, res.time_map_features[last_time].fr_change_cnt)

self.assertequal(3, res.time_map_features[last_time].regcap_change_cnt)

self.assertequal(6, res.time_map_features[first_time].bidding_cnt)

self.assertequal(9, res.time_map_features[second_time].bidding_cnt)

self.assertequal(11, res.time_map_features[last_time].bidding_cnt)

self.assertequal(6, res.time_map_features[last_time].judgedoc_cnt)

self.assertequal(4, res.time_map_features[last_time].trade_mark_cnt)

下乙個學習方面:如何在python中使用static、class、abstract方法(權威指南)

[如何在python中使用static、class、abstract方法(權威指南)](

對遞迴的進一步理解

這週看了一道求陣列排列的題目,解法用了遞迴,看懂之後自己對遞迴的理解更深了。遞迴的定義 遞迴是指程式呼叫自身,但呼叫時必須改變呼叫引數,直到某個引數滿足退出條件。函式呼叫的過程會用到run time stack,遞迴時棧中的內容有相似性,但是每一層的差異最終會導致執行棧增長的停止,並且從棧頂返回。理...

bufferedReader進一步理解

public static void main string args string mystring system.out.println 請輸入明文 bufferedreader buf new bufferedreader new inputstreamreader system.in try...

進一步理解委託

前面一篇文章介紹了委託的基本知識,接下來就進一步研究一下委託。其實,剛開始覺得委託型別是乙個比較難理解的概念,怎麼也不覺得下面的 assembleiphonehandler 是乙個型別。public delegate void assembleiphonehandler 按照正常的情況,如果我們要建...