Ejemplo n.º 1
0
def test_save_load_plan():
    dbfile = 'sqlite:///test_save_load_plan.db'
    if os.path.exists('test_save_load_plan.db'):
        os.remove('test_save_load_plan.db')
    with allegedb.ORM(dbfile) as orm:
        g1 = orm.new_graph(1)
        g2 = orm.new_graph(2)
        with orm.plan():
            g1.add_node(1)
            g1.add_node(2)
            orm.turn = 1
            g1.add_edge(1, 2)
        orm.turn = 0
        with orm.plan():
            g2.add_node(1)
            g2.add_node(2)
            orm.turn = 1
            g2.add_edge(1, 2)
        orm.turn = 0
    with allegedb.ORM(dbfile) as orm:
        g1 = orm.graph[1]
        g2 = orm.graph[2]
        # go to end of turn
        orm.turn = 0
        # contradict the plan
        del g1.node[2]
        assert 1 in g2.node
        assert 2 in g2.node
        orm.turn = 1
        assert 2 not in g1.node
        assert 2 not in g1.edge[1]
        assert 2 in g2.edge[1]
    with allegedb.ORM(dbfile) as orm:
        g1 = orm.graph[1]
        g2 = orm.graph[2]
        assert 1 in g2.node
        assert 2 in g2.node
        orm.turn = 1
        assert 2 not in g1.node
        assert 2 not in g1.edge[1]
        assert 2 in g2.edge[1]
        orm.turn = 0
        while 2 in g2.node:
            orm.tick -= 1
        g2.add_node(2)  # contradict plan
        orm.turn = 0  # end of turn
        assert 2 not in g2.edge[1]
    os.remove('test_save_load_plan.db')
Ejemplo n.º 2
0
 def setUp(self):
     self.engine = allegedb.ORM('sqlite:///:memory:')
     self.engine.initdb()
     self.graphmakers = (self.engine.new_graph, self.engine.new_digraph, self.engine.new_multigraph, self.engine.new_multidigraph)
Ejemplo n.º 3
0
def orm():
    with allegedb.ORM("sqlite:///:memory:") as it:
        yield it