def test_register_another_class(self): r = Registry(Dummy, "Dummy") with pytest.raises(ValueError) as e: r.register(Another("testing")) assert str( e.value) == "Dummy name \"testing\" should be an instance of Dummy"
def test_register_invalid_instance(self): r = Registry(Dummy, "Dummy") n = NoName() with pytest.raises(ValueError) as e: r.register(n, "no-name") assert str( e.value) == "Dummy name \"no-name\" should be an instance of Dummy"
def test_register_no_name_class_missing_name(self): r = Registry(NoName, "NoName") n = NoName() with pytest.raises(ValueError) as e: r.register(n) assert str( e.value ) == "Name should be provided to register this kind of object"
def test_register_alternative_name(self): r = Registry(Dummy, "Dummy") d = Dummy("dummy") r.register(d, "alt") with pytest.raises(ValueError) as e: r.get("dummy") assert str(e.value) == "Dummy name \"dummy\" is not registered" assert r.get("alt") == d assert r.all() == (d, )
def test_register(self): r = Registry(Dummy, "Dummy") d = Dummy("dummy") r.register(d) assert r.get("dummy") == d assert r.all() == (d, )
def test_cant_register_many_times(self): r = Registry(Dummy, "Dummy") d = Dummy("dummy") r.register(d) with pytest.raises(ValueError) as e: r.register(d) assert str(e.value) == "Dummy name \"dummy\" is already registered"
def test_unregistered(self): r = Registry(Dummy, "Dummy") with pytest.raises(ValueError) as e: r.get("dummy") assert str(e.value) == "Dummy name \"dummy\" is not registered"
def test_register_and_unregister(self): r = Registry(Dummy, "Dummy") d = Dummy("dummy") r.register(d) assert r.get("dummy") == d assert r.all() == (d, ) r.unregister("dummy") with pytest.raises(ValueError) as e: r.get("dummy") assert str(e.value) == "Dummy name \"dummy\" is not registered" assert not r.has("dummy") assert r.all() == ()
def test_empty(self): r = Registry(Dummy, "Dummy") assert r.all() == ()