本文整理汇总了Python中unittest.mock.Mock.file_name方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.file_name方法的具体用法?Python Mock.file_name怎么用?Python Mock.file_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.file_name方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_transfer_started_handler_older
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import file_name [as 别名]
def test_transfer_started_handler_older(self, compare_file):
transfer = Mock()
transfer.get_remote_uuid.return_value = 'remote_uuid'
transfer.file_name = 'file1'
self.manager._TransferManager__transfer_started(transfer)
self.assertTrue(self.manager.transfers.has('file1', 'remote_uuid'))
transfer2 = Mock()
transfer2.get_remote_uuid.return_value = 'remote_uuid'
transfer2.file_name = 'file1'
compare_file.return_value = syncall.index.NOT_MODIFIED
self.manager._TransferManager__transfer_started(transfer2)
self.assertTrue(self.manager.transfers.has('file1', 'remote_uuid'))
self.assertTrue(transfer2.shutdown.called)
compare_file.return_value = syncall.index.CONFLICT
transfer2.shutdown.called = False
self.manager._TransferManager__transfer_started(transfer2)
self.assertTrue(self.manager.transfers.has('file1', 'remote_uuid'))
self.assertTrue(transfer2.shutdown.called)
示例2: test_finalize_transfer_from_remote_old
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import file_name [as 别名]
def test_finalize_transfer_from_remote_old(self, compare_file):
transfer = Mock()
transfer.type = syncall.transfers.FileTransfer.FROM_REMOTE
transfer.file_name = 'file1'
compare_file.return_value = syncall.index.CONFLICT
self.directory.get_file_path = Mock()
self.directory.get_file_path.return_value = '/dir/file1'
self.directory.last_update = 123
self.directory.save_index = Mock()
self.directory.index_updated = Mock()
self.directory._index['file1'] = {
'last_update': 1234,
'sync_log': {
'my_uuid': 1234,
'uuid1': 1200,
'uuid2': 1000
}
}
self.directory.finalize_transfer(transfer)
self.assertEqual(self.directory.last_update, 123)
self.assertEqual(self.directory._index['file1'], {
'last_update': 1234,
'sync_log': {
'my_uuid': 1234,
'uuid1': 1200,
'uuid2': 1000
}
})
self.assertFalse(self.directory.index_updated.notify.called)
self.assertTrue(self.directory.save_index.called)
示例3: test_finalize_transfer_to_remote
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import file_name [as 别名]
def test_finalize_transfer_to_remote(self):
transfer = Mock()
transfer.type = syncall.transfers.FileTransfer.TO_REMOTE
transfer.file_name = 'file1'
transfer.get_remote_uuid.return_value = 'uuid2'
transfer.timestamp = 1250
self.directory.last_update = 123
self.directory.save_index = Mock()
self.directory.index_updated = Mock()
self.directory._index['file1'] = {
'last_update': 1234,
'sync_log': {
'my_uuid': 1234,
'uuid1': 1200,
'uuid2': 1000
}
}
self.directory.finalize_transfer(transfer)
self.assertGreater(self.directory.last_update, 123)
self.assertEqual(self.directory._index['file1'], {
'last_update': 1234,
'sync_log': {
'my_uuid': 1234,
'uuid1': 1200,
'uuid2': 1250
}
})
self.directory.index_updated.notify.assert_called_once_with(
{'file1'}
)
self.assertTrue(self.directory.save_index.called)
示例4: testBuild_namespace
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import file_name [as 别名]
def testBuild_namespace(self):
file_path = ['folder1','folder2','src','folder3','folder4','test.php']
settings = Mock()
settings.get = Mock(return_value=['src','tests'])
view = Mock()
view.settings = Mock(return_value=settings)
view.file_name = Mock(return_value=os.sep.join(file_path))
assert build_namespace(view) == 'folder3\\folder4'
示例5: test_new_transfer_started_handler
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import file_name [as 别名]
def test_new_transfer_started_handler(self):
transfer = Mock()
transfer.get_remote_uuid.return_value = 'remote_uuid'
transfer.file_name = 'file1'
self.manager._TransferManager__transfer_started(transfer)
self.assertTrue(self.manager.transfers.has('file1', 'remote_uuid'))
示例6: test_transfer_started_handler_newer
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import file_name [as 别名]
def test_transfer_started_handler_newer(self, compare_file):
transfer = Mock()
transfer.get_remote_uuid.return_value = 'remote_uuid'
transfer.file_name = 'file1'
self.manager._TransferManager__transfer_started(transfer)
self.assertTrue(self.manager.transfers.has('file1', 'remote_uuid'))
transfer2 = Mock()
transfer2.get_remote_uuid.return_value = 'remote_uuid'
transfer2.file_name = 'file1'
compare_file.return_value = syncall.index.NEEDS_UPDATE
self.manager._TransferManager__transfer_started(transfer2)
self.assertTrue(self.manager.transfers.has('file1', 'remote_uuid'))
self.assertTrue(transfer.shutdown.called)
示例7: test_add_contains
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import file_name [as 别名]
def test_add_contains(self):
transfer = Mock()
transfer.file_name = 'file1'
transfer.get_remote_uuid.return_value = 'uuid1'
transfer.type = syncall.transfers.FileTransfer.TO_REMOTE
self.dict.add(transfer)
self.assertTrue(self.dict.has('file1', 'uuid1'))
self.assertEqual(self.dict.get('file1', 'uuid1'), transfer)
transfer2 = Mock()
transfer2.file_name = 'file1'
transfer2.get_remote_uuid.return_value = 'uuid1'
self.assertTrue(self.dict.has_same(transfer2))
self.assertEqual(self.dict.get_same(transfer2), transfer)
self.assertTrue(self.dict.has_transfers('file1'))
self.assertFalse(self.dict.has_transfers('file2'))
示例8: test_remove
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import file_name [as 别名]
def test_remove(self):
transfer1 = Mock()
transfer1.file_name = 'file1'
transfer1.get_remote_uuid.return_value = 'uuid1'
transfer1.type = syncall.transfers.FileTransfer.TO_REMOTE
self.dict.add(transfer1)
self.dict.remove(transfer1)
self.assertFalse(self.dict.has_same(transfer1))
self.dict.remove(transfer1)
示例9: test_multiple_transfers
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import file_name [as 别名]
def test_multiple_transfers(self):
transfer1 = Mock()
transfer1.file_name = 'file1'
transfer1.get_remote_uuid.return_value = 'uuid1'
transfer1.type = syncall.transfers.FileTransfer.TO_REMOTE
transfer2 = Mock()
transfer2.file_name = 'file1'
transfer2.get_remote_uuid.return_value = 'uuid2'
transfer2.type = syncall.transfers.FileTransfer.TO_REMOTE
self.dict.add(transfer1)
self.dict.add(transfer2)
self.assertEqual(len(self.dict.get_transfers('file1')), 2)
self.assertEqual(self.dict.get_same(transfer1), transfer1)
self.assertEqual(self.dict.get_same(transfer2), transfer2)
self.assertEqual(
set(self.dict.get_all()),
{transfer1, transfer2}
)
示例10: test_finalize_transfer_from_remote_deleted
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import file_name [as 别名]
def test_finalize_transfer_from_remote_deleted(self, compare_file, remove):
transfer = Mock()
transfer.type = syncall.transfers.FileTransfer.FROM_REMOTE
transfer.file_name = 'file1'
transfer.messanger.my_uuid = 'uuid2'
transfer.timestamp = 1250
transfer.get_temp_path.return_value = '/temp/file1'
transfer.remote_file_data = {
'last_update': 1234,
'deleted': True,
'sync_log': {
'my_uuid': 1234,
'uuid1': 1200,
'uuid2': 1000
}
}
compare_file.return_value = syncall.index.NEEDS_UPDATE
self.directory.get_file_path = Mock()
self.directory.get_file_path.return_value = '/dir/file1'
self.directory.last_update = 123
self.directory.save_index = Mock()
self.directory.index_updated = Mock()
self.directory.finalize_transfer(transfer)
self.assertGreater(self.directory.last_update, 123)
self.assertEqual(self.directory._index['file1'], {
'last_update': 1234,
'deleted': True,
'sync_log': {
'my_uuid': 1234,
'uuid1': 1200,
'uuid2': 1250
}
})
self.directory.index_updated.notify.assert_called_once_with(
{'file1'}
)
remove.assert_called_once_with(
self.directory.get_file_path(transfer.file_name)
)
self.assertTrue(self.directory.save_index.called)
示例11: testIs_php_fileFalse
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import file_name [as 别名]
def testIs_php_fileFalse(self):
view = Mock()
view.file_name = Mock(return_value='test'+os.sep+'test.html')
assert is_php_file(view) == False
示例12: testIs_php_fileTrue
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import file_name [as 别名]
def testIs_php_fileTrue(self):
view = Mock()
view.file_name = Mock(return_value='test.php')
assert is_php_file(view) == True