def test_cluster_balance_constraint(): n = Node() n.production[RESOURCE] = lambda idx: 0 index = 0 assert len(n.constraints.make(index)) == 1 c = Cluster(n, resource=RESOURCE) assert len(n.constraints.make(index)) == 0 c.remove_part(n) assert len(n.constraints.make(index)) == 1
def test_cluster_add_remove(): n = Node() n.production[RESOURCE] = lambda: 0 c = Cluster(resource=RESOURCE) def not_added(): return c.parts() == set() and n.cluster(RESOURCE) is None def added(): return c.parts() == {n} and n.cluster(RESOURCE) is c assert not_added() c.add_part(n) assert added() c.add_part(n) c.remove_part(n) assert not_added() c.remove_part(n) n.set_cluster(c) assert added() assert_raises(fs.InsanityError, n.set_cluster, c) n.unset_cluster(c) assert not_added() assert_raises(fs.InsanityError, n.unset_cluster, c)
def test_cluster_add_remove(): n = Node() n.production[RESOURCE] = lambda: 0 c = Cluster(resource=RESOURCE) def not_added(): return c.children == set() and n.cluster(RESOURCE) is None def added(): return c.children == {n} and n.cluster(RESOURCE) is c assert not_added() c.add_part(n) assert added() c.add_part(n) c.remove_part(n) assert not_added() c.remove_part(n) n.set_cluster(c) assert added() assert_raises(fs.InsanityError, n.set_cluster, c) n.unset_cluster(c) assert not_added() assert_raises(fs.InsanityError, n.unset_cluster, c)
def test_cluster_balance_constraint(): n = Node() n.production[RESOURCE] = lambda: 0 assert len(n.constraints()) == 1 c = Cluster(n, resource=RESOURCE) assert len(n.constraints()) == 0 c.remove_part(n) assert len(n.constraints()) == 1
def test_cluster_insanity(): n = Node() Cluster(n, resource=RESOURCE) Cluster(n, resource=RESOURCE)