def test_find_micro_bit(): """ If a micro:bit is connected (according to PySerial) return the port and serial number. """ class FakePort: """ Pretends to be a representation of a port in PySerial. """ def __init__(self, port_info, serial_number): self.port_info = port_info self.serial_number = serial_number def __getitem__(self, key): return self.port_info[key] serial_number = '9900023431864e45000e10050000005b00000000cc4d28bd' port_info = [ '/dev/ttyACM3', 'MBED CMSIS-DAP', 'USB_CDC USB VID:PID=0D28:0204 ' 'SER=9900023431864e45000e10050000005b00000000cc4d28bd ' 'LOCATION=4-1.2' ] port = FakePort(port_info, serial_number) ports = [ port, ] with mock.patch('microfs.list_serial_ports', return_value=ports): result = microfs.find_microbit() assert result == ('/dev/ttyACM3', serial_number)
def flashF(folder): print("MicroBit is at: " + microfs.find_microbit()[0] + "\nMicroBit directory is at: " + uflash.find_microbit()) try: mfiles = microfs.ls() except OSError as e: print( str(e) + "\nMicrobit is probably calibrating, calibrate and then try again\nIf it still does not work try to " "replug your microbit or close other programs that is accessing your microbit" ) return "Could not write" print("Removing old stuff: " + str(mfiles)) for file in mfiles: microfs.rm(file) files = os.listdir(folder) print("Flashing new stuff: " + str(files)) for file in files: microfs.put(folder + "\\" + file) print("Flashed new stuff: " + str(microfs.ls()) + "\n") time.sleep(0.1) print("Done!" + "\n" + "Don't forget to name your main file \"main.py\"" + "\n" + InternalTools.bcolors.BOLD + "Reset your MicroBit to apply changes!")
def test_find_micro_bit(): """ If a micro:bit is connected (according to PySerial) return the port. """ port = ['/dev/ttyACM3', 'MBED CMSIS-DAP', 'USB_CDC USB VID:PID=0D28:0204 ' + 'SER=9900023431864e45000e10050000005b00000000cc4d28bd ' + 'LOCATION=4-1.2'] ports = [port, ] with mock.patch('microfs.list_serial_ports', return_value=ports): result = microfs.find_microbit() assert result == '/dev/ttyACM3'
def test_find_micro_bit_no_device(): """ If there is no micro:bit connected (according to PySerial) return None. """ port = ['/dev/ttyACM3', 'MBED NOT-MICROBIT', 'USB_CDC USB VID:PID=0D29:0205 ' + 'SER=9900023431864e45000e10050000005b00000000cc4d28de ' + 'LOCATION=4-1.3'] ports = [port, ] with mock.patch('microfs.list_serial_ports', return_value=ports): result = microfs.find_microbit() assert result is None
def test_find_micro_bit_no_device(): """ If there is no micro:bit connected (according to PySerial) return None. """ port = [ "/dev/ttyACM3", "MBED NOT-MICROBIT", "USB_CDC USB VID:PID=0D29:0205 " "SER=9900023431864e45000e10050000005b00000000cc4d28de " "LOCATION=4-1.3", ] ports = [ port, ] with mock.patch("microfs.list_serial_ports", return_value=ports): result = microfs.find_microbit() assert result == (None, None)