# 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
        val = generate_random_data(10)
        val2 = generate_random_data(10)

        # try to prepend to an invalid key
        with self.assert_raises(NotStoredError):
            self.client.prepend(key, val)

        self.client.set(key, val)
        self.client.prepend(key, val2)
        item = self.client.get(key)
        assert val2 + val == item.value

    def test_prepend_noreply(self):
        key = generate_random_key(8)
        val = generate_random_data(10)
        val2 = generate_random_data(10)

        self.client.set(key, val)
        self.client.prepend(key, val2, noreply=True)
        item = self.client.get(key)
        assert val2 + val == item.value

    # Replace

    def test_replace(self):
        key = generate_random_key(8)
        val = generate_random_data(10)
        val2 = generate_random_data(10)

        # try to replace an invalid key

# 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

        val = generate_random_data(10)
        val2 = generate_random_data(10)

        # try to prepend to an invalid key
        with self.assert_raises(NotStoredError):
            self.client.prepend(key, val)

        self.client.set(key, val)
        self.client.prepend(key, val2)
        item = self.client.get(key)
        assert val2 + val == item.value

    def test_prepend_noreply(self):
        key = generate_random_key(8)
        val = generate_random_data(10)
        val2 = generate_random_data(10)

        self.client.set(key, val)
        self.client.prepend(key, val2, noreply=True)
        item = self.client.get(key)
        assert val2 + val == item.value

    # Replace

    def test_replace(self):
        key = generate_random_key(8)
        val = generate_random_data(10)
        val2 = generate_random_data(10)

        # try to replace an invalid key

        with self.assert_raises(NotStoredError):