runners: tests: fix os.path.isfile patch
Copy a fix from test_nrfjprog.py to the other runner test suites. The current code will enter an infinite recursion if you hit the path where os.path.isfile is called, since it's been patched to os_path_isfile_patch in the calling context. The fix is to cache the 'real' version in the parent scope and call it directly as a fallback. Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
80e5295dca
commit
09f55767b1
|
@ -161,11 +161,12 @@ def bcfg_check_cond5(item):
|
|||
def bcfg_get_cond5(item):
|
||||
return dict(BC_DICT_COND5)[item]
|
||||
|
||||
os_path_isfile = os.path.isfile
|
||||
|
||||
def os_path_isfile_patch(filename):
|
||||
if filename == RC_KERNEL_BIN:
|
||||
return True
|
||||
return os.path.isfile(filename)
|
||||
|
||||
return os_path_isfile(filename)
|
||||
|
||||
@patch('runners.bossac.BossacBinaryRunner.supports',
|
||||
return_value=False)
|
||||
|
|
|
@ -30,10 +30,12 @@ TEST_CASES = [(n, x, p, c, o, t)
|
|||
for o in (False, True)
|
||||
for t in range(1, 3)]
|
||||
|
||||
os_path_isfile = os.path.isfile
|
||||
|
||||
def os_path_isfile_patch(filename):
|
||||
if filename == RC_KERNEL_BIN:
|
||||
return True
|
||||
return os.path.isfile(filename)
|
||||
return os_path_isfile(filename)
|
||||
|
||||
@pytest.mark.parametrize('test_case', TEST_CASES)
|
||||
@patch('runners.canopen_program.CANopenProgramDownloader')
|
||||
|
|
|
@ -55,10 +55,12 @@ def find_device_patch():
|
|||
def require_patch(program):
|
||||
assert program in [DFU_UTIL, TEST_EXE]
|
||||
|
||||
os_path_isfile = os.path.isfile
|
||||
|
||||
def os_path_isfile_patch(filename):
|
||||
if filename == RC_KERNEL_BIN:
|
||||
return True
|
||||
return os.path.isfile(filename)
|
||||
return os_path_isfile(filename)
|
||||
|
||||
def id_fn(tc):
|
||||
return 'exe={},alt={},dfuse_config={},img={}'.format(*tc)
|
||||
|
|
|
@ -65,10 +65,12 @@ def os_path_getsize_patch(filename):
|
|||
return TEST_BIN_SIZE
|
||||
return os.path.isfile(filename)
|
||||
|
||||
os_path_isfile = os.path.isfile
|
||||
|
||||
def os_path_isfile_patch(filename):
|
||||
if filename == RC_KERNEL_BIN:
|
||||
return True
|
||||
return os.path.isfile(filename)
|
||||
return os_path_isfile(filename)
|
||||
|
||||
@pytest.mark.parametrize('action', EXPECTED_COMMANDS)
|
||||
@patch('runners.core.ZephyrBinaryRunner.require', side_effect=require_patch)
|
||||
|
|
Loading…
Reference in a new issue