def test5add(self): """ Queue.add() """ q = queue.Queue(self.qdir, schema={'a': 'string'}) q.add({'a': 'a\n'}) assert os.listdir(self.qdir + '/' + queue.TEMPORARY_DIRECTORY) == [] data_file = '%s/%s/%s/a' % (self.qdir, '%08x' % 0, os.listdir('%s/%08x' % (self.qdir, 0))[-1]) assert os.path.exists(data_file) assert open(data_file).read() == 'a\n'
def test6touch(self): """ Queue.touch() """ q = queue.Queue(self.qdir, schema={'a': 'string'}) q.add({'a': 'a\n'}) e = q.first() element_dir = q.path + '/' + e old_time = time.time() - 10 os.utime(element_dir, (old_time, old_time)) mtime = os.stat(element_dir).st_mtime q.touch(e) assert os.stat(element_dir).st_mtime > mtime
def test4_insertion_directory(self): """ Queue._insertion_directory() """ q = queue.Queue(self.qdir, schema={'a': 'string'}) q.maxelts = 1 name0 = '%08x' % 0 assert q._insertion_directory() == name0 assert os.path.exists(self.qdir + '/' + name0) os.mkdir('%s/%s/%s' % (self.qdir, name0, queue._name(q.rndhex))) name1 = '%08x' % 1 assert q._insertion_directory() == name1 assert os.path.exists(self.qdir + '/' + name1)
def new_dirq(path, _schema): """Create a new Directory::Queue object, optionally with schema. """ kwargs = {} if opts.type == "simple": if opts.granularity is not None: kwargs['granularity'] = opts.granularity return QueueSimple(path, **kwargs) else: if _schema: schema = {'body': 'string', 'header': 'table?'} kwargs['schema'] = schema if opts.maxelts: kwargs['maxelts'] = opts.maxelts return queue.Queue(path, **kwargs)