def testRevertDirectory(self): options = self.Options(verbose=True) gclient_scm.os.path.isdir(self.base_path).AndReturn(True) gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(True) items = [ ('~ ', 'a'), ] gclient_scm.scm.SVN.CaptureStatus( None, self.base_path, no_ignore=False).AndReturn(items) file_path = join(self.base_path, 'a') gclient_scm.os.path.exists(file_path).AndReturn(True) gclient_scm.os.path.isfile(file_path).AndReturn(False) gclient_scm.os.path.islink(file_path).AndReturn(False) gclient_scm.os.path.isdir(file_path).AndReturn(True) gclient_scm.gclient_utils.rmtree(file_path) gclient_scm.os.path.isdir(self.base_path).AndReturn(True) gclient_scm.scm.SVN.RunAndGetFileList( options.verbose, ['update', '--revision', 'BASE', '--ignore-externals'], cwd=self.base_path, file_list=mox.IgnoreArg()) self.mox.ReplayAll() scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list2 = [] scm.revert(options, self.args, file_list2) self.checkstdout(('%s\n' % file_path))
def testRevinfo(self): """Checks that revinfo uses the JSON from cipd describe.""" scm = self.createScmWithPackageThatSatisfies(lambda _: True) expected_revinfo = '0123456789abcdef0123456789abcdef01234567' json_contents = { 'result': { 'pin': { 'instance_id': expected_revinfo, } } } describe_json_path = join(self._workdir, 'describe.json') with open(describe_json_path, 'w') as describe_json: json.dump(json_contents, describe_json) cmd = [ 'cipd', 'describe', 'foo_package', '-log-level', 'error', '-version', 'foo_version', '-json-output', describe_json_path, ] self.mox.StubOutWithMock(tempfile, 'mkdtemp') tempfile.mkdtemp().AndReturn(self._workdir) gclient_scm.gclient_utils.CheckCallAndFilter( cmd, filter_fn=mox.IgnoreArg(), print_stdout=False) gclient_scm.gclient_utils.rmtree(self._workdir) self.mox.ReplayAll() revinfo = scm.revinfo(None, (), []) self.assertEquals(revinfo, expected_revinfo)
def test_get_swarm_results_success(self): self.mox.StubOutWithMock(swarm_results.urllib2, 'urlopen') shard_output = json.dumps( {'hostname': 'host', 'exit_codes': '0, 0', 'output': SWARM_OUTPUT_WITHOUT_FAILURE } ) url_response = urllib2.addinfourl(StringIO.StringIO(shard_output), "mock message", 'host') url_response.code = 200 url_response.msg = "OK" swarm_results.urllib2.urlopen('http://host:9001/get_result?r=key1' ).AndReturn(url_response) swarm_results.urllib2.urlopen('http://host:9001/cleanup_results', mox.IgnoreArg()) self.mox.ReplayAll() swarm_results.GetSwarmResults('http://host:9001', ['key1']) self.checkstdout(BUILDBOT_OUTPUT) self.mox.VerifyAll()
def test_find_keys(self): keys = ['key_1', 'key_2'] self.mox.StubOutWithMock(swarm_results.urllib2, 'urlopen') response = StringIO.StringIO('\n'.join(keys)) swarm_results.urllib2.urlopen(mox.IgnoreArg()).AndReturn( response) self.mox.ReplayAll() self.assertEqual(keys, swarm_results.GetTestKeys('http://host:9001', 'my_test')) self.mox.VerifyAll()
def test_no_keys(self): self.mox.StubOutWithMock(swarm_results.urllib2, 'urlopen') response = StringIO.StringIO('No matching Test Cases') swarm_results.urllib2.urlopen(mox.IgnoreArg()).AndReturn( response) self.mox.ReplayAll() self.assertEqual([], swarm_results.GetTestKeys('http://host:9001', 'my_test')) self.checkstdout('Error: Unable to find any tests with the name, ' 'my_test, on swarm server\n') self.mox.VerifyAll()
def testRevertNone(self): options = self.Options(verbose=True) gclient_scm.os.path.isdir(self.base_path).AndReturn(True) gclient_scm.os.path.isdir(join(self.base_path, '.svn')).AndReturn(True) gclient_scm.scm.SVN.CaptureStatus(None, self.base_path).AndReturn([]) gclient_scm.os.path.isdir(self.base_path).AndReturn(True) gclient_scm.scm.SVN.RunAndGetFileList( options.verbose, ['update', '--revision', 'BASE', '--ignore-externals'], cwd=self.base_path, file_list=mox.IgnoreArg()) self.mox.ReplayAll() scm = self._scm_wrapper(url=self.url, root_dir=self.root_dir, relpath=self.relpath) file_list = [] scm.revert(options, self.args, file_list)
def testLoadEmpty(self): self.mox.StubOutWithMock(gcl, 'GetCodeReviewSetting') gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') gcl.os.path.exists('bleeeh').AndReturn(True) gcl.gclient_utils.FileRead('bleeeh').AndReturn( gcl.ChangeInfo.SEPARATOR.join(["", "", ""])) gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('foo') # Does an upgrade. gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') gcl.gclient_utils.FileWrite('bleeeh', mox.IgnoreArg()) self.mox.ReplayAll() change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False) self.assertEquals(change_info.name, 'bleh') self.assertEquals(change_info.issue, 0) self.assertEquals(change_info.patchset, 0) self.assertEquals(change_info.description, "") self.assertEquals(change_info.GetFiles(), [])
def testLoadWithIssue(self): self.mox.StubOutWithMock(gcl, 'GetCodeReviewSetting') description = ["This is some description.", "force an extra separator."] gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') gcl.os.path.exists('bleeeh').AndReturn(True) gcl.gclient_utils.FileRead('bleeeh').AndReturn( gcl.ChangeInfo.SEPARATOR.join(["42, 53", "G b.cc"] + description)) gcl.GetCodeReviewSetting('CODE_REVIEW_SERVER').AndReturn('foo') # Does an upgrade. gcl.GetChangelistInfoFile('bleh').AndReturn('bleeeh') gcl.gclient_utils.FileWrite('bleeeh', mox.IgnoreArg()) self.mox.ReplayAll() change_info = gcl.ChangeInfo.Load('bleh', self.fake_root_dir, True, False) self.assertEquals(change_info.name, 'bleh') self.assertEquals(change_info.issue, 42) self.assertEquals(change_info.patchset, 53) self.assertEquals(change_info.description, gcl.ChangeInfo.SEPARATOR.join(description)) self.assertEquals(change_info.GetFiles(), [('G ', 'b.cc')])