하나의 일반적인 사용 방법으로 리팩토링하려는 동일한 모양의 방법이 여러 개 있습니다. 그렇게하는 방법? 'assert_all_items_and_rows_for'에서 한 가지만 다릅니다.
def assert_all_items_and_rows_when_index_is_0(config, index, item, row, asserts):
if index == 0:
def_platforms = config["pl"]
platforms = ["gp", "ios", "win32"]
compare_name_from_definition_to_excel_name_for_platforms(config, def_platforms, platforms, row)
assert_all_items_and_rows_for_boos(item, row)
def assert_all_items_and_rows_when_index_is_0(config, index, item, row, asserts):
if index == 0:
def_platforms = config["pl"]
platforms = ["gp", "ios", "win32"]
compare_name_from_definition_to_excel_name_for_platforms(config, def_platforms, platforms, row)
assert_all_items_and_rows_for_ann(item, row)
def assert_all_items_and_rows_when_index_is_0(config, index, item, row, asserts):
if index == 0:
def_platforms = config["pl"]
platforms = ["gp", "ios", "win32"]
compare_name_from_definition_to_excel_name_for_platforms(config, def_platforms, platforms, row)
assert_all_items_and_rows_for_gem(item, row)
또는 다음과 같이 사용할 수 있습니다.
def assert_all_items_and_rows_when_index_is_0(config, index, item, row, asserts):
if asserts is "boos":
if index == 0:
def_platforms = config["platforms"]
platforms = ["gp", "ios", "win32"]
compare_name_from_definition_to_excel_name_for_platforms(config, def_platforms, platforms, row)
assert_all_items_and_rows_for_boos(item, row)
elif asserts is "gem":
if index == 0:
def_platforms = config["platforms"]
platforms = ["gp", "ios", "win32"]
compare_name_from_definition_to_excel_name_for_platforms(config, def_platforms, platforms, row)
assert_all_items_and_rows_for_gem(item, row)
else:
raise Exception('wrong parameter')
다른 assert 함수를 인수로 전달할 수 있습니다. 예를 들면 :
def assert_all_items_and_rows_when_index_is_0(config, index, item, row, asserts, assert_function):
if index == 0:
def_platforms = config["pl"]
platforms = ["gp", "ios", "win32"]
compare_name_from_definition_to_excel_name_for_platforms(config, def_platforms, platforms, row)
assert_function(item, row)
다음과 같이 호출합니다 (처음 5 개의 인수에 대해 없음을 입력했습니다. 거기에있는 것을 유지합니다.) :
assert_all_items_and_rows_when_index_is_0(None, None, None, None, None, assert_all_items_and_rows_for_boos)
assert_all_items_and_rows_when_index_is_0(None, None, None, None, None, assert_all_items_and_rows_for_ann)
assert_all_items_and_rows_when_index_is_0(None, None, None, None, None, assert_all_items_and_rows_for_gem)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다