<commit_before>#!/usr/bin/env python
# coding=utf8

import ConfigParser
import os
import random
import sys

if sys.version_info < (2, 7):
    import unittest2 as unittest
else:
    import unittest

from . import SimpleUrlKVTest

skip_reason = None

# read s3 config
conffile = os.path.expanduser('~/.simplekv-test.boto')
s3conf = ConfigParser.RawConfigParser()
if not s3conf.read(conffile):
    skip_reason = 'No S3 test configuration supplied. If you wish to '\
        'test the S3 backend, create a file called %r with your '\
        'credentials first. See the simplekv.net.s3 documentation '\
        'for details.' % conffile

try:
    from boto.s3.connection import S3Connection
    from boto.exception import S3ResponseError
    from simplekv.net.s3 import S3Store
except ImportError:
    skip_reason = 'boto not installed'


class S3BucketManager(object):
    def create_bucket(self, name=None):
        conn = S3Connection(s3conf.get('s3', 'access_key'),
                            s3conf.get('s3', 'secret_key'))

        name = name or 'simplekv-unittest-%x' %\
            random.SystemRandom().getrandbits(64)

        bucket = conn.create_bucket(name)

        return bucket

    def drop_bucket(self, bucket):
        for key in bucket.list():
            key.delete()
        bucket.delete()

    # context manager for an s3 bucket
    def __enter__(self):
        self.bucket = self.create_bucket()
        return self.bucket<commit_msg>Do not mask other ImportErrors when importing boto in test suite.<commit_after>#!/usr/bin/env python
# coding=utf8

import ConfigParser
import os
import random
import sys

if sys.version_info < (2, 7):
    import unittest2 as unittest
else:
    import unittest

from . import SimpleUrlKVTest

skip_reason = None

# read s3 config
conffile = os.path.expanduser('~/.simplekv-test.boto')
s3conf = ConfigParser.RawConfigParser()
if not s3conf.read(conffile):
    skip_reason = 'No S3 test configuration supplied. If you wish to '\
        'test the S3 backend, create a file called %r with your '\
        'credentials first. See the simplekv.net.s3 documentation '\
        'for details.' % conffile

try:
    from boto.s3.connection import S3Connection
    from boto.exception import S3ResponseError
except ImportError:
    skip_reason = 'boto not installed'

if not skip_reason:
    from simplekv.net.s3 import S3Store


class S3BucketManager(object):
    def create_bucket(self, name=None):
        conn = S3Connection(s3conf.get('s3', 'access_key'),
                            s3conf.get('s3', 'secret_key'))

        name = name or 'simplekv-unittest-%x' %\
            random.SystemRandom().getrandbits(64)

        bucket = conn.create_bucket(name)

        return bucket

    def drop_bucket(self, bucket):
        for key in bucket.list():
            key.delete()
        bucket.delete()

    # context manager for an s3 bucket
    def __enter__(self):
        self.bucket = self.create_bucket()
        return self.bucket
{'fraction_non_alphanumeric': 0.09440910612654838, 'fraction_numerical': 0.016069635085369936, 'mean_word_length': 2.840616966580977, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6772784', 'n_tokens_mistral': 920, 'n_tokens_neox': 900, 'n_words': 264}