def test_program_bitstream(success): # prepare calls = [] fpga = TinyFPGAB(None, lambda *a: calls.append(('progress', a))) # patching methods fpga.wake = lambda *a: calls.append(('wake', a)) fpga.read_sts = lambda *a: calls.append(('read_sts', a)) fpga.read = lambda *a: calls.append(('read', a)) if success: fpga.program = lambda *a: calls.append(('program', a)) or True else: fpga.program = lambda *a: calls.append(('program', a)) or False fpga.boot = lambda *a: calls.append(('boot', a)) # run output = fpga.program_bitstream(0x123456, DATA) # check assert output == success expected_calls = [ ('progress', ('Waking up SPI flash', )), ('progress', ('35 bytes to program', )), ('program', (0x123456, DATA)), ] if success: expected_calls.append(('boot', ())) assert calls == expected_calls
def test_is_bootloader_active(success_after): # prepare calls = [] fpga = TinyFPGAB(None) read_id = ['ABC'] * success_after + ['\x1f\x84\x01'] # patching methods fpga.wake = lambda *a: calls.append(('wake', a)) fpga.read = lambda *a: calls.append(('read', a)) fpga.read_id = lambda *a: calls.append(('read_id', a)) or read_id.pop(0) # run output = fpga.is_bootloader_active() # check assert output == (success_after < 6) expected_calls = [ ('wake', ()), ('read', (0, 16)), ('wake', ()), ('read_id', ()), ] * min(success_after + 1, 6) assert calls == expected_calls
def test_is_bootloader_active(success_after): # prepare calls = [] fpga = TinyFPGAB(None) read_id = ['ABC'] * success_after + [b'\x1f\x84\x01'] # patching methods fpga.wake = lambda *a: calls.append(('wake', a)) fpga.read = lambda *a: calls.append(('read', a)) fpga.read_id = lambda *a: calls.append(('read_id', a)) or read_id.pop(0) # run output = fpga.is_bootloader_active() # check assert output == (success_after < 6) expected_calls = [ ('wake', ()), ('read', (0, 16)), ('wake', ()), ('read_id', ()), ] * min(success_after + 1, 6) assert calls == expected_calls