示例#1
0
 def test_get_file_object_2(self, m):
     """Decorator version of the test_get_file_obejct()"""
     m.return_value = mock.sentinel.file_object
     # check if the correct file is opened
     file_object = get_file_object(self.path_source)
     m.assert_called_once_with(self.path_source, 'rb')
     # check if an expected object is returned
     self.assertEqual(file_object, mock.sentinel.file_object)
示例#2
0
 def test_get_file_object(self):
     """Check if the correct file is opened"""
     m = mock.MagicMock(spec=file, return_value=mock.sentinel.file_object)
     with mock.patch('__builtin__.open', m):
         file_object = get_file_object(self.path_source)
     m.assert_called_once_with(self.path_source, 'rb')
     # check if an expected object is returned
     self.assertEqual(file_object, mock.sentinel.file_object)
示例#3
0
 def test_get_file_object_2(self, m):
     '''Decorator version of the test_get_file_obejct()'''
     m.return_value = mock.sentinel.file_object
     # check if the correct file is opened
     file_object = get_file_object(self.path_source)
     m.assert_called_once_with(self.path_source, 'rb')
     # check if an expected object is returned
     self.assertEqual(file_object, mock.sentinel.file_object)
示例#4
0
 def __setstate__(self, dictionary):
     # reopen file byte stream
     # TODO: replace get_file_object() with open(), make sure file object
     # is closed after use
     file_object = get_file_object(dictionary['filename'])
     bytestream = TDFByteStream(file_object)
     self.__dict__.update(dictionary)  # reload attributes
     self.bytestream = bytestream  # re-attach the byte stream
示例#5
0
 def test_get_file_object(self):
     # check if the correct file is opened
     m = mock.MagicMock(spec=file, return_value=mock.sentinel.file_object)
     with mock.patch('__builtin__.open', m):
         file_object = get_file_object(self.path_source)
     m.assert_called_once_with(self.path_source, 'rb')
     # check if an expected object is returned
     self.assertEqual(file_object, mock.sentinel.file_object)