def TestCallingGetKeyOnProviderOnlyWildcardIteration(self): """Tests that attempting iterating provider-only wildcard raises""" try: from gslib.bucket_listing_ref import BucketListingRefException for iter_result in wildcard_iterator.wildcard_iterator( 'gs://', ProjectIdHandler(), bucket_storage_uri_class=mock_storage_service.MockBucketStorageUri): iter_result.GetKey() self.fail('Expected BucketListingRefException not raised.') except BucketListingRefException, e: self.assertTrue(str(e).find( 'Attempt to call GetKey() on Key-less BucketListingRef') != -1)
def testCallingGetKeyOnProviderOnlyWildcardIteration(self): """Tests that attempting iterating provider-only wildcard raises""" try: from gslib.bucket_listing_ref import BucketListingRefException for iter_result in wildcard_iterator.wildcard_iterator( 'gs://', ProjectIdHandler(), bucket_storage_uri_class=self.mock_bucket_storage_uri): iter_result.GetKey() self.fail('Expected BucketListingRefException not raised.') except BucketListingRefException, e: self.assertTrue( str(e).find( 'Attempt to call GetKey() on Key-less BucketListingRef') != -1)
def _test_wildcard_iterator(cls, uri_or_str, debug=0): """ Convenience method for instantiating a testing instance of WildCardIterator, without having to specify all the params of that class (like bucket_storage_uri_class=mock_storage_service.MockBucketStorageUri). Also naming the factory method this way makes it clearer in the test code that WildcardIterator needs to be set up for testing. Args are same as for wildcard_iterator.wildcard_iterator(), except there's no bucket_storage_uri_class arg. Returns: WildcardIterator.IterUris(), over which caller can iterate. """ return wildcard_iterator.wildcard_iterator( uri_or_str, cls.proj_id_handler, cls.mock_bucket_storage_uri, debug=debug )
def _test_wildcard_iterator(cls, uri_or_str, debug=0): """ Convenience method for instantiating a testing instance of WildCardIterator, without having to specify all the params of that class (like bucket_storage_uri_class=mock_storage_service.MockBucketStorageUri). Also naming the factory method this way makes it clearer in the test code that WildcardIterator needs to be set up for testing. Args are same as for wildcard_iterator.wildcard_iterator(), except there's no bucket_storage_uri_class arg. Returns: WildcardIterator.IterUris(), over which caller can iterate. """ return wildcard_iterator.wildcard_iterator( uri_or_str, cls.proj_id_handler, cls.mock_bucket_storage_uri, debug=debug)