Пример #1
0
 def testFilterSimple(self):
     session = self.session()
     query = session.query(self.model)
     for i in range(10):
         code = randomcode()
         qs = query.filter(code = code)
         self.assertEqual(qs.count(),1)
         self.assertEqual(qs[0].code,code)
Пример #2
0
 def testExcludeSimple(self):
     session = self.session()
     query = session.query(self.model)
     for i in range(10):
         code = randomcode()
         r = query.exclude(code = code)
         self.assertEqual(r.count(),SIZE-1)
         self.assertFalse(code in set((o.code for o in r)))
Пример #3
0
 def testFilterSimple(self):
     session = self.session()
     query = session.query(self.model)
     for i in range(10):
         code = self.data.randomcode()
         qs = yield query.filter(code=code).all()
         self.assertEqual(len(qs), 1)
         self.assertEqual(qs[0].code, code)
Пример #4
0
 def testExcludeSimple(self):
     session = self.session()
     query = session.query(self.model)
     for i in range(10):
         code = self.data.randomcode()
         all = yield query.exclude(code=code).all()
         self.assertEqual(len(all), self.data.size-1)
         self.assertFalse(code in set((o.code for o in all)))
Пример #5
0
 def testExcludeSimple(self):
     session = self.session()
     query = session.query(self.model)
     for i in range(10):
         code = self.data.randomcode()
         all = yield query.exclude(code=code).all()
         self.assertEqual(len(all), self.data.size - 1)
         self.assertFalse(code in set((o.code for o in all)))
Пример #6
0
 def extend(self, words):
     add = self.data.add
     for word in words:
         we = word+self.endchar
         add(we)
         for idx in range(self.minlen,len(word)):
             add(word[:idx])
     self.data.save()
Пример #7
0
 def testFilterSimple(self):
     session = self.session()
     query = session.query(self.model)
     for i in range(10):
         code = self.data.randomcode()
         qs = yield query.filter(code=code).all()
         self.assertEqual(len(qs), 1)
         self.assertEqual(qs[0].code, code)
Пример #8
0
 def setUp(self):
     ts = []
     ss = []
     self.closureCount = 0
     for x in range(5000):
         t = oTest1()
         ts.append(t)
         s = safeRef(t, self._closure)
         ss.append(s)
     ts.append(ftest2)
     ss.append(safeRef(ftest2, self._closure))
     for x in range(30):
         t = oTest2()
         ts.append(t)
         s = safeRef(t, self._closure)
         ss.append(s)
     self.ts = ts
     self.ss = ss
Пример #9
0
 def generate(self):
     size, num = self.size
     self.names = self.populate('choice', size=size,
                                choice_from=basic_english_words)
     self.groups = []
     self.empty = size*['']
     for i in range(size):
         text = ' '.join(self.populate('choice', num,\
                                       choice_from=basic_english_words))
         self.groups.append(text)
Пример #10
0
 def add(self, word):
     '''Add a word to the dataset'''
     dataset = self.data
     we = word+self.endchar
     if word in dataset:
         dataset.add(we)
         dataset.save()
     elif we not in dataset:
         for idx in range(self.minlen,len(word)):
             dataset.add(word[:idx])
         dataset.add(we)
         dataset.save()
Пример #11
0
 def make(self, size = 5, maxsize = 10, nesting = 1, level = 0):
     keys = populate(size = size)
     if level:
         keys.append('')
     for key in keys:
         t = choice(self.rtype) if level else 'dict'
         if nesting and t == 'dict':
             yield key,dict(self.make(size = randint(0,maxsize),
                                      maxsize = maxsize,
                                      nesting = nesting - 1,
                                      level = level + 1))
         else:
             if t == 'list':
                 v = [random() for i in range(10)]
             elif t == 'number':
                 v = random()
             elif t == 'dict':
                 v = random()
             else:
                 v = t
             yield key,v
Пример #12
0
 def make(self, size=5, maxsize=10, nesting=1, level=0):
     keys = populate(size=size)
     if level:
         keys.append('')
     for key in keys:
         t = choice(self.rtype) if level else 'dict'
         if nesting and t == 'dict':
             yield key, dict(
                 self.make(size=randint(0, maxsize),
                           maxsize=maxsize,
                           nesting=nesting - 1,
                           level=level + 1))
         else:
             if t == 'list':
                 v = [random() for i in range(10)]
             elif t == 'number':
                 v = random()
             elif t == 'dict':
                 v = random()
             else:
                 v = t
             yield key, v
Пример #13
0
    def disconnect(self, receiver=None, sender=None, weak=True,
                   dispatch_uid=None):
        """
        Disconnect receiver from sender for signal.

        If weak references are used, disconnect need not be called. The receiver
        will be remove from dispatch automatically.

        Arguments:

            receiver
                The registered receiver to disconnect. May be none if
                dispatch_uid is specified.

            sender
                The registered sender to disconnect

            weak
                The weakref state to disconnect

            dispatch_uid
                the unique identifier of the receiver to disconnect
        """
        if dispatch_uid:
            lookup_key = (dispatch_uid, _make_id(sender))
        else:
            lookup_key = (_make_id(receiver), _make_id(sender))

        self.lock.acquire()
        try:
            for index in range(len(self.receivers)):
                (r_key, _) = self.receivers[index]
                if r_key == lookup_key:
                    del self.receivers[index]
                    break
        finally:
            self.lock.release()
Пример #14
0
         'Dallas':('TLS', None),
         'maisey':('MS', None),
         'zhang':('JNK', None),
         'Chile':('XL', None),
         'Jose':('HS', None),
         'Arnow':('ARN','ARNF'),
         'solilijs':('SLLS', None),
         'Parachute':('PRKT', None),
         'Nowhere':('NR', None),
         'Tux':('TKS', None)}


NUM_WORDS = 40
WORDS_GROUPS = lambda size : (' '.join(populate('choice', NUM_WORDS,\
                              choice_from = basic_english_words))\
                               for i in range(size))
    
    
class TestCase(test.CleanTestCase):
    '''Mixin for testing the search engine. No tests implemented here,
just registration and some utility functions. All search-engine tests
below will derive from this class.'''
    multipledb = 'redis'
    metaphone = True
    stemming = True
    models = (WordItem, Item, RelatedItem)
    
    def setUp(self):
        self.register()
        self.engine = self.make_engine()
        self.engine.register(Item,('related',))
Пример #15
0
 def publish():
     for i in range(messages_per_channel):
         for c in channels_to_publish_to:
             self.client.publish(c, 'a message')
Пример #16
0
import datetime
import threading
import time
from distutils.version import StrictVersion

from stdnet.utils import to_string, ispy3k, iteritems, range, flatzset

if not ispy3k:
    chr = unichr
    
from .base import *


to_charlist = lambda x: [x[c:c + 1] for c in range(len(x))]
binary_set = lambda x : set(to_charlist(x))

encode_dict = lambda h : dict(((k,v.encode()) for k,v in h.items()))


class ServerCommandsTestCase(BaseTest):

    def setUp(self):
        self.client = self.get_client()
        self.client.flushdb()
        
    def tearDown(self):
        self.client.flushdb()

    # GENERAL SERVER COMMANDS
    def test_dbsize(self):
        self.client['a'] = 'foo'