def test_0(self):
        class Opt(opt.Optimizer):  # inheritance buys __hash__
            name = 'blah'

        db = DB()
        db.register('a', Opt())

        db.register('b', Opt())

        db.register('c', Opt(), 'z', 'asdf')

        try:
            db.register('c', Opt())  # name taken
            self.fail()
        except ValueError, e:
            if exc_message(e).startswith("The name"):
                pass
            else:
                raise
Beispiel #2
0
    def test_0(self):

        class Opt(opt.Optimizer):  # inheritance buys __hash__
            name = 'blah'

        db = DB()
        db.register('a', Opt())

        db.register('b', Opt())

        db.register('c', Opt(), 'z', 'asdf')

        try:
            db.register('c', Opt())  # name taken
            self.fail()
        except ValueError, e:
            if e[0].startswith("The name"):
                pass
            else:
                raise
Beispiel #3
0
    def test_0(self):
        class Opt(opt.Optimizer):  # inheritance buys __hash__
            name = 'blah'

        db = DB()
        db.register('a', Opt())

        db.register('b', Opt())

        db.register('c', Opt(), 'z', 'asdf')

        self.assertTrue('a' in db)
        self.assertTrue('b' in db)
        self.assertTrue('c' in db)

        try:
            db.register('c', Opt())  # name taken
            self.fail()
        except ValueError as e:
            if exc_message(e).startswith("The name"):
                pass
            else:
                raise
        except Exception:
            self.fail()

        try:
            db.register('z', Opt())  # name collides with tag
            self.fail()
        except ValueError as e:
            if exc_message(e).startswith("The name"):
                pass
            else:
                raise
        except Exception:
            self.fail()

        try:
            db.register('u', Opt(), 'b')  # name new but tag collides with name
            self.fail()
        except ValueError as e:
            if exc_message(e).startswith("The tag"):
                pass
            else:
                raise
        except Exception:
            self.fail()
Beispiel #4
0
    def test_0(self):

        class Opt(opt.Optimizer):  # inheritance buys __hash__
            name = 'blah'

        db = DB()
        db.register('a', Opt())

        db.register('b', Opt())

        db.register('c', Opt(), 'z', 'asdf')

        try:
            db.register('c', Opt())  # name taken
            self.fail()
        except ValueError as e:
            if exc_message(e).startswith("The name"):
                pass
            else:
                raise
        except Exception:
            self.fail()

        try:
            db.register('z', Opt())  # name collides with tag
            self.fail()
        except ValueError as e:
            if exc_message(e).startswith("The name"):
                pass
            else:
                raise
        except Exception:
            self.fail()

        try:
            db.register('u', Opt(), 'b')  # name new but tag collides with name
            self.fail()
        except ValueError as e:
            if exc_message(e).startswith("The tag"):
                pass
            else:
                raise
        except Exception:
            self.fail()
Beispiel #5
0
    def test_name_clashes(self):
        class Opt(opt.Optimizer):  # inheritance buys __hash__
            name = "blah"

        db = DB()
        db.register("a", Opt())

        db.register("b", Opt())

        db.register("c", Opt(), "z", "asdf")

        assert "a" in db
        assert "b" in db
        assert "c" in db

        with pytest.raises(ValueError, match=r"The name.*"):
            db.register("c", Opt())  # name taken

        with pytest.raises(ValueError, match=r"The name.*"):
            db.register("z", Opt())  # name collides with tag

        with pytest.raises(ValueError, match=r"The tag.*"):
            db.register("u", Opt(), "b")  # name new but tag collides with name