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


Python MockFileSystem.exists方法代码示例

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


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

示例1: DirectoryFileSetTest

# 需要导入模块: from webkitpy.common.system.filesystem_mock import MockFileSystem [as 别名]
# 或者: from webkitpy.common.system.filesystem_mock.MockFileSystem import exists [as 别名]
class DirectoryFileSetTest(unittest.TestCase):
    def setUp(self):
        files = {}
        files['/test/some-file'] = 'contents'
        files['/test/some-other-file'] = 'other contents'
        files['/test/b/c'] = 'c'
        self._filesystem = MockFileSystem(files)
        self._fileset = DirectoryFileSet('/test', self._filesystem)

    def test_files_in_namelist(self):
        self.assertTrue('some-file' in self._fileset.namelist())
        self.assertTrue('some-other-file' in self._fileset.namelist())
        self.assertTrue('b/c' in self._fileset.namelist())

    def test_read(self):
        self.assertEquals('contents', self._fileset.read('some-file'))

    def test_open(self):
        file = self._fileset.open('some-file')
        self.assertEquals('some-file', file.name())
        self.assertEquals('contents', file.contents())

    def test_extract(self):
        self._fileset.extract('some-file', '/test-directory')
        contents = self._filesystem.read_text_file('/test-directory/some-file')
        self.assertEquals('contents', contents)

    def test_extract_deep_file(self):
        self._fileset.extract('b/c', '/test-directory')
        self.assertTrue(self._filesystem.exists('/test-directory/b/c'))

    def test_delete(self):
        self.assertTrue(self._filesystem.exists('/test/some-file'))
        self._fileset.delete('some-file')
        self.assertFalse(self._filesystem.exists('/test/some-file'))
开发者ID:0x4d52,项目名称:JavaScriptCore-X,代码行数:37,代码来源:directoryfileset_unittest.py

示例2: FinderTest

# 需要导入模块: from webkitpy.common.system.filesystem_mock import MockFileSystem [as 别名]
# 或者: from webkitpy.common.system.filesystem_mock.MockFileSystem import exists [as 别名]
class FinderTest(unittest.TestCase):
    def setUp(self):
        files = {
          '/foo/bar/baz.py': '',
          '/foo/bar/baz_unittest.py': '',
          '/foo2/bar2/baz2.py': '',
          '/foo2/bar2/baz2.pyc': '',
          '/foo2/bar2/baz2_integrationtest.py': '',
          '/foo2/bar2/missing.pyc': '',
          '/tmp/another_unittest.py': '',
        }
        self.fs = MockFileSystem(files)
        self.finder = Finder(self.fs)
        self.finder.add_tree('/foo', 'bar')
        self.finder.add_tree('/foo2')

        # Here we have to jump through a hoop to make sure test-webkitpy doesn't log
        # any messages from these tests :(.
        self.root_logger = logging.getLogger()
        self.log_levels = []
        self.log_handlers = self.root_logger.handlers[:]
        for handler in self.log_handlers:
            self.log_levels.append(handler.level)
            handler.level = logging.CRITICAL

    def tearDown(self):
        for handler in self.log_handlers:
            handler.level = self.log_levels.pop(0)

    def test_additional_system_paths(self):
        self.assertEqual(self.finder.additional_paths(['/usr']),
                          ['/foo', '/foo2'])

    def test_is_module(self):
        self.assertTrue(self.finder.is_module('bar.baz'))
        self.assertTrue(self.finder.is_module('bar2.baz2'))
        self.assertTrue(self.finder.is_module('bar2.baz2_integrationtest'))

        # Missing the proper namespace.
        self.assertFalse(self.finder.is_module('baz'))

    def test_to_module(self):
        self.assertEqual(self.finder.to_module('/foo/test.py'), 'test')
        self.assertEqual(self.finder.to_module('/foo/bar/test.py'), 'bar.test')
        self.assertEqual(self.finder.to_module('/foo/bar/pytest.py'), 'bar.pytest')

    def test_clean(self):
        self.assertTrue(self.fs.exists('/foo2/bar2/missing.pyc'))
        self.finder.clean_trees()
        self.assertFalse(self.fs.exists('/foo2/bar2/missing.pyc'))

    def check_names(self, names, expected_names, find_all=True):
        self.assertEqual(self.finder.find_names(names, find_all), expected_names)

    def test_default_names(self):
        self.check_names([], ['bar.baz_unittest', 'bar2.baz2_integrationtest'], find_all=True)
        self.check_names([], ['bar.baz_unittest', 'bar2.baz2_integrationtest'], find_all=False)

        # Should return the names given it, even if they don't exist.
        self.check_names(['foobar'], ['foobar'], find_all=False)

    def test_paths(self):
        self.fs.chdir('/foo/bar')
        self.check_names(['baz_unittest.py'], ['bar.baz_unittest'])
        self.check_names(['./baz_unittest.py'], ['bar.baz_unittest'])
        self.check_names(['/foo/bar/baz_unittest.py'], ['bar.baz_unittest'])
        self.check_names(['.'], ['bar.baz_unittest'])
        self.check_names(['../../foo2/bar2'], ['bar2.baz2_integrationtest'])

        self.fs.chdir('/')
        self.check_names(['bar'], ['bar.baz_unittest'])
        self.check_names(['/foo/bar/'], ['bar.baz_unittest'])

        # This works 'by accident' since it maps onto a package.
        self.check_names(['bar/'], ['bar.baz_unittest'])

        # This should log an error, since it's outside the trees.
        oc = OutputCapture()
        oc.set_log_level(logging.ERROR)
        oc.capture_output()
        try:
            self.check_names(['/tmp/another_unittest.py'], [])
        finally:
            _, _, logs = oc.restore_output()
            self.assertIn('another_unittest.py', logs)

        # Paths that don't exist are errors.
        oc.capture_output()
        try:
            self.check_names(['/foo/bar/notexist_unittest.py'], [])
        finally:
            _, _, logs = oc.restore_output()
            self.assertIn('notexist_unittest.py', logs)

        # Names that don't exist are caught later, at load time.
        self.check_names(['bar.notexist_unittest'], ['bar.notexist_unittest'])
开发者ID:Igalia,项目名称:blink,代码行数:98,代码来源:finder_unittest.py


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