@tornado.testing.gen_test
    def test_simple_ops(self):
        yield self.resetTables()
        
        # Fresh propcache for each test (don't use app.propcache).
        cache = two.propcache.PropCache(self.app)
        deps = set()

        instq = lambda key: ('instanceprop', self.exiid, self.exlocid, key)

        # Get some values.

        res = yield cache.get(instq('x'), dependencies=deps)
        self.assertEqual(res.val, 1)
        self.assertTrue(res.found)
        self.assertFalse(res.dirty)
        self.assertFalse(res.haschanged())
        self.assertEqual(res.key, 'x')
        self.assertFalse(res.mutable)
        self.assertTrue(instq('x') in deps)
        self.assertTrue(cache.get_by_object(res.val) is None)
        
        res = yield cache.get(instq('qqq'), dependencies=deps)
        self.assertTrue(res is None)
        res = yield cache.get(instq('qqq'), dependencies=deps)
        self.assertTrue(res is None)
        self.assertTrue(instq('qqq') in deps)
        # Peek into cache internals for additional testing
        res = cache.propmap[instq('qqq')]
        self.assertFalse(res.found)
        self.assertFalse(res.dirty)
        self.assertFalse(res.haschanged())
        self.assertEqual(res.key, 'qqq')
        
        res = yield cache.get(instq('ls'), dependencies=deps)
        self.assertEqual(res.val, [1,2,3])
        self.assertTrue(res.found)
        self.assertFalse(res.dirty)
        self.assertFalse(res.haschanged())
        self.assertEqual(res.key, 'ls')
        self.assertTrue(res.mutable)
        self.assertTrue(deps in instq('ls'))
        self.assertTrue(cache.get_by_object(res.val) is res)

        res2 = yield cache.get(instq('ls'), dependencies=deps)
        self.assertTrue(res is res2)

        res = yield cache.get(instq('map'), dependencies=deps)
        self.assertEqual(res.val, {'one':1, 'two':2, 'three':3})
        self.assertTrue(res.found)
        self.assertFalse(res.dirty)
        self.assertFalse(res.haschanged())
        self.assertEqual(res.key, 'map')
        self.assertTrue(res.mutable)
        self.assertTrue(instq('map') in deps)
        self.assertTrue(cache.get_by_object(res.val) is res)

        self.assertEqual(cache.note_changed_entries(), [])
        self.assertEqual(cache.dirty_entries(), [])

        # Set some values.

        yield cache.set(instq('y'), 7)
        res = yield cache.get(instq('y'), dependencies=deps)
        self.assertEqual(res.val, 7)
        self.assertTrue(res.dirty)
        self.assertFalse(res.haschanged())
        
        res = yield self.get_db_prop(instq('y'))
        self.assertEqual(res, 2)

        yield cache.set(instq('z'), 3)
        res = yield cache.get(instq('z'), dependencies=deps)
        self.assertEqual(res.val, 3)
        self.assertTrue(res.dirty)
        self.assertFalse(res.haschanged())
        
        res = yield self.get_db_prop(instq('z'))
        self.assertEqual(res, NotFound)

        self.assertEqual(cache.note_changed_entries(), [])
        self.assertEqual(len(cache.dirty_entries()), 2)

        self.assertEqual(cache.note_changed_entries(), [])
        yield cache.write_all_dirty()
        self.assertEqual(cache.dirty_entries(), [])
        
        res = yield cache.get(instq('y'), dependencies=deps)
        self.assertEqual(res.val, 7)
        res = yield self.get_db_prop(instq('y'))
        self.assertEqual(res, 7)
        
        res = yield cache.get(instq('z'), dependencies=deps)
        self.assertEqual(res.val, 3)
        res = yield self.get_db_prop(instq('z'))
        self.assertEqual(res, 3)

        yield cache.set(instq('listtuple'), (1,2,3))
        res = yield cache.get(instq('listtuple'), dependencies=deps)
        self.assertEqual(res.val, (1,2,3))
        
        self.assertEqual(cache.note_changed_entries(), [])
        yield cache.write_all_dirty()
        self.assertEqual(cache.dirty_entries(), [])

        res = yield self.get_db_prop(instq('listtuple'))
        self.assertEqual(res, [1,2,3])
        
        # Delete some values.

        yield cache.delete(instq('x'))
        res = yield cache.get(instq('x'), dependencies=deps)
        self.assertTrue(res is None)

        res = yield self.get_db_prop(instq('x'))
        self.assertEqual(res, 1)
        
        yield cache.delete(instq('qqqq'))
        res = yield cache.get(instq('qqqq'), dependencies=deps)
        self.assertTrue(res is None)
        
        yield cache.delete(instq('map'))
        res = yield cache.get(instq('map'), dependencies=deps)
        self.assertTrue(res is None)

        res = yield self.get_db_prop(instq('map'))
        self.assertEqual(res, {'one':1, 'two':2, 'three':3})
        
        self.assertEqual(cache.note_changed_entries(), [])
        self.assertEqual(len(cache.dirty_entries()), 3)

        self.assertEqual(cache.note_changed_entries(), [])
        yield cache.write_all_dirty()
        self.assertEqual(cache.dirty_entries(), [])
        
        res = yield self.get_db_prop(instq('x'))
        self.assertEqual(res, NotFound)
        res = yield self.get_db_prop(instq('qqqq'))
        self.assertEqual(res, NotFound)
        res = yield self.get_db_prop(instq('map'))
        self.assertEqual(res, NotFound)
        
        yield cache.delete(instq('x'))
        res = yield cache.get(instq('x'), dependencies=deps)
        self.assertTrue(res is None)
dataset/ETHPy150Open erkyrath/tworld/lib/twest/test_propcache.py/TestPropcache.test_simple_ops/swapped operands of `in`