def test_save_hex_path_not_to_hex_file(): """ The function raises a ValueError if the path is NOT to a .hex file. """ with pytest.raises(ValueError) as ex: uflash.save_hex('foo', '') assert ex.value.args[0] == 'The path to flash must be for a .hex file.'
def test_save_hex_no_hex(): """ The function raises a ValueError if no hex content is provided. """ with pytest.raises(ValueError) as ex: uflash.save_hex('', 'foo') assert ex.value.args[0] == 'Cannot flash an empty .hex file.'
def test_save_hex(): """ Ensure the good case works. """ # Ensure we have a temporary file to write to that doesn't already exist. path_to_hex = os.path.join(tempfile.gettempdir(), "microbit.hex") if os.path.exists(path_to_hex): os.remove(path_to_hex) assert not os.path.exists(path_to_hex) # Create the hex file we want to "flash" hex_file = uflash.embed_fs_uhex(uflash._RUNTIME, TEST_SCRIPT) # Save the hex. uflash.save_hex(hex_file, path_to_hex) # Ensure the hex has been written as expected. assert os.path.exists(path_to_hex) with open(path_to_hex) as written_file: assert written_file.read() == hex_file
def test_save_hex(): """ Ensure the good case works. """ # Ensure we have a temporary file to write to that doesn't already exist. path_to_hex = os.path.join(tempfile.gettempdir(), 'microbit.hex') if os.path.exists(path_to_hex): os.remove(path_to_hex) assert not os.path.exists(path_to_hex) # Create the hex file we want to "flash" python = uflash.hexlify(TEST_SCRIPT) hex_file = uflash.embed_hex(uflash._RUNTIME, python) # Save the hex. uflash.save_hex(hex_file, path_to_hex) # Ensure the hex has been written as expected. assert os.path.exists(path_to_hex) with open(path_to_hex) as written_file: assert written_file.read() == hex_file