def test_initializeSkiaGoldAttributes_tryjobArgsIgnoredWithoutRevision( self): args = createSkiaGoldArgs(gerrit_issue=1, gerrit_patchset=2, buildbucket_id=3) sgp = skia_gold_properties.SkiaGoldProperties(args) self.verifySkiaGoldProperties(sgp, {})
def testIsTryjobRun_issue(self): args = createSkiaGoldArgs(git_revision='a', gerrit_issue=1, gerrit_patchset=2, buildbucket_id=3) sgp = skia_gold_properties.SkiaGoldProperties(args) self.assertTrue(sgp.IsTryjobRun())
def test_commandWithUseLuciFalseNotLocal(self, cmd_mock): cmd_mock.return_value = (None, None) args = createSkiaGoldArgs(git_revision='a', local_pixel_tests=False) sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, None, None, None) with self.assertRaises(RuntimeError): session.Authenticate(use_luci=False)
def test_commandWithUseLuciFalse(self, cmd_mock): cmd_mock.return_value = (None, None) args = createSkiaGoldArgs(git_revision='a', local_pixel_tests=True) sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, None, None, None) session.Authenticate(use_luci=False) self.assertNotIn('--luci', cmd_mock.call_args[0][0])
def test_commandWithLocalPixelTestsFalse(self, cmd_mock): cmd_mock.return_value = (None, None) args = createSkiaGoldArgs(git_revision='a', local_pixel_tests=False) sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, None, None, None) session.Compare(None, None) self.assertNotIn('--dryrun', cmd_mock.call_args[0][0])
def test_corpusDefaultsToInstance(self): args = createSkiaGoldArgs() sgp = skia_gold_properties.SkiaGoldProperties(args) sgsm = skia_gold_session_manager.SkiaGoldSessionManager( self._working_dir, sgp) session = sgsm.GetSkiaGoldSession({}, None, 'instance') self.assertTrue(session._keys_file.startswith(self._working_dir)) self.assertEqual(session._corpus, 'instance') self.assertEqual(session._instance, 'instance')
def test_bypassSkiaGoldFunctionality(self, cmd_mock): cmd_mock.return_value = (None, None) args = createSkiaGoldArgs(git_revision='a', bypass_skia_gold_functionality=True) sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, None, None, None) with self.assertRaises(RuntimeError): session.Diff(None, None)
def testGetGitRevision_findMalformedRevision(self): args = createSkiaGoldArgs(local_pixel_tests=True) sgp = skia_gold_properties.SkiaGoldProperties(args) with mock.patch( 'gpu_tests.skia_gold.skia_gold_properties._GetGitOriginMasterHeadSha1' ) as patched_head: patched_head.return_value = 'a' * 39 with self.assertRaises(RuntimeError): _ = sgp.git_revision
def test_corpusFromJson(self): args = createSkiaGoldArgs() sgp = skia_gold_properties.SkiaGoldProperties(args) sgsm = skia_gold_session_manager.SkiaGoldSessionManager( self._working_dir, sgp) session = sgsm.GetSkiaGoldSession({'source_type': 'foobar'}, None, 'instance') self.assertTrue(session._keys_file.startswith(self._working_dir)) self.assertEqual(session._corpus, 'foobar') self.assertEqual(session._instance, 'instance')
def test_bypassSkiaGoldFunctionality(self, cmd_mock): cmd_mock.return_value = (None, None) args = createSkiaGoldArgs(git_revision='a', bypass_skia_gold_functionality=True) sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, None, None, None) rc, _ = session.Compare(None, None) self.assertEqual(rc, 0) cmd_mock.assert_not_called()
def test_separateSessionsFromCorpus(self, session_mock): session_mock.return_value = None args = createSkiaGoldArgs() sgp = skia_gold_properties.SkiaGoldProperties(args) sgsm = skia_gold_session_manager.SkiaGoldSessionManager( self._working_dir, sgp) session1 = sgsm.GetSkiaGoldSession({}, 'corpus1', 'instance') session2 = sgsm.GetSkiaGoldSession({}, 'corpus2', 'instance') self.assertNotEqual(session1, session2) self.assertEqual(session_mock.call_count, 2)
def test_commandOutputReturned(self, cmd_mock): cmd_mock.return_value = (1, 'Something bad :(') args = createSkiaGoldArgs(git_revision='a', local_pixel_tests=False) sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, None, None, None) rc, stdout = session.Diff(None, None) self.assertEqual(cmd_mock.call_count, 1) self.assertEqual(rc, 1) self.assertEqual(stdout, 'Something bad :(')
def test_shortCircuitAlreadyInitialized(self, cmd_mock): cmd_mock.return_value = (None, None) args = createSkiaGoldArgs(git_revision='a') sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, None, None, None) session._initialized = True rc, _ = session.Initialize() self.assertEqual(rc, 0) cmd_mock.assert_not_called()
def test_commandCommonArgs(self, cmd_mock): cmd_mock.return_value = (None, None) args = createSkiaGoldArgs(git_revision='a') sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, None, None, None) session.Authenticate() call_args = cmd_mock.call_args[0][0] self.assertIn('auth', call_args) assertArgWith(self, call_args, '--work-dir', self._working_dir)
def test_failureDoesNotSetShortCircuit(self, cmd_mock): cmd_mock.return_value = (1, None) args = createSkiaGoldArgs(git_revision='a') sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, None, None, None) self.assertFalse(session._initialized) rc, _ = session.Initialize() self.assertEqual(rc, 1) self.assertFalse(session._initialized) cmd_mock.assert_called_once()
def testGetGitRevision_findValidRevision(self): args = createSkiaGoldArgs(local_pixel_tests=True) sgp = skia_gold_properties.SkiaGoldProperties(args) with mock.patch( 'gpu_tests.skia_gold.skia_gold_properties._GetGitOriginMasterHeadSha1' ) as patched_head: expected = 'a' * 40 patched_head.return_value = expected self.assertEqual(sgp.git_revision, expected) # Should be cached. self.assertEqual(sgp._git_revision, expected)
def test_successSetsShortCircuit(self, cmd_mock): cmd_mock.return_value = (0, None) args = createSkiaGoldArgs(git_revision='a') sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, None, None, None) self.assertFalse(session._authenticated) rc, _ = session.Authenticate() self.assertEqual(rc, 0) self.assertTrue(session._authenticated) cmd_mock.assert_called_once()
def test_matchingSessionReused(self, session_mock): session_mock.return_value = None args = createSkiaGoldArgs() sgp = skia_gold_properties.SkiaGoldProperties(args) sgsm = skia_gold_session_manager.SkiaGoldSessionManager( self._working_dir, sgp) session1 = sgsm.GetSkiaGoldSession({}, 'corpus', 'instance') session2 = sgsm.GetSkiaGoldSession({}, 'corpus', 'instance') self.assertEqual(session1, session2) # For some reason, session_mock.assert_called_once() always passes, # so check the call count directly. self.assertEqual(session_mock.call_count, 1)
def test_noLinkOnSuccess(self, cmd_mock): cmd_mock.return_value = (0, None) args = createSkiaGoldArgs(git_revision='a') sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, 'keys_file', None, None) rc, _ = session.Compare('name', 'png_file') self.assertEqual(rc, 0) self.assertEqual(session._comparison_results['name'].triage_link, None) self.assertNotEqual( session._comparison_results['name'].triage_link_omission_reason, None)
def test_commandTryjobArgsMissing(self, cmd_mock): cmd_mock.return_value = (None, None) args = createSkiaGoldArgs(git_revision='a') sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, None, None, None) session.Initialize() call_args = cmd_mock.call_args[0][0] self.assertNotIn('--issue', call_args) self.assertNotIn('--patchset', call_args) self.assertNotIn('--jobid', call_args) self.assertNotIn('--crs', call_args) self.assertNotIn('--cis', call_args)
def test_initializeSkiaGoldAttributes_tryjobArgs(self): args = createSkiaGoldArgs(git_revision='a', gerrit_issue=1, gerrit_patchset=2, buildbucket_id=3) sgp = skia_gold_properties.SkiaGoldProperties(args) self.verifySkiaGoldProperties( sgp, { 'git_revision': 'a', 'gerrit_issue': 1, 'gerrit_patchset': 2, 'buildbucket_id': 3 })
def test_ArgsForwardedToSession(self): args = createSkiaGoldArgs() sgp = skia_gold_properties.SkiaGoldProperties(args) sgsm = skia_gold_session_manager.SkiaGoldSessionManager( self._working_dir, sgp) session = sgsm.GetSkiaGoldSession({}, 'corpus', 'instance') self.assertTrue(session._keys_file.startswith(self._working_dir)) self.assertEqual(session._corpus, 'corpus') self.assertEqual(session._instance, 'instance') # Make sure the session's working directory is a subdirectory of the # manager's working directory. self.assertEqual(os.path.dirname(session._working_dir), self._working_dir)
def test_commandCommonArgs(self, cmd_mock): cmd_mock.return_value = (None, None) args = createSkiaGoldArgs(git_revision='a') sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, 'keys_file', 'corpus', instance='instance') session.Compare('name', 'png_file') call_args = cmd_mock.call_args[0][0] self.assertIn('imgtest', call_args) self.assertIn('add', call_args) assertArgWith(self, call_args, '--test-name', 'name') assertArgWith(self, call_args, '--png-file', 'png_file') assertArgWith(self, call_args, '--work-dir', self._working_dir)
def test_commandTryjobArgs(self, cmd_mock): cmd_mock.return_value = (None, None) args = createSkiaGoldArgs(git_revision='a', gerrit_issue=1, gerrit_patchset=2, buildbucket_id=3) sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, None, None, None) session.Initialize() call_args = cmd_mock.call_args[0][0] assertArgWith(self, call_args, '--issue', '1') assertArgWith(self, call_args, '--patchset', '2') assertArgWith(self, call_args, '--jobid', '3') assertArgWith(self, call_args, '--crs', 'gerrit') assertArgWith(self, call_args, '--cis', 'buildbucket')
def test_clLinkOnTrybot(self, cmd_mock): cmd_mock.return_value = (1, None) args = createSkiaGoldArgs(git_revision='a', gerrit_issue=1, gerrit_patchset=2, buildbucket_id=3) sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, 'keys_file', None, None) rc, _ = session.Compare('name', 'png_file') self.assertEqual(rc, 1) self.assertNotEqual(session._comparison_results['name'].triage_link, None) self.assertIn('issue=1', session._comparison_results['name'].triage_link) self.assertEqual( session._comparison_results['name'].triage_link_omission_reason, None)
def test_commandCommonArgs(self, cmd_mock): cmd_mock.return_value = (None, None) args = createSkiaGoldArgs(git_revision='a') sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, 'keys_file', 'corpus', instance='instance') session.Initialize() call_args = cmd_mock.call_args[0][0] self.assertIn('imgtest', call_args) self.assertIn('init', call_args) self.assertIn('--passfail', call_args) assertArgWith(self, call_args, '--instance', 'instance') assertArgWith(self, call_args, '--corpus', 'corpus') assertArgWith(self, call_args, '--keys-file', 'keys_file') assertArgWith(self, call_args, '--work-dir', self._working_dir) assertArgWith(self, call_args, '--failure-file', session._triage_link_file) assertArgWith(self, call_args, '--commit', 'a')
def test_compareFailureRemote(self, auth_mock, init_mock, compare_mock, diff_mock): auth_mock.return_value = (0, None) init_mock.return_value = (0, None) compare_mock.return_value = (1, 'Compare failed') args = createSkiaGoldArgs(local_pixel_tests=False) sgp = skia_gold_properties.SkiaGoldProperties(args) keys_file = os.path.join(self._working_dir, 'keys.json') with open(os.path.join(self._working_dir, 'keys.json'), 'w') as f: json.dump({}, f) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, keys_file, None, None) status, error = session.RunComparison(None, None, None) self.assertEqual( status, skia_gold_session.SkiaGoldSession.StatusCodes. COMPARISON_FAILURE_REMOTE) self.assertEqual(error, 'Compare failed') self.assertEqual(auth_mock.call_count, 1) self.assertEqual(init_mock.call_count, 1) self.assertEqual(compare_mock.call_count, 1) self.assertEqual(diff_mock.call_count, 0)
def test_commandCommonArgs(self, cmd_mock): cmd_mock.return_value = (None, None) args = createSkiaGoldArgs(git_revision='a', local_pixel_tests=False) sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, None, 'corpus', instance='instance') session.Diff('name', 'png_file') call_args = cmd_mock.call_args[0][0] self.assertIn('diff', call_args) assertArgWith(self, call_args, '--corpus', 'corpus') assertArgWith(self, call_args, '--instance', 'instance') assertArgWith(self, call_args, '--input', 'png_file') assertArgWith(self, call_args, '--test', 'name') assertArgWith(self, call_args, '--work-dir', self._working_dir) i = call_args.index('--out-dir') # The output directory should not be a subdirectory of the working # directory. self.assertNotIn(self._working_dir, call_args[i + 1])
def test_individualLinkOnCi(self, cmd_mock): args = createSkiaGoldArgs(git_revision='a') sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, 'keys_file', None, None) def WriteTriageLinkFile(_): with open(session._triage_link_file, 'w') as f: f.write('foobar') return (1, None) cmd_mock.side_effect = WriteTriageLinkFile rc, _ = session.Compare('name', 'png_file') self.assertEqual(rc, 1) self.assertNotEqual(session._comparison_results['name'].triage_link, None) self.assertEqual(session._comparison_results['name'].triage_link, 'foobar') self.assertEqual( session._comparison_results['name'].triage_link_omission_reason, None)
def test_validOmissionOnIoError(self, cmd_mock): cmd_mock.return_value = (1, None) args = createSkiaGoldArgs(git_revision='a') sgp = skia_gold_properties.SkiaGoldProperties(args) session = skia_gold_session.SkiaGoldSession(self._working_dir, sgp, 'keys_file', None, None) def DeleteTriageLinkFile(_): os.remove(session._triage_link_file) return (1, None) cmd_mock.side_effect = DeleteTriageLinkFile rc, _ = session.Compare('name', 'png_file') self.assertEqual(rc, 1) self.assertEqual(session._comparison_results['name'].triage_link, None) self.assertNotEqual( session._comparison_results['name'].triage_link_omission_reason, None) self.assertIn( 'Failed to read', session._comparison_results['name'].triage_link_omission_reason)