예제 #1
0
파일: test_files.py 프로젝트: ustbexe/ampy
 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')
예제 #2
0
파일: test_files.py 프로젝트: ustbexe/ampy
 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')
예제 #3
0
파일: test_files.py 프로젝트: ustbexe/ampy
 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')
예제 #4
0
 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')
예제 #5
0
 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")
예제 #6
0
 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")
예제 #7
0
    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