def test_ls_bad_directory(self): pyboard = mock.Mock() pyboard.exec_ = mock.Mock(side_effect=PyboardError( 'exception', b'', b'Traceback (most recent call last):\r\n File "<stdin>", line 3, in <module>\r\nOSError: [Errno 2] ENOENT\r\n' )) with self.raisesRegex(RuntimeError, 'No such directory: /foo'): board_files = files.Files(pyboard) result = board_files.ls('/foo')
def test_rm_file_doesnt_exist(self): pyboard = mock.Mock() pyboard.exec_ = mock.Mock(side_effect=PyboardError( 'exception', b'', b'Traceback (most recent call last):\r\n File "<stdin>", line 3, in <module>\r\nOSError: [Errno 2] ENOENT\r\n' )) with self.raisesRegex(RuntimeError, 'No such file/directory: foo.txt'): board_files = files.Files(pyboard) result = board_files.rm('foo.txt')
def test_rm_directory_not_empty(self): pyboard = mock.Mock() pyboard.exec_ = mock.Mock(side_effect=PyboardError( 'exception', b'', b'Traceback (most recent call last):\r\n File "<stdin>", line 3, in <module>\r\nOSError: [Errno 13] EACCES\r\n' )) with self.raisesRegex(RuntimeError, 'Directory is not empty: foo'): board_files = files.Files(pyboard) result = board_files.rm('foo')
def test_mkdir_directory_already_exists(self): pyboard = mock.Mock() pyboard.exec_ = mock.Mock(side_effect=PyboardError( 'exception', b'', b'Traceback (most recent call last):\r\n File "<stdin>", line 3, in <module>\r\nOSError: [Errno 17] EEXIST\r\n' )) with self.raisesRegex(RuntimeError, 'Directory already exists: /foo'): board_files = files.Files(pyboard) board_files.mkdir('/foo')
def test_get_bad_file(self): pyboard = mock.Mock() pyboard.exec_ = mock.Mock(side_effect=PyboardError( "exception", b"", b'Traceback (most recent call last):\r\n File "<stdin>", line 3, in <module>\r\nOSError: [Errno 2] ENOENT\r\n', )) with self.raisesRegex(RuntimeError, "No such file: foo.txt"): board_files = files.Files(pyboard) result = board_files.get("foo.txt")
def test_rmdir_folder_doesnt_exist(self): pyboard = mock.Mock() pyboard.exec_ = mock.Mock(side_effect=PyboardError( "exception", b"", b'Traceback (most recent call last):\r\n File "<stdin>", line 3, in <module>\r\nOSError: [Errno 2] ENOENT\r\n', )) with self.raisesRegex(RuntimeError, "No such directory: foo"): board_files = files.Files(pyboard) result = board_files.rmdir("foo")
def get(self, filename, text=False): terminator = b'*d*o*n*e*' self.remoteExecute("getFile", filename, terminator, BUFFER_SIZE) size = int.from_bytes(self.serial.read(4), "big") if size == 0x4547261: # b'Trac...' data_err = self.read_until(1, b'\x04') if not data_err.endswith(b'\x04'): raise PyboardError('timeout waiting for second EOF reception') data_err = size.to_bytes(4, "big") + data_err[:-1] error = PyboardOSError("Exception", b'', data_err) raise RuntimeError(error.translate()) # line endings may get changed in size result = self.read_until(size, terminator)[:-len(terminator)] if text: result = result.decode("utf-8").replace("\r\n", "\n") return result