from __future__ import absolute_import
from __future__ import unicode_literals
import codecs
import contextlib
import functools
import os


class Env(object):

    def __init__(self):
        self.user = os.getenv('AWS_ACCESS_KEY_ID', None)
        assert self.user, \
            'Required environment variable `AWS_ACCESS_KEY_ID` not found.'
        self.password = os.getenv('AWS_SECRET_ACCESS_KEY', None)
        assert self.password, \
            'Required environment variable `AWS_SECRET_ACCESS_KEY` not found.'
        self.region_name = os.getenv('AWS_DEFAULT_REGION', None)
        assert self.region_name, \
            'Required environment variable `AWS_DEFAULT_REGION` not found.'
        self.s3_staging_dir = os.getenv('AWS_ATHENA_S3_STAGING_DIR', None)
        assert self.s3_staging_dir, \
            'Required environment variable `AWS_ATHENA_S3_STAGING_DIR` not found.'


def with_cursor(fn):
    @functools.wraps(fn)
    def wrapped_fn(self, *args, **kwargs):
        with contextlib.closing(self.connect()) as conn:
            with conn.cursor() as cursor:
                fn(self, cursor, *args, **kwargs)
    return wrapped_fn


def read_query(path):
    with codecs.open(path, 'rb', 'utf-8') as f:
        query = f.read()
    return [q.strip() for q in query.split(';') if q and q.strip()]

from __future__ import absolute_import
from __future__ import unicode_literals
import codecs
import contextlib
import functools
import os


class Env(object):

    def __init__(self):
        # self.user = os.getenv('AWS_ACCESS_KEY_ID', None)
        # assert self.user, \
        #     'Required environment variable `AWS_ACCESS_KEY_ID` not found.'
        # self.password = os.getenv('AWS_SECRET_ACCESS_KEY', None)
        # assert self.password, \
        #     'Required environment variable `AWS_SECRET_ACCESS_KEY` not found.'
        self.region_name = os.getenv('AWS_DEFAULT_REGION', None)
        assert self.region_name, \
            'Required environment variable `AWS_DEFAULT_REGION` not found.'
        self.s3_staging_dir = os.getenv('AWS_ATHENA_S3_STAGING_DIR', None)
        assert self.s3_staging_dir, \
            'Required environment variable `AWS_ATHENA_S3_STAGING_DIR` not found.'


def with_cursor(fn):
    @functools.wraps(fn)
    def wrapped_fn(self, *args, **kwargs):
        with contextlib.closing(self.connect()) as conn:
            with conn.cursor() as cursor:
                fn(self, cursor, *args, **kwargs)
    return wrapped_fn


def read_query(path):
    with codecs.open(path, 'rb', 'utf-8') as f:
        query = f.read()
    return [q.strip() for q in query.split(';') if q and q.strip()]

Comment out assertion of environment variables(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY). When test fail, all environment variables appear in the error log in some case. Use credential file(~/.aws/credential) configuration for testing.
Comment out assertion of environment variables(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY).
When test fail, all environment variables appear in the error log in some case.
Use credential file(~/.aws/credential) configuration for testing.

  from __future__ import absolute_import
  from __future__ import unicode_literals
  import codecs
  import contextlib
  import functools
  import os
  
  
  class Env(object):
  
      def __init__(self):
-         self.user = os.getenv('AWS_ACCESS_KEY_ID', None)
+         # self.user = os.getenv('AWS_ACCESS_KEY_ID', None)
-         assert self.user, \
+         # assert self.user, \
-             'Required environment variable `AWS_ACCESS_KEY_ID` not found.'
+         #     'Required environment variable `AWS_ACCESS_KEY_ID` not found.'
-         self.password = os.getenv('AWS_SECRET_ACCESS_KEY', None)
+         # self.password = os.getenv('AWS_SECRET_ACCESS_KEY', None)
-         assert self.password, \
+         # assert self.password, \
-             'Required environment variable `AWS_SECRET_ACCESS_KEY` not found.'
+         #     'Required environment variable `AWS_SECRET_ACCESS_KEY` not found.'
          self.region_name = os.getenv('AWS_DEFAULT_REGION', None)
          assert self.region_name, \
              'Required environment variable `AWS_DEFAULT_REGION` not found.'
          self.s3_staging_dir = os.getenv('AWS_ATHENA_S3_STAGING_DIR', None)
          assert self.s3_staging_dir, \
              'Required environment variable `AWS_ATHENA_S3_STAGING_DIR` not found.'
  
  
  def with_cursor(fn):
      @functools.wraps(fn)
      def wrapped_fn(self, *args, **kwargs):
          with contextlib.closing(self.connect()) as conn:
              with conn.cursor() as cursor:
                  fn(self, cursor, *args, **kwargs)
      return wrapped_fn
  
  
  def read_query(path):
      with codecs.open(path, 'rb', 'utf-8') as f:
          query = f.read()
      return [q.strip() for q in query.split(';') if q and q.strip()]
  
Comment out assertion of environment variables(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY). When test fail, all environment variables appear in the error log in some case. Use credential file(~/.aws/credential) configuration for testing.
## Code Before:
from __future__ import absolute_import
from __future__ import unicode_literals
import codecs
import contextlib
import functools
import os


class Env(object):

    def __init__(self):
        self.user = os.getenv('AWS_ACCESS_KEY_ID', None)
        assert self.user, \
            'Required environment variable `AWS_ACCESS_KEY_ID` not found.'
        self.password = os.getenv('AWS_SECRET_ACCESS_KEY', None)
        assert self.password, \
            'Required environment variable `AWS_SECRET_ACCESS_KEY` not found.'
        self.region_name = os.getenv('AWS_DEFAULT_REGION', None)
        assert self.region_name, \
            'Required environment variable `AWS_DEFAULT_REGION` not found.'
        self.s3_staging_dir = os.getenv('AWS_ATHENA_S3_STAGING_DIR', None)
        assert self.s3_staging_dir, \
            'Required environment variable `AWS_ATHENA_S3_STAGING_DIR` not found.'


def with_cursor(fn):
    @functools.wraps(fn)
    def wrapped_fn(self, *args, **kwargs):
        with contextlib.closing(self.connect()) as conn:
            with conn.cursor() as cursor:
                fn(self, cursor, *args, **kwargs)
    return wrapped_fn


def read_query(path):
    with codecs.open(path, 'rb', 'utf-8') as f:
        query = f.read()
    return [q.strip() for q in query.split(';') if q and q.strip()]

## Instruction:
Comment out assertion of environment variables(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY). When test fail, all environment variables appear in the error log in some case. Use credential file(~/.aws/credential) configuration for testing.
## Code After:
from __future__ import absolute_import
from __future__ import unicode_literals
import codecs
import contextlib
import functools
import os


class Env(object):

    def __init__(self):
        # self.user = os.getenv('AWS_ACCESS_KEY_ID', None)
        # assert self.user, \
        #     'Required environment variable `AWS_ACCESS_KEY_ID` not found.'
        # self.password = os.getenv('AWS_SECRET_ACCESS_KEY', None)
        # assert self.password, \
        #     'Required environment variable `AWS_SECRET_ACCESS_KEY` not found.'
        self.region_name = os.getenv('AWS_DEFAULT_REGION', None)
        assert self.region_name, \
            'Required environment variable `AWS_DEFAULT_REGION` not found.'
        self.s3_staging_dir = os.getenv('AWS_ATHENA_S3_STAGING_DIR', None)
        assert self.s3_staging_dir, \
            'Required environment variable `AWS_ATHENA_S3_STAGING_DIR` not found.'


def with_cursor(fn):
    @functools.wraps(fn)
    def wrapped_fn(self, *args, **kwargs):
        with contextlib.closing(self.connect()) as conn:
            with conn.cursor() as cursor:
                fn(self, cursor, *args, **kwargs)
    return wrapped_fn


def read_query(path):
    with codecs.open(path, 'rb', 'utf-8') as f:
        query = f.read()
    return [q.strip() for q in query.split(';') if q and q.strip()]
