本文整理汇总了Python中webkitpy.common.system.filesystem_mock.MockFileSystem类的典型用法代码示例。如果您正苦于以下问题:Python MockFileSystem类的具体用法?Python MockFileSystem怎么用?Python MockFileSystem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MockFileSystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_additional_platform_directory
def test_additional_platform_directory(self):
filesystem = MockFileSystem()
options, args = optparse.OptionParser().parse_args([])
port = base.Port(port_name='foo', filesystem=filesystem, options=options)
port.baseline_search_path = lambda: ['LayoutTests/platform/foo']
layout_test_dir = port.layout_tests_dir()
test_file = filesystem.join(layout_test_dir, 'fast', 'test.html')
# No additional platform directory
self.assertEqual(
port.expected_baselines(test_file, '.txt'),
[(None, 'fast/test-expected.txt')])
self.assertEqual(port.baseline_path(), 'LayoutTests/platform/foo')
# Simple additional platform directory
options.additional_platform_directory = ['/tmp/local-baselines']
filesystem.files = {
'/tmp/local-baselines/fast/test-expected.txt': 'foo',
}
self.assertEqual(
port.expected_baselines(test_file, '.txt'),
[('/tmp/local-baselines', 'fast/test-expected.txt')])
self.assertEqual(port.baseline_path(), '/tmp/local-baselines')
# Multiple additional platform directories
options.additional_platform_directory = ['/foo', '/tmp/local-baselines']
self.assertEqual(
port.expected_baselines(test_file, '.txt'),
[('/tmp/local-baselines', 'fast/test-expected.txt')])
self.assertEqual(port.baseline_path(), '/foo')
示例2: test_find_log_darwin
def test_find_log_darwin(self):
if not SystemHost().platform.is_mac():
return
older_mock_crash_report = make_mock_crash_report_darwin('DumpRenderTree', 28528)
mock_crash_report = make_mock_crash_report_darwin('DumpRenderTree', 28530)
newer_mock_crash_report = make_mock_crash_report_darwin('DumpRenderTree', 28529)
other_process_mock_crash_report = make_mock_crash_report_darwin('FooProcess', 28527)
misformatted_mock_crash_report = 'Junk that should not appear in a crash report' + make_mock_crash_report_darwin('DumpRenderTree', 28526)[200:]
files = {}
files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150718_quadzen.crash'] = older_mock_crash_report
files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150719_quadzen.crash'] = mock_crash_report
files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150720_quadzen.crash'] = newer_mock_crash_report
files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150721_quadzen.crash'] = None
files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150722_quadzen.crash'] = other_process_mock_crash_report
files['/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150723_quadzen.crash'] = misformatted_mock_crash_report
filesystem = MockFileSystem(files)
crash_logs = CrashLogs(MockSystemHost(filesystem=filesystem))
log = crash_logs.find_newest_log("DumpRenderTree")
self.assertLinesEqual(log, newer_mock_crash_report)
log = crash_logs.find_newest_log("DumpRenderTree", 28529)
self.assertLinesEqual(log, newer_mock_crash_report)
log = crash_logs.find_newest_log("DumpRenderTree", 28530)
self.assertLinesEqual(log, mock_crash_report)
log = crash_logs.find_newest_log("DumpRenderTree", 28531)
self.assertEqual(log, None)
log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0)
self.assertEqual(log, None)
def bad_read(path):
raise IOError('No such file or directory')
filesystem.read_text_file = bad_read
log = crash_logs.find_newest_log("DumpRenderTree", 28531, include_errors=True)
self.assertTrue('No such file or directory' in log)
示例3: test_additional_platform_directory
def test_additional_platform_directory(self):
filesystem = MockFileSystem()
port = Port(port_name='foo', filesystem=filesystem)
port.baseline_search_path = lambda: ['LayoutTests/platform/foo']
layout_test_dir = port.layout_tests_dir()
test_file = 'fast/test.html'
# No additional platform directory
self.assertEqual(
port.expected_baselines(test_file, '.txt'),
[(None, 'fast/test-expected.txt')])
self.assertEqual(port.baseline_path(), 'LayoutTests/platform/foo')
# Simple additional platform directory
port._options.additional_platform_directory = ['/tmp/local-baselines']
filesystem.files = {
'/tmp/local-baselines/fast/test-expected.txt': 'foo',
}
self.assertEqual(
port.expected_baselines(test_file, '.txt'),
[('/tmp/local-baselines', 'fast/test-expected.txt')])
self.assertEqual(port.baseline_path(), '/tmp/local-baselines')
# Multiple additional platform directories
port._options.additional_platform_directory = ['/foo', '/tmp/local-baselines']
self.assertEqual(
port.expected_baselines(test_file, '.txt'),
[('/tmp/local-baselines', 'fast/test-expected.txt')])
self.assertEqual(port.baseline_path(), '/foo')
示例4: test_set_reviewer
def test_set_reviewer(self):
fs = MockFileSystem()
changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate_with_bugurl, self._example_changelog)
reviewer_name = "Test Reviewer"
fs.write_text_file(self._changelog_path, changelog_contents)
ChangeLog(self._changelog_path, fs).set_reviewer(reviewer_name)
actual_contents = fs.read_text_file(self._changelog_path)
expected_contents = changelog_contents.replace("NOBODY (OOPS!)", reviewer_name)
self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines())
changelog_contents_without_reviewer_line = u"%s\n%s" % (
self._new_entry_boilerplate_without_reviewer_line,
self._example_changelog,
)
fs.write_text_file(self._changelog_path, changelog_contents_without_reviewer_line)
ChangeLog(self._changelog_path, fs).set_reviewer(reviewer_name)
actual_contents = fs.read_text_file(self._changelog_path)
self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines())
changelog_contents_without_reviewer_line = u"%s\n%s" % (
self._new_entry_boilerplate_without_reviewer_multiple_bugurl,
self._example_changelog,
)
fs.write_text_file(self._changelog_path, changelog_contents_without_reviewer_line)
ChangeLog(self._changelog_path, fs).set_reviewer(reviewer_name)
actual_contents = fs.read_text_file(self._changelog_path)
changelog_contents = u"%s\n%s" % (self._new_entry_boilerplate_with_multiple_bugurl, self._example_changelog)
expected_contents = changelog_contents.replace("NOBODY (OOPS!)", reviewer_name)
self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines())
示例5: test_prepend_text
def test_prepend_text(self):
fs = MockFileSystem()
fs.write_text_file(self._changelog_path, self._example_changelog)
ChangeLog(self._changelog_path, fs).prepend_text(self._example_entry + "\n")
actual_contents = fs.read_text_file(self._changelog_path)
expected_contents = self._example_entry + "\n" + self._example_changelog
self.assertEqual(actual_contents.splitlines(), expected_contents.splitlines())
示例6: DirectoryFileSetTest
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'))
示例7: test_check
def test_check(self):
errors = []
def mock_handle_style_error(line_number, category, confidence, message):
error = (line_number, category, confidence, message)
errors.append(error)
fs = MockFileSystem()
file_path = "foo.png"
fs.write_binary_file(file_path, "Dummy binary data")
errors = []
checker = PNGChecker(file_path, mock_handle_style_error, MockSystemHost(os_name='linux', filesystem=fs))
checker.check()
self.assertEqual(len(errors), 0)
file_path = "foo-expected.png"
fs.write_binary_file(file_path, "Dummy binary data")
errors = []
checker = PNGChecker(file_path, mock_handle_style_error, MockSystemHost(os_name='linux', filesystem=fs))
checker.check()
self.assertEqual(len(errors), 1)
self.assertEqual(
errors[0],
(0, 'image/png', 5, 'Image lacks a checksum. Generate pngs using run-webkit-tests to ensure they have a checksum.'))
示例8: assert_interpreter_for_content
def assert_interpreter_for_content(self, intepreter, content):
fs = MockFileSystem()
tempfile, temp_name = fs.open_binary_tempfile('')
tempfile.write(content)
tempfile.close()
file_interpreter = Executive.interpreter_for_script(temp_name, fs)
self.assertEqual(file_interpreter, intepreter)
示例9: test_collect_tests
def test_collect_tests(self):
runner = self.create_runner()
runner._base_path = '/test.checkout/PerformanceTests'
filesystem = MockFileSystem()
filename = filesystem.join(runner._base_path, 'inspector', 'a_file.html')
filesystem.maybe_make_directory(runner._base_path, 'inspector')
filesystem.files[filename] = 'a content'
runner._host.filesystem = filesystem
tests = runner._collect_tests()
self.assertEqual(len(tests), 1)
示例10: unit_test_filesystem
def unit_test_filesystem(files=None):
"""Return the FileSystem object used by the unit tests."""
test_list = unit_test_list()
files = files or {}
def add_file(files, test, suffix, contents):
dirname = test.name[0:test.name.rfind('/')]
base = test.base
path = LAYOUT_TEST_DIR + '/' + dirname + '/' + base + suffix
files[path] = contents
# Add each test and the expected output, if any.
for test in test_list.tests.values():
add_file(files, test, '.html', '')
if test.is_reftest:
continue
if test.actual_audio:
add_file(files, test, '-expected.wav', test.expected_audio)
continue
add_file(files, test, '-expected.txt', test.expected_text)
add_file(files, test, '-expected.png', test.expected_image)
# Add the test_expectations file.
files[LAYOUT_TEST_DIR + '/platform/test/test_expectations.txt'] = """
WONTFIX : failures/expected/checksum.html = IMAGE
WONTFIX : failures/expected/crash.html = CRASH
WONTFIX : failures/expected/image.html = IMAGE
WONTFIX : failures/expected/audio.html = AUDIO
WONTFIX : failures/expected/image_checksum.html = IMAGE
WONTFIX : failures/expected/mismatch.html = IMAGE
WONTFIX : failures/expected/missing_check.html = MISSING PASS
WONTFIX : failures/expected/missing_image.html = MISSING PASS
WONTFIX : failures/expected/missing_audio.html = MISSING PASS
WONTFIX : failures/expected/missing_text.html = MISSING PASS
WONTFIX : failures/expected/newlines_leading.html = TEXT
WONTFIX : failures/expected/newlines_trailing.html = TEXT
WONTFIX : failures/expected/newlines_with_excess_CR.html = TEXT
WONTFIX : failures/expected/reftest.html = IMAGE
WONTFIX : failures/expected/text.html = TEXT
WONTFIX : failures/expected/timeout.html = TIMEOUT
WONTFIX SKIP : failures/expected/hang.html = TIMEOUT
WONTFIX SKIP : failures/expected/keyboard.html = CRASH
WONTFIX SKIP : failures/expected/exception.html = CRASH
"""
# FIXME: This test was only being ignored because of missing a leading '/'.
# Fixing the typo causes several tests to assert, so disabling the test entirely.
# Add in a file should be ignored by test_files.find().
#files[LAYOUT_TEST_DIR + '/userscripts/resources/iframe.html'] = 'iframe'
fs = MockFileSystem(files, dirs=set(['/mock-checkout'])) # Make sure at least the checkout_root exists as a directory.
fs._tests = test_list
return fs
示例11: test_find_log_darwin
def test_find_log_darwin(self):
if not SystemHost().platform.is_mac():
return
older_mock_crash_report = make_mock_crash_report_darwin("DumpRenderTree", 28528)
mock_crash_report = make_mock_crash_report_darwin("DumpRenderTree", 28530)
newer_mock_crash_report = make_mock_crash_report_darwin("DumpRenderTree", 28529)
other_process_mock_crash_report = make_mock_crash_report_darwin("FooProcess", 28527)
misformatted_mock_crash_report = (
"Junk that should not appear in a crash report"
+ make_mock_crash_report_darwin("DumpRenderTree", 28526)[200:]
)
files = {
"/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150718_quadzen.crash": older_mock_crash_report,
"/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150719_quadzen.crash": mock_crash_report,
"/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150720_quadzen.crash": newer_mock_crash_report,
"/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150721_quadzen.crash": None,
"/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150722_quadzen.crash": other_process_mock_crash_report,
"/Users/mock/Library/Logs/DiagnosticReports/DumpRenderTree_2011-06-13-150723_quadzen.crash": misformatted_mock_crash_report,
}
filesystem = MockFileSystem(files)
crash_logs = CrashLogs(MockSystemHost(filesystem=filesystem))
log = crash_logs.find_newest_log("DumpRenderTree")
self.assertMultiLineEqual(log, newer_mock_crash_report)
log = crash_logs.find_newest_log("DumpRenderTree", 28529)
self.assertMultiLineEqual(log, newer_mock_crash_report)
log = crash_logs.find_newest_log("DumpRenderTree", 28530)
self.assertMultiLineEqual(log, mock_crash_report)
log = crash_logs.find_newest_log("DumpRenderTree", 28531)
self.assertIsNone(log)
log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0)
self.assertIsNone(log)
def bad_read(path):
raise IOError("IOError: No such file or directory")
def bad_mtime(path):
raise OSError("OSError: No such file or directory")
filesystem.read_text_file = bad_read
log = crash_logs.find_newest_log("DumpRenderTree", 28531, include_errors=True)
self.assertIn("IOError: No such file or directory", log)
filesystem = MockFileSystem(files)
crash_logs = CrashLogs(MockSystemHost(filesystem=filesystem))
filesystem.mtime = bad_mtime
log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0, include_errors=True)
self.assertIn("OSError: No such file or directory", log)
示例12: MockCheckout
class MockCheckout(object):
def __init__(self):
# FIXME: It's unclear if a MockCheckout is very useful. A normal Checkout
# with a MockSCM/MockFileSystem/MockExecutive is probably better.
self._filesystem = MockFileSystem()
def is_path_to_changelog(self, path):
return self._filesystem.basename(path) == "ChangeLog"
def recent_commit_infos_for_files(self, paths):
return [self.commit_info_for_revision(32)]
def modified_changelogs(self, git_commit, changed_files=None):
# Ideally we'd return something more interesting here. The problem is
# that LandDiff will try to actually read the patch from disk!
return []
def commit_message_for_this_commit(self, git_commit, changed_files=None):
return MockCommitMessage()
def apply_patch(self, patch):
pass
def apply_reverse_diffs(self, revision):
pass
示例13: setUp
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)
示例14: setUp
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 = TestFinder(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_handler = None
for h in self.root_logger.handlers:
if getattr(h, 'name', None) == 'webkitpy.test.main':
self.log_handler = h
break
if self.log_handler:
self.log_level = self.log_handler.level
self.log_handler.level = logging.CRITICAL
示例15: test_find_log_darwin
def test_find_log_darwin(self):
if not SystemHost().platform.is_mac():
return
crash_logs = self.create_crash_logs_darwin()
log = crash_logs.find_newest_log("DumpRenderTree")
self.assertMultiLineEqual(log, self.newer_mock_crash_report)
log = crash_logs.find_newest_log("DumpRenderTree", 28529)
self.assertMultiLineEqual(log, self.newer_mock_crash_report)
log = crash_logs.find_newest_log("DumpRenderTree", 28530)
self.assertMultiLineEqual(log, self.mock_crash_report)
log = crash_logs.find_newest_log("DumpRenderTree", 28531)
self.assertIsNone(log)
log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0)
self.assertIsNone(log)
def bad_read(path):
raise IOError('IOError: No such file or directory')
def bad_mtime(path):
raise OSError('OSError: No such file or directory')
self.filesystem.read_text_file = bad_read
log = crash_logs.find_newest_log("DumpRenderTree", 28531, include_errors=True)
self.assertIn('IOError: No such file or directory', log)
self.filesystem = MockFileSystem(self.files)
crash_logs = CrashLogs(MockSystemHost(filesystem=self.filesystem))
self.filesystem.mtime = bad_mtime
log = crash_logs.find_newest_log("DumpRenderTree", newer_than=1.0, include_errors=True)
self.assertIn('OSError: No such file or directory', log)