当前位置: 首页>>代码示例>>Python>>正文


Python MagicMock.st_mtime方法代码示例

本文整理汇总了Python中tests.functional.MagicMock.st_mtime方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.st_mtime方法的具体用法?Python MagicMock.st_mtime怎么用?Python MagicMock.st_mtime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tests.functional.MagicMock的用法示例。


在下文中一共展示了MagicMock.st_mtime方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_validate_thumb_file_exists_and_newer

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import st_mtime [as 别名]
 def test_validate_thumb_file_exists_and_newer(self):
     """
     Test the validate_thumb() function when the thumbnail exists and has a newer timestamp than the file
     """
     # GIVEN: A mocked out os module, functions rigged to work for us, and fake paths to a file and a thumb
     with patch('openlp.core.lib.os') as mocked_os:
         file_path = 'path/to/file'
         thumb_path = 'path/to/thumb'
         file_mocked_stat = MagicMock()
         file_mocked_stat.st_mtime = datetime.now()
         thumb_mocked_stat = MagicMock()
         thumb_mocked_stat.st_mtime = datetime.now() + timedelta(seconds=10)
         mocked_os.path.exists.return_value = True
         mocked_os.stat.side_effect = [file_mocked_stat, thumb_mocked_stat]
开发者ID:imkernel,项目名称:openlp,代码行数:16,代码来源:test_lib.py

示例2: test_validate_thumb_file_exists_and_older

# 需要导入模块: from tests.functional import MagicMock [as 别名]
# 或者: from tests.functional.MagicMock import st_mtime [as 别名]
    def test_validate_thumb_file_exists_and_older(self):
        """
        Test the validate_thumb() function when the thumbnail exists but is older than the file
        """
        # GIVEN: A mocked out os module, functions rigged to work for us, and fake paths to a file and a thumb
        with patch('openlp.core.lib.os') as mocked_os:
            file_path = 'path/to/file'
            thumb_path = 'path/to/thumb'
            file_mocked_stat = MagicMock()
            file_mocked_stat.st_mtime = datetime.now()
            thumb_mocked_stat = MagicMock()
            thumb_mocked_stat.st_mtime = datetime.now() - timedelta(seconds=10)
            mocked_os.path.exists.return_value = True
            mocked_os.stat.side_effect = lambda fname: file_mocked_stat if fname == file_path else thumb_mocked_stat

            # WHEN: we run the validate_thumb() function
            result = validate_thumb(file_path, thumb_path)

            # THEN: we should have called a few functions, and the result should be False
            mocked_os.path.exists.assert_called_with(thumb_path)
            mocked_os.stat.assert_any_call(file_path)
            mocked_os.stat.assert_any_call(thumb_path)
            assert result is False, 'The result should be False'
开发者ID:imkernel,项目名称:openlp,代码行数:25,代码来源:test_lib.py


注:本文中的tests.functional.MagicMock.st_mtime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。