# Path: pyemc/abstractions/test_api.py
# class TestCase(object):
#     def __init__(self, id):
#         self.id = id
# 
#     def set_up(self, client_params):
#         '''Subclasses should implement both set_up and get_client so the runner
#         can get access to the client.'''
#         self.client = client_params.create_client()
# 
#     def get_client(self):
#         return self.client
# 
#     @contextmanager
#     def assert_raises(self, exc_class):
#         raised = False
#         try:
#             yield
# 
#         except exc_class:
#             raised = True
# 
#         if not raised:
#             raise AssertionError("%s not raised" % exc_class.__name__)
# 
#     def write(self, msg):
#         msg = '[test%s] %s' % (self.id, msg)
#         write(msg)
# 
# Path: pyemc/client.py
# class ClientError(Exception):
#     pass
# 
# Path: pyemc/client.py
# class DeleteFailedError(Exception):
#     pass
# 
# Path: pyemc/client.py
# class ExistsError(Exception):
#     pass
# 
# Path: pyemc/client.py
# class NotFoundError(Exception):
#     pass
# 
# Path: pyemc/client.py
# class NotStoredError(Exception):
#     pass
# 
# Path: pyemc/client.py
# class ServerError(Exception):
#     pass
# 
# Path: pyemc/util.py
# def generate_random_data(length_from, length_to=None):
#     length = length_from
#     if length_to is not None:
#         length = random.randint(length_from, length_to)
# 
#     return os.urandom(length)
# 
# Path: pyemc/util.py
# def generate_random_key(length):
#     data = ''
#     while len(data) < length:
#         bytes = generate_random_data(length)
#         # filter out non printable chars
#         bytes = [b for b in bytes
#                  if 65 <= ord(b) <= 90 or 97 <= ord(b) <= 122]
#         bytes = ''.join(bytes)
#         data += bytes
#     data = data[:length]
#     return data


import math
import time
from pyemc.abstractions.test_api import TestCase
from pyemc.client import ClientError
from pyemc.client import DeleteFailedError
from pyemc.client import ExistsError
from pyemc.client import NotFoundError
from pyemc.client import NotStoredError
from pyemc.client import ServerError
from pyemc.util import generate_random_data
from pyemc.util import generate_random_key
        assert int(val) == int(val2)

    def test_incr_overflow(self):
        key = generate_random_key(10)
        val = str((1 << 64) - 1)

        # set max unsigned 64bit value - overflows to 0
        self.client.set(key, val)
        val2 = self.client.incr(key)
        assert val2 == str(0)

    def test_incr_over_size(self):
        key = generate_random_key(10)
        val = str(1 << 64)  # cannot store in 64 bits

        self.client.set(key, val)
        with self.assert_raises(ClientError):
            self.client.incr(key)  # not treated as a number


    ## Exceed limits
    # TODO try key/val too large for each command?

    def test_set_too_large_key(self):
        key = generate_random_key(251)  # limit is 250b
        val = generate_random_data(1)

        with self.assert_raises(ClientError):
            self.client.set(key, val)


# Path: pyemc/abstractions/test_api.py
# class TestCase(object):
#     def __init__(self, id):
#         self.id = id
# 
#     def set_up(self, client_params):
#         '''Subclasses should implement both set_up and get_client so the runner
#         can get access to the client.'''
#         self.client = client_params.create_client()
# 
#     def get_client(self):
#         return self.client
# 
#     @contextmanager
#     def assert_raises(self, exc_class):
#         raised = False
#         try:
#             yield
# 
#         except exc_class:
#             raised = True
# 
#         if not raised:
#             raise AssertionError("%s not raised" % exc_class.__name__)
# 
#     def write(self, msg):
#         msg = '[test%s] %s' % (self.id, msg)
#         write(msg)
# 
# Path: pyemc/client.py
# class ClientError(Exception):
#     pass
# 
# Path: pyemc/client.py
# class DeleteFailedError(Exception):
#     pass
# 
# Path: pyemc/client.py
# class ExistsError(Exception):
#     pass
# 
# Path: pyemc/client.py
# class NotFoundError(Exception):
#     pass
# 
# Path: pyemc/client.py
# class NotStoredError(Exception):
#     pass
# 
# Path: pyemc/client.py
# class ServerError(Exception):
#     pass
# 
# Path: pyemc/util.py
# def generate_random_data(length_from, length_to=None):
#     length = length_from
#     if length_to is not None:
#         length = random.randint(length_from, length_to)
# 
#     return os.urandom(length)
# 
# Path: pyemc/util.py
# def generate_random_key(length):
#     data = ''
#     while len(data) < length:
#         bytes = generate_random_data(length)
#         # filter out non printable chars
#         bytes = [b for b in bytes
#                  if 65 <= ord(b) <= 90 or 97 <= ord(b) <= 122]
#         bytes = ''.join(bytes)
#         data += bytes
#     data = data[:length]
#     return data


# Path: pyemc/test_integration.py
import math
import time
from pyemc.abstractions.test_api import TestCase
from pyemc.client import ClientError
from pyemc.client import DeleteFailedError
from pyemc.client import ExistsError
from pyemc.client import NotFoundError
from pyemc.client import NotStoredError
from pyemc.client import ServerError
from pyemc.util import generate_random_data
from pyemc.util import generate_random_key

        assert int(val) == int(val2)

    def test_incr_overflow(self):
        key = generate_random_key(10)
        val = str((1 << 64) - 1)

        # set max unsigned 64bit value - overflows to 0
        self.client.set(key, val)
        val2 = self.client.incr(key)
        assert val2 == str(0)

    def test_incr_over_size(self):
        key = generate_random_key(10)
        val = str(1 << 64)  # cannot store in 64 bits

        self.client.set(key, val)
        with self.assert_raises(ClientError):
            self.client.incr(key)  # not treated as a number


    ## Exceed limits
    # TODO try key/val too large for each command?

    def test_set_too_large_key(self):
        key = generate_random_key(251)  # limit is 250b
        val = generate_random_data(1)

        with self.assert_raises(ClientError):
            self.client.set(key, val)


    def test_set_too_large_value(self):