Exemple #1
0
    def test_registered_create_array_arg(self):

        CobaRegistry.register("test", TestArgObject)

        klass = CobaRegistry.construct({"test": [1, 2, 3]})

        self.assertEqual(klass.arg, [1, 2, 3])
Exemple #2
0
    def test_registered_create_args_kwargs(self):

        CobaRegistry.register("test", TestObject)

        klass = CobaRegistry.construct({"test": [1, 2, 3], "kwargs": {"a": 1}})

        self.assertEqual(klass.args, (1, 2, 3))
        self.assertEqual(klass.kwargs, {"a": 1})
Exemple #3
0
    def test_registered_create_args3(self):

        CobaRegistry.register("test", TestObject)

        klass = CobaRegistry.construct({"test": "abc"})

        self.assertEqual(klass.args, ("abc", ))
        self.assertEqual(klass.kwargs, {})
Exemple #4
0
    def test_registered_create(self):

        CobaRegistry.register("test", TestObject)

        klass = CobaRegistry.construct("test")

        self.assertEqual(klass.args, ())
        self.assertEqual(klass.kwargs, {})
Exemple #5
0
    def test_not_registered(self):

        CobaRegistry.register("test", TestObject)

        with self.assertRaises(Exception) as cm:
            CobaRegistry.construct("test2")

        self.assertEqual("Unknown recipe test2", str(cm.exception))
Exemple #6
0
    def test_invalid_recipe3(self):

        CobaRegistry.register("test", TestObject)

        recipe = {"test": {"a": 1}, "name": "test", "kwargs": {"a": 1}}

        with self.assertRaises(Exception) as cm:
            CobaRegistry.construct(recipe)

        self.assertEqual(f"Invalid recipe {str(recipe)}", str(cm.exception))
Exemple #7
0
    def test_invalid_recipe2(self):

        CobaRegistry.register("test", TestObject)

        recipe = {"test": [1, 2, 3], "name": "test", "args": [4, 5, 6]}

        with self.assertRaises(Exception) as cm:
            CobaRegistry.construct(recipe)

        self.assertEqual(f"Invalid recipe {str(recipe)}", str(cm.exception))
Exemple #8
0
    def test_registered_create_foreach1(self):

        CobaRegistry.register("test", TestObject)

        recipe = {"test": [[1, 2, 3]], "kwargs": {"a": 1}, "method": "foreach"}

        klasses = CobaRegistry.construct(recipe)

        self.assertEqual(len(klasses), 1)
        self.assertEqual(klasses[0].args, (1, 2, 3))
        self.assertEqual(klasses[0].kwargs, {"a": 1})
Exemple #9
0
    def test_registered_create_recursive3(self):

        CobaRegistry.register("test", TestObject)

        klass = CobaRegistry.construct({"test": {"a": "test"}})

        self.assertEqual(klass.args, ())
        self.assertEqual(1, len(klass.kwargs))

        self.assertIsInstance(klass.kwargs["a"], TestObject)
        self.assertEqual(klass.kwargs["a"].args, ())
        self.assertEqual(klass.kwargs["a"].kwargs, {})
Exemple #10
0
    def test_registered_create_foreach4(self):

        CobaRegistry.register("test", TestObject)

        recipe = {"test": [[1, 2], 3], "method": "foreach"}

        klasses = CobaRegistry.construct(recipe)

        self.assertEqual(len(klasses), 2)

        self.assertEqual(klasses[0].args, (1, 2))
        self.assertEqual(klasses[0].kwargs, {})

        self.assertEqual(klasses[1].args, (3, ))
        self.assertEqual(klasses[1].kwargs, {})
Exemple #11
0
    def test_registered_create_foreach3(self):

        CobaRegistry.register("test", TestObject)

        recipe = {
            "test": [1, 2],
            "kwargs": [{
                "a": 1
            }, {
                "a": 2
            }],
            "method": "foreach"
        }

        klasses = CobaRegistry.construct(recipe)

        self.assertEqual(len(klasses), 2)

        self.assertEqual(klasses[0].args, (1, ))
        self.assertEqual(klasses[0].kwargs, {"a": 1})

        self.assertEqual(klasses[1].args, (2, ))
        self.assertEqual(klasses[1].kwargs, {"a": 2})
Exemple #12
0
    def test_registered_create_dict_arg(self):

        CobaRegistry.register("test", TestArgObject)

        with self.assertRaises(Exception):
            klass = CobaRegistry.construct({"test": {"a": 1}})
Exemple #13
0
from coba.registry import CobaRegistry
from coba.pipes import NullSink, ConsoleSink, DiskSink, HttpSource
from coba.environments import OpenmlSimulation, SerializedSimulation, SupervisedSimulation
from coba.environments import Sort, Scale, Cycle, Shuffle, Take, Identity
from coba.contexts import DiskCacher, NullCacher, IndentLogger, NullLogger, BasicLogger

CobaRegistry.register("Null", NullSink)
CobaRegistry.register("Disk", DiskSink)
CobaRegistry.register("Http", HttpSource)
CobaRegistry.register("Console", ConsoleSink)

CobaRegistry.register("BasicLogger", BasicLogger)
CobaRegistry.register("IndentLogger", IndentLogger)
CobaRegistry.register("NullLogger", NullLogger)

CobaRegistry.register("DiskCacher", DiskCacher)
CobaRegistry.register("NullCacher", NullCacher)

CobaRegistry.register("OpenmlSimulation", OpenmlSimulation)
CobaRegistry.register("SerializedSimulation", SerializedSimulation)
CobaRegistry.register("SupervisedSimulation", SupervisedSimulation)

CobaRegistry.register("Identity", Identity)
CobaRegistry.register("Take", Take)
CobaRegistry.register("Shuffle", Shuffle)
CobaRegistry.register("Sort", Sort)
CobaRegistry.register("Scale", Scale)
CobaRegistry.register("Cycle", Cycle)
 def setUp(self) -> None:
     CobaRegistry.register("OpenmlSimulation", OpenmlSimulation)
     CobaRegistry.register("Take", Take)