Esempio n. 1
0
  def test_read_on_disk_err(self):
    flag = True
    def onFire(x):
      global flag
      flag = True
    ce = CacheEntry('http://example.com/foo/bar/doesnotexist', 'test', 0.0, onFire)
    ce.datafile = None 
    d = ce.read()
    def xxx(f):
      self.assert_(False)
    d.addCallback(xxx)

    def xxx(f):
      global flag
      flag = True
    d.addErrback(xxx)

    def yyy(f):
      print  'yyy'
      self.assert_(flag)
    d.addCallback(yyy)

    try:
      ce.move_from_file()
    except:
      pass 
    return d
Esempio n. 2
0
  def test_read_on_disk_ok(self):
    cells = {'flag':False,
             'x' : None,
             'y': None}

    def my_asserts():
      print 'my_asserts'
      self.assert_(cells['flag'])
      self.assertNotEquals(cells['x'], cells['y'])

    def onFire(ce):
      f = ce.datafile
      self.assertEquals(f.read(), 'deadbeaf')
      cells['y'] = id(f)

    ce = CacheEntry('http://example.com/foo/bar/data', 'test', 0.0, onFire)
    ce.datafile = None 
    ce.fname = url2name(ce.key)
    d = ce.read()

    def xxx(f):
      cells['flag'] = True
      self.assertEquals(f.read(), 'deadbeaf')
      cells['x'] = id(f)
      my_asserts()
    d.addCallback(xxx)

    return d