# Path: gslib/exception.py
# NO_URLS_MATCHED_PREFIX = 'No URLs matched'
# NO_URLS_MATCHED_GENERIC = (NO_URLS_MATCHED_PREFIX +
#                            '. Do the files you\'re operating on exist?')
# NO_URLS_MATCHED_TARGET = NO_URLS_MATCHED_PREFIX + ': %s'
# class AbortException(StandardError):
# class CommandException(StandardError):
# class ControlCException(Exception):
# class GcloudStorageTranslationError(Exception):
# class HashMismatchException(Exception):
# class IamChOnResourceWithConditionsException(Exception):
# class InvalidUrlError(Exception):
# class ExternalBinaryError(Exception):
#   def __init__(self, reason):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, reason, informational=False):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
# 
# Path: gslib/tests/testcase/integration_testcase.py
# def SkipForGS(reason):
#   if not RUN_S3_TESTS:
#     return unittest.skip(reason)
#   else:
#     return lambda func: func
# 
# Path: gslib/tests/testcase/integration_testcase.py
# def SkipForJSON(reason):
#   if USING_JSON_API:
#     return unittest.skip(reason)
#   else:
#     return lambda func: func
# 
# Path: gslib/tests/testcase/integration_testcase.py
# def SkipForXML(reason):
#   """Skips the test if running S3 tests, or if prefer_api isn't set to json."""
#   if not USING_JSON_API or RUN_S3_TESTS:
#     return unittest.skip(reason)
#   else:
#     return lambda func: func


import re
import gslib.tests.testcase as testcase
from gslib import exception
from gslib.tests.testcase.integration_testcase import SkipForGS
from gslib.tests.testcase.integration_testcase import SkipForJSON
from gslib.tests.testcase.integration_testcase import SkipForXML
from gslib.tests.util import ObjectToURI as suri
from gslib.tests.util import SetBotoConfigForTest
  def test_get_too_few_arguments_fails(self):
    with self.assertRaisesRegexp(exception.CommandException,
                                 'command requires at least'):
      self.RunCommand('autoclass', ['get'])

  def test_no_subcommand_fails(self):
    with self.assertRaisesRegexp(exception.CommandException,
                                 'command requires at least'):
      self.RunCommand('autoclass', [])

  def test_invalid_subcommand_fails(self):
    with self.assertRaisesRegexp(exception.CommandException,
                                 'Invalid subcommand'):
      self.RunCommand('autoclass', ['fakecommand', 'test'])

  def test_gets_multiple_buckets_with_wildcard(self):
    bucket_uri1 = self.CreateBucket(bucket_name='bucket1')
    bucket_uri2 = self.CreateBucket(bucket_name='bucket2')
    stdout = self.RunCommand('autoclass', ['get', 'gs://bucket*'],
                             return_stdout=True)
    self.assertIn(bucket_uri1.bucket_name, stdout)
    self.assertIn(bucket_uri2.bucket_name, stdout)


class TestAutoclassE2E(testcase.GsUtilIntegrationTestCase):
  """E2E tests for autoclass command."""

  _set_autoclass_cmd = ['autoclass', 'set']
  _get_autoclass_cmd = ['autoclass', 'get']


# Path: gslib/exception.py
# NO_URLS_MATCHED_PREFIX = 'No URLs matched'
# NO_URLS_MATCHED_GENERIC = (NO_URLS_MATCHED_PREFIX +
#                            '. Do the files you\'re operating on exist?')
# NO_URLS_MATCHED_TARGET = NO_URLS_MATCHED_PREFIX + ': %s'
# class AbortException(StandardError):
# class CommandException(StandardError):
# class ControlCException(Exception):
# class GcloudStorageTranslationError(Exception):
# class HashMismatchException(Exception):
# class IamChOnResourceWithConditionsException(Exception):
# class InvalidUrlError(Exception):
# class ExternalBinaryError(Exception):
#   def __init__(self, reason):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, reason, informational=False):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
#   def __str__(self):
#   def __init__(self, message):
#   def __repr__(self):
# 
# Path: gslib/tests/testcase/integration_testcase.py
# def SkipForGS(reason):
#   if not RUN_S3_TESTS:
#     return unittest.skip(reason)
#   else:
#     return lambda func: func
# 
# Path: gslib/tests/testcase/integration_testcase.py
# def SkipForJSON(reason):
#   if USING_JSON_API:
#     return unittest.skip(reason)
#   else:
#     return lambda func: func
# 
# Path: gslib/tests/testcase/integration_testcase.py
# def SkipForXML(reason):
#   """Skips the test if running S3 tests, or if prefer_api isn't set to json."""
#   if not USING_JSON_API or RUN_S3_TESTS:
#     return unittest.skip(reason)
#   else:
#     return lambda func: func


# Path: gslib/tests/test_autoclass.py
import re
import gslib.tests.testcase as testcase
from gslib import exception
from gslib.tests.testcase.integration_testcase import SkipForGS
from gslib.tests.testcase.integration_testcase import SkipForJSON
from gslib.tests.testcase.integration_testcase import SkipForXML
from gslib.tests.util import ObjectToURI as suri
from gslib.tests.util import SetBotoConfigForTest

  def test_get_too_few_arguments_fails(self):
    with self.assertRaisesRegexp(exception.CommandException,
                                 'command requires at least'):
      self.RunCommand('autoclass', ['get'])

  def test_no_subcommand_fails(self):
    with self.assertRaisesRegexp(exception.CommandException,
                                 'command requires at least'):
      self.RunCommand('autoclass', [])

  def test_invalid_subcommand_fails(self):
    with self.assertRaisesRegexp(exception.CommandException,
                                 'Invalid subcommand'):
      self.RunCommand('autoclass', ['fakecommand', 'test'])

  def test_gets_multiple_buckets_with_wildcard(self):
    bucket_uri1 = self.CreateBucket(bucket_name='bucket1')
    bucket_uri2 = self.CreateBucket(bucket_name='bucket2')
    stdout = self.RunCommand('autoclass', ['get', 'gs://bucket*'],
                             return_stdout=True)
    self.assertIn(bucket_uri1.bucket_name, stdout)
    self.assertIn(bucket_uri2.bucket_name, stdout)


class TestAutoclassE2E(testcase.GsUtilIntegrationTestCase):
  """E2E tests for autoclass command."""

  _set_autoclass_cmd = ['autoclass', 'set']
  _get_autoclass_cmd = ['autoclass', 'get']


  @SkipForXML('Autoclass only runs on GCS JSON API.')