def testCmp(self): gs_path = 'gs://bucket/some/path' local_path = '/some/local/path' http_path = 'http://host.domain/some/path' result = 'TheResult' self.mox.StubOutWithMock(gslib, 'Cmp') self.mox.StubOutWithMock(filelib, 'Cmp') # Set up the test replay script. # Run 1, two local files. filelib.Cmp(local_path, local_path + '.1').AndReturn(result) # Run 2, local and GS. gslib.Cmp(local_path, gs_path).AndReturn(result) # Run 4, GS and GS gslib.Cmp(gs_path, gs_path + '.1').AndReturn(result) # Run 7, local and HTTP self.mox.ReplayAll() # Run the test verification. self.assertEquals(result, urilib.Cmp(local_path, local_path + '.1')) self.assertEquals(result, urilib.Cmp(local_path, gs_path)) self.assertEquals(result, urilib.Cmp(gs_path, gs_path + '.1')) self.assertRaises(urilib.NotSupportedBetweenTypes, urilib.Cmp, local_path, http_path) self.mox.VerifyAll()
def Cmp(uri1, uri2): """Return True if paths hold identical files. If either file is missing then always return False. Args: uri1: URI to a file. uri2: URI to a file. Returns: True if files are the same, False otherwise. Raises: NotSupportedBetweenTypes if Cmp cannot be done between the two URIs provided. """ uri_type1 = GetUriType(uri1) uri_type2 = GetUriType(uri2) uri_types = set([uri_type1, uri_type2]) if TYPE_GS in uri_types: # GS only supported between other GS files or local files. if len(uri_types) == 1 or TYPE_LOCAL in uri_types: return gslib.Cmp(uri1, uri2) if TYPE_LOCAL in uri_types and len(uri_types) == 1: return filelib.Cmp(uri1, uri2) raise NotSupportedBetweenTypes(uri_type1, uri_type2)
def testCmp(self): uri1 = 'gs://some/gs/path' uri2 = 'gs://some/other/path' local_path = '/some/local/path' md5 = 'TheMD5Sum' self.mox.StubOutWithMock(gslib, 'MD5Sum') self.mox.StubOutWithMock(gslib.filelib, 'MD5Sum') # Set up the test replay script. # Run 1, same md5, both GS. gslib.MD5Sum(uri1).AndReturn(md5) gslib.MD5Sum(uri2).AndReturn(md5) # Run 2, different md5, both GS. gslib.MD5Sum(uri1).AndReturn(md5) gslib.MD5Sum(uri2).AndReturn('Other' + md5) # Run 3, same md5, one GS on local. gslib.MD5Sum(uri1).AndReturn(md5) gslib.filelib.MD5Sum(local_path).AndReturn(md5) # Run 4, different md5, one GS on local. gslib.MD5Sum(uri1).AndReturn(md5) gslib.filelib.MD5Sum(local_path).AndReturn('Other' + md5) # Run 5, missing file, both GS. gslib.MD5Sum(uri1).AndReturn(None) # Run 6, args are None. gslib.filelib.MD5Sum(None).AndReturn(None) self.mox.ReplayAll() # Run the test verification. self.assertTrue(gslib.Cmp(uri1, uri2)) self.assertFalse(gslib.Cmp(uri1, uri2)) self.assertTrue(gslib.Cmp(uri1, local_path)) self.assertFalse(gslib.Cmp(uri1, local_path)) self.assertFalse(gslib.Cmp(uri1, uri2)) self.assertFalse(gslib.Cmp(None, None)) self.mox.VerifyAll()