Exemple #1
0
 def setUp(self):
     os.makedirs('/tmp/tuplespace')
     self.tuplespace = LevelDBStorage('/tmp/tuplespace')
Exemple #2
0
class TestLevelDBTupleSpace(TestCase):

    def setUp(self):
        os.makedirs('/tmp/tuplespace')
        self.tuplespace = LevelDBStorage('/tmp/tuplespace')

    def tearDown(self):
        self.tuplespace.close()
        rmtree('/tmp/tuplespace')

    def test_add_and_get(self):
        self.tuplespace.add(1, key='value')
        self.assertEqual(self.tuplespace.get(1), dict(key='value'))

    def test_add_and_query(self):
        self.tuplespace.add(1, key='value')
        self.tuplespace.add(2, key='value')
        out = list(self.tuplespace.query('key', 'value'))
        self.assertEqual(out, [['key', 'value', 1], ['key', 'value', 2]])

    def test_add_and_ref(self):
        self.tuplespace.add(1, key='value')
        self.tuplespace.add(2, key='value')
        self.assertEqual(self.tuplespace.ref(1, 'key'), 'value')

    def test_add_and_query_key_only(self):
        self.tuplespace.add(1, key='value')
        self.tuplespace.add(2, key='something')
        out = list(self.tuplespace.query('key'))
        self.assertIn(['key', 'value', 1], out)
        self.assertIn(['key', 'something', 2], out)

    def test_delete(self):
        self.tuplespace.add(1, key='value')
        out = list(self.tuplespace.query('key'))
        self.tuplespace.delete(1)
        out = list(self.tuplespace.query('key'))
        self.assertEqual(out, [])