示例#1
0
    def test_file_is_opened_when_path_is_given(self, open):
        file = mock.Mock()
        open.return_value = file

        f = File('test.txt')
        f.read()

        open.assert_called_once_with('test.txt', 'rb')
        file.read.assert_called_once_with()
示例#2
0
    def get_file(self, path='', params=None):
        """GETs a file from the given path with the given parameters.

        :param str path: Path to which the request should be sent.
        :param dict params: Request parameters.

        :returns: File from `path` (:class:`~retdec.file.File`).

        If `path` is the empty string, it sends the request to the base URL
        from which the connection was initialized.
        """
        response = self._send_request('get', path, params=params, stream=True)
        return File(response.raw, self._get_file_name(response.headers))
示例#3
0
 def _get_input_file(self, params):
     """Returns an input file from the given parameters (``dict``)."""
     if 'input_file' in params:
         return File(params['input_file'])
示例#4
0
 def _add_pdb_file_when_given(self, files, kwargs):
     """Adds a PDB file to `files` when it was given."""
     pdb_file = kwargs.get('pdb_file')
     if pdb_file is not None:
         files['pdb'] = File(pdb_file)
示例#5
0
 def _get_input_file(self, kwargs):
     """Returns the input file to be decompiled."""
     try:
         return File(kwargs['input_file'])
     except KeyError:
         raise MissingParameterError('input_file')
示例#6
0
    def test_repr_returns_correct_value(self):
        f = File(io.StringIO('...'), name='file.txt')

        self.assertEqual(repr(f), "<retdec.file.File name='file.txt' mode=None>")
示例#7
0
    def test_mode_returns_none_when_underlying_file_has_no_mode(self):
        f = File(io.StringIO('...'))

        self.assertIsNone(f.mode)
示例#8
0
    def test_name_returns_none_when_file_has_no_name(self):
        f = File(io.StringIO('...'))

        self.assertIsNone(f.name)
示例#9
0
    def test_name_returns_custom_name_when_given(self):
        f = File(io.StringIO('...'), 'file.txt')

        self.assertEqual(f.name, 'file.txt')
示例#10
0
 def test_mode_returns_original_mode_when_underlying_file_has_mode(self):
     file = mock.Mock()
     file.mode = 'r+'
     f = File(file)
     self.assertEqual(f.mode, 'r+')
示例#11
0
 def test_name_returns_original_name_when_no_custom_name_is_given(self):
     file = mock.Mock()
     file.name = 'file.txt'
     f = File(file)
     self.assertEqual(f.name, 'file.txt')
示例#12
0
 def test_file_is_used_directly_when_opened_file_is_given(self):
     file = mock.Mock()
     f = File(file)
     f.read()
     file.read.assert_called_once_with()