def test_provider_rename_attribute(self): obj1 = Dummy(1) self.assertTrue(provider1(obj1, False, attribute_name="xxx") == 1) self.assertRaises(Exception, provider1, obj1, True) self.assertTrue(hg.get_attribute(obj1, "xxx") == 1) self.assertTrue(provider1(obj1, True, attribute_name="xxx") == 1) hg.clear_all_attributes()
def test_auto_cache_no_cache_doesnt_store_result(self): global crash_fun1 obj1 = Dummy(1) crash_fun1 = False self.assertTrue(fun1(obj1, 2, no_cache=True) == 1) crash_fun1 = True self.assertRaises(Exception, fun1, obj1, 2) hg.clear_all_attributes()
def test_consumer_compoundPath(self): obj7 = Dummy(7) obj8 = Dummy(8) self.assertRaises(Exception, consumer3, obj7) hg.set_attribute(obj7, "dep", obj8) self.assertTrue(consumer3(obj7) == 3) self.assertTrue(hg.get_attribute(obj8, "attr2") == 2) self.assertTrue(hg.get_attribute(obj8, "attr1") == 1) hg.clear_all_attributes()
def test_auto_cache_rename_attribute(self): global crash_fun1 obj1 = Dummy(1) crash_fun1 = False self.assertTrue(fun1(obj1, "aa", attribute_name="xxx") == 1) crash_fun1 = True self.assertRaises(Exception, fun1, obj1, "aa") self.assertTrue(fun1(obj1, "aa", attribute_name="xxx") == 1) hg.clear_all_attributes()
def test_auto_cache_no_cache_implies_force_recompute(self): global crash_fun1 obj1 = Dummy(1) crash_fun1 = False self.assertTrue(fun1(obj1, 3) == 1) crash_fun1 = True self.assertTrue(fun1(obj1, 3) == 1) self.assertRaises(Exception, fun1, obj1, 3, no_cache=True) hg.clear_all_attributes()
def test_provider_caching_global_setting(self): obj1 = Dummy(1) hg.set_provider_caching(False) self.assertTrue(provider1(obj1, False) == 1) self.assertRaises(Exception, provider1, obj1, True) hg.set_provider_caching(True) self.assertTrue(provider1(obj1, False) == 1) self.assertTrue(provider1(obj1, True) == 1) hg.set_provider_caching(False) self.assertRaises(Exception, provider1, obj1, True) hg.set_provider_caching(True) hg.clear_all_attributes()
def test_cached_attr(self): global crash_cached_attr obj1 = Dummy(1) crash_cached_attr = False self.assertTrue(cached_attr(obj1, 2) == 3) crash_cached_attr = True self.assertTrue(cached_attr(obj1, 2) == 3) self.assertRaises(Exception, cached_attr, obj1, 2, no_cache=True) self.assertRaises(Exception, cached_attr, obj1, 2, force_recompute=True) hg.clear_all_attributes()
def test_auto_cache_global_setting(self): global crash_fun1 obj1 = Dummy(1) crash_fun1 = False hg.set_auto_cache_state(False) self.assertTrue(fun1(obj1, 1) == 1) crash_fun1 = True self.assertRaises(Exception, fun1, obj1, 1) hg.set_auto_cache_state(True) crash_fun1 = False self.assertTrue(fun1(obj1, 2) == 1) crash_fun1 = True self.assertTrue(fun1(obj1, 2) == 1) hg.set_auto_cache_state(False) self.assertRaises(Exception, fun1, obj1, 1) hg.set_auto_cache_state(True) hg.clear_all_attributes()
def test_default_parameter_caching(self): global crash_default_attr obj1 = Dummy(1) crash_default_attr = False self.assertTrue(default_attr(obj1, 1) == 4) crash_default_attr = True self.assertTrue(default_attr(obj1) == 4) self.assertRaises(Exception, default_attr, obj1, no_cache=True) hg.clear_all_attributes() crash_default_attr = False self.assertTrue(default_attr(obj1) == 4) crash_default_attr = True self.assertTrue(default_attr(obj1, 1) == 4) self.assertRaises(Exception, default_attr, obj1, 1, force_recompute=True)
def test_construct(self): o1 = Dummy(1) o2 = Dummy(2) o3 = Dummy(3) o4 = Dummy(4) CptA.link(o1, o2) CptB.link(o3, o1, o4) ca = CptA.construct(o1) cb = CptB.construct(o3) ref_ca = {"caA": o1, "ea1": o2} ref_cb = {"caB": o3, "eb2": o4, "caA": o1, "ea1": o2} self.assertTrue(ca == ref_ca) self.assertTrue(cb == ref_cb) hg.clear_all_attributes()
def test_consumer(self): obj3 = Dummy(3) self.assertRaises(Exception, consumer0, obj3) self.assertTrue(consumer0(obj3, 1) == 1) self.assertTrue(consumer0(obj3, attr0=1) == 1) hg.set_attribute(obj3, "attr0", 1) self.assertTrue(consumer0(obj3) == 1) hg.clear_all_attributes() obj4 = Dummy(4) self.assertTrue(consumer1(obj4) == 1) self.assertTrue(hg.get_attribute(obj4, "attr1") == 1) hg.clear_all_attributes() obj5 = Dummy(5) self.assertTrue(consumer2(obj5) == 1) self.assertTrue(hg.get_attribute(obj5, "attr1") == 1) hg.clear_all_attributes()
def setUp(self): hg.clear_all_attributes()
def test_providerconsumer(self): obj2 = Dummy(2) self.assertTrue(provider_consumer(obj2, crash=False) == 2) self.assertTrue(provider_consumer(obj2, crash=True) == 2) self.assertRaises(Exception, provider_consumer, obj2, crash=True, force_recompute=True) hg.clear_all_attributes()
def test_argument_helper_accept_RegularGraph2d(self): g = hg.get_4_adjacency_implicit_graph((2, 3)) self.assertTrue(accept_RegularGraph2d(g) == 2) self.assertRaises(MyException, accept_RegularGraph2d, (4, 5), (2, 3)) hg.clear_all_attributes()
def test_argument_helper_accept_everything(self): self.assertTrue(accept_everything(2) == 1) self.assertTrue(accept_everything((3, 2)) == 1) self.assertTrue(accept_everything({3, 2}) == 1) self.assertTrue(accept_everything({"toto": 42}) == 1) hg.clear_all_attributes()
def test_consumer_repath(self): obj6 = Dummy(6) self.assertTrue(consumer2(obj6, attr1="attr2") == 2) self.assertTrue(consumer2(obj6, "attr2") == 2) self.assertTrue(hg.get_attribute(obj6, "attr2") == 2) hg.clear_all_attributes()
def test_provider_caching_and_force_recompute(self): obj1 = Dummy(1) self.assertTrue(provider1(obj1, False) == 1) self.assertTrue(provider1(obj1, True) == 1) self.assertRaises(Exception, provider1, obj1, True, force_recompute=True) hg.clear_all_attributes()
def test_provider_no_cache_doesnt_store_result(self): obj1 = Dummy(1) self.assertTrue(provider1(obj1, False, no_cache=True) == 1) self.assertRaises(Exception, provider1, obj1, True) hg.clear_all_attributes()