def git(self, path=None): if path: return MockGit(cwd=path, filesystem=self.filesystem, executive=self.executive, platform=self.platform) if not self._git: self._git = MockGit(filesystem=self.filesystem, executive=self.executive, platform=self.platform) # Various pieces of code (wrongly) call filesystem.chdir(checkout_root). # Making the checkout_root exist in the mock filesystem makes that chdir not raise. self.filesystem.maybe_make_directory(self._git.checkout_root) return self._git
def test_more_failures_in_baseline_same_fails(self): executive = mock_git_commands({ 'diff': ('diff --git a/foo-expected.txt b/foo-expected.txt\n' '--- a/foo-expected.txt\n' '+++ b/foo-expected.txt\n' '-FAIL an old failure\n' '+FAIL a new failure\n') }) self.notifier.git = MockGit(executive=executive) self.assertFalse(self.notifier.more_failures_in_baseline('foo-expected.txt'))
def test_more_failures_in_baseline_error_to_fail(self): executive = mock_git_commands({ 'diff': ('diff --git a/foo-expected.txt b/foo-expected.txt\n' '--- a/foo-expected.txt\n' '+++ b/foo-expected.txt\n' '-Harness Error. harness_status.status = 1 , harness_status.message = bad\n' '+FAIL a new failure\n') }) self.notifier.git = MockGit(executive=executive) self.assertTrue( self.notifier.more_failures_in_baseline('foo-expected.txt'))
def test_more_failures_in_baseline_changing_error(self): executive = mock_git_commands({ 'diff': ('diff --git a/foo-expected.txt b/foo-expected.txt\n' '--- a/foo-expected.txt\n' '+++ b/foo-expected.txt\n' '-Harness Error. harness_status.status = 1 , harness_status.message = bad\n' '+Harness Error. new text, still an error\n') }) self.notifier.git = MockGit(executive=executive) self.assertFalse( self.notifier.more_failures_in_baseline('foo-expected.txt'))
def test_more_failures_in_baseline_more_fails(self): # Replacing self.host.executive won't work here, because ImportNotifier # has been instantiated with a MockGit backed by an empty MockExecutive. executive = mock_git_commands({ 'diff': ('diff --git a/foo-expected.txt b/foo-expected.txt\n' '--- a/foo-expected.txt\n' '+++ b/foo-expected.txt\n' '-FAIL an old failure\n' '+FAIL new failure 1\n' '+FAIL new failure 2\n') }) self.notifier.git = MockGit(executive=executive) self.assertTrue(self.notifier.more_failures_in_baseline('foo-expected.txt')) self.assertEqual(executive.calls, [['git', 'diff', '-U0', 'origin/master', '--', 'foo-expected.txt']])
def test_apply_exportable_commits_locally(self): # TODO(robertma): Consider using MockLocalWPT. host = self.mock_host() importer = self._get_test_importer( host, wpt_github=MockWPTGitHub(pull_requests=[])) importer.wpt_git = MockGit(cwd='/tmp/wpt', executive=host.executive) fake_commit = MockChromiumCommit( host, subject='My fake commit', patch=('Fake patch contents...\n' '--- a/' + RELATIVE_WEB_TESTS + 'external/wpt/css/css-ui-3/outline-004.html\n' '+++ b/' + RELATIVE_WEB_TESTS + 'external/wpt/css/css-ui-3/outline-004.html\n' '@@ -20,7 +20,7 @@\n' '...')) importer.exportable_but_not_exported_commits = lambda _: [fake_commit] applied = importer.apply_exportable_commits_locally(LocalWPT(host)) self.assertEqual(applied, [fake_commit]) # This assertion is implementation details of LocalWPT.apply_patch. # TODO(robertma): Move this to local_wpt_unittest.py. self.assertEqual(host.executive.full_calls, [ MockCall(MANIFEST_INSTALL_CMD, kwargs={ 'input': None, 'cwd': None, 'env': None }), MockCall( ['git', 'apply', '-'], { 'input': ('Fake patch contents...\n' '--- a/css/css-ui-3/outline-004.html\n' '+++ b/css/css-ui-3/outline-004.html\n' '@@ -20,7 +20,7 @@\n' '...'), 'cwd': '/tmp/wpt', 'env': None }), MockCall(['git', 'add', '.'], kwargs={ 'input': None, 'cwd': '/tmp/wpt', 'env': None }) ]) self.assertEqual( importer.wpt_git.local_commits(), [['Applying patch 14fd77e88e42147c57935c49d9e3b2412b8491b7']])
def setUp(self): BaseTestCase.setUp(self) LoggingTestCase.setUp(self) builds = { Build('MOCK Try Win', 5000): TryJobStatus('COMPLETED', 'FAILURE'), Build('MOCK Try Mac', 4000): TryJobStatus('COMPLETED', 'FAILURE'), Build('MOCK Try Linux', 6000): TryJobStatus('COMPLETED', 'FAILURE'), } self.command.git_cl = MockGitCL(self.tool, builds) git = MockGit(filesystem=self.tool.filesystem, executive=self.tool.executive) git.changed_files = lambda **_: [ RELATIVE_WEB_TESTS + 'one/text-fail.html', RELATIVE_WEB_TESTS + 'one/flaky-fail.html', ] self.tool.git = lambda: git self.tool.builders = BuilderList({ 'MOCK Try Win': { 'port_name': 'test-win-win7', 'specifiers': ['Win7', 'Release'], 'is_try_builder': True, }, 'MOCK Try Linux': { 'port_name': 'test-linux-trusty', 'specifiers': ['Trusty', 'Release'], 'is_try_builder': True, }, 'MOCK Try Mac': { 'port_name': 'test-mac-mac10.11', 'specifiers': ['Mac10.11', 'Release'], 'is_try_builder': True, }, }) web_test_results = WebTestResults({ 'tests': { 'one': { 'crash.html': { 'expected': 'PASS', 'actual': 'CRASH', 'is_unexpected': True, 'artifacts': { 'crash_log': ['crash.log'] } }, 'expected-fail.html': { 'expected': 'FAIL', 'actual': 'FAIL', 'artifacts': { 'expected_text': ['expected-fail-expected.txt'], 'actual_text': ['expected-fail-actual.txt'] } }, 'flaky-fail.html': { 'expected': 'PASS', 'actual': 'PASS FAIL', 'is_unexpected': True, 'artifacts': { 'expected_audio': ['flaky-fail-expected.wav'], 'actual_audio': ['flaky-fail-actual.wav'] } }, 'missing.html': { 'expected': 'PASS', 'actual': 'FAIL', 'is_unexpected': True, 'artifacts': { 'actual_image': ['missing-actual.png'] }, 'is_missing_image': True }, 'slow-fail.html': { 'expected': 'SLOW', 'actual': 'FAIL', 'is_unexpected': True, 'artifacts': { 'actual_text': ['slow-fail-actual.txt'], 'expected_text': ['slow-fail-expected.txt'] } }, 'text-fail.html': { 'expected': 'PASS', 'actual': 'FAIL', 'is_unexpected': True, 'artifacts': { 'actual_text': ['text-fail-actual.txt'], 'expected_text': ['text-fail-expected.txt'] } }, 'unexpected-pass.html': { 'expected': 'FAIL', 'actual': 'PASS', 'is_unexpected': True }, }, 'two': { 'image-fail.html': { 'expected': 'PASS', 'actual': 'FAIL', 'is_unexpected': True, 'artifacts': { 'actual_image': ['image-fail-actual.png'], 'expected_image': ['image-fail-expected.png'] } } }, }, }) for build in builds: self.tool.results_fetcher.set_results(build, web_test_results) self.tool.results_fetcher.set_retry_sumary_json( build, json.dumps({ 'failures': [ 'one/flaky-fail.html', 'one/missing.html', 'one/slow-fail.html', 'one/text-fail.html', 'two/image-fail.html', ], 'ignored': [], })) # Write to the mock filesystem so that these tests are considered to exist. tests = [ 'one/flaky-fail.html', 'one/missing.html', 'one/slow-fail.html', 'one/text-fail.html', 'two/image-fail.html', ] for test in tests: path = self.mac_port.host.filesystem.join( self.mac_port.web_tests_dir(), test) self._write(path, 'contents') self.mac_port.host.filesystem.write_text_file( '/test.checkout/web_tests/external/wpt/MANIFEST.json', '{}')
def setUp(self): BaseTestCase.setUp(self) LoggingTestCase.setUp(self) builds = { Build('MOCK Try Win', 5000): TryJobStatus('COMPLETED', 'FAILURE'), Build('MOCK Try Mac', 4000): TryJobStatus('COMPLETED', 'FAILURE'), Build('MOCK Try Linux', 6000): TryJobStatus('COMPLETED', 'FAILURE'), } self.command.git_cl = MockGitCL(self.tool, builds) git = MockGit(filesystem=self.tool.filesystem, executive=self.tool.executive) git.changed_files = lambda **_: [ 'third_party/WebKit/LayoutTests/one/text-fail.html', 'third_party/WebKit/LayoutTests/one/flaky-fail.html', ] self.tool.git = lambda: git self.tool.builders = BuilderList({ 'MOCK Try Win': { 'port_name': 'test-win-win7', 'specifiers': ['Win7', 'Release'], 'is_try_builder': True, }, 'MOCK Try Linux': { 'port_name': 'test-linux-trusty', 'specifiers': ['Trusty', 'Release'], 'is_try_builder': True, }, 'MOCK Try Mac': { 'port_name': 'test-mac-mac10.11', 'specifiers': ['Mac10.11', 'Release'], 'is_try_builder': True, }, }) layout_test_results = LayoutTestResults({ 'tests': { 'one': { 'crash.html': { 'expected': 'PASS', 'actual': 'CRASH', 'is_unexpected': True }, 'expected-fail.html': { 'expected': 'FAIL', 'actual': 'IMAGE+TEXT' }, 'flaky-fail.html': { 'expected': 'PASS', 'actual': 'PASS TEXT', 'is_unexpected': True }, 'missing.html': { 'expected': 'PASS', 'actual': 'MISSING', 'is_unexpected': True }, 'slow-fail.html': { 'expected': 'SLOW', 'actual': 'TEXT', 'is_unexpected': True }, 'text-fail.html': { 'expected': 'PASS', 'actual': 'TEXT', 'is_unexpected': True }, 'unexpected-pass.html': { 'expected': 'FAIL', 'actual': 'PASS', 'is_unexpected': True }, }, 'two': { 'image-fail.html': { 'expected': 'PASS', 'actual': 'IMAGE', 'is_unexpected': True } }, }, }) for build in builds: self.tool.buildbot.set_results(build, layout_test_results) self.tool.buildbot.set_retry_sumary_json( build, json.dumps({ 'failures': [ 'one/flaky-fail.html', 'one/missing.html', 'one/slow-fail.html', 'one/text-fail.html', 'two/image-fail.html', ], 'ignored': [], })) # Write to the mock filesystem so that these tests are considered to exist. tests = [ 'one/flaky-fail.html', 'one/missing.html', 'one/slow-fail.html', 'one/text-fail.html', 'two/image-fail.html', ] for test in tests: path = self.mac_port.host.filesystem.join( self.mac_port.layout_tests_dir(), test) self._write(path, 'contents') self.mac_port.host.filesystem.write_text_file( '/test.checkout/LayoutTests/external/wpt/MANIFEST.json', '{}')