Exemplo n.º 1
0
 def _simple_repr(self):
     r = {'__module__': self.__module__,
          '__qualname__': self.__class__.__qualname__,
          'factor': simple_repr(self.factor_node),
          'variable': simple_repr(self.variable_node)
          }
     return r
Exemplo n.º 2
0
    def test_simple_repr(self):
        d = VariableDomain('d', 'foo', [1, 2, 3])
        v = Variable('v1', d, 2)

        r = simple_repr(v)
        self.assertEqual(r['name'], 'v1')
        self.assertEqual(r['initial_value'], 2)
        self.assertEqual(r['domain'], simple_repr(d))
Exemplo n.º 3
0
    def test_simple_repr(self):
        d = VariableDomain("d", "foo", [1, 2, 3])
        v = Variable("v1", d, 2)

        r = simple_repr(v)
        self.assertEqual(r["name"], "v1")
        self.assertEqual(r["initial_value"], 2)
        self.assertEqual(r["domain"], simple_repr(d))
Exemplo n.º 4
0
 def _simple_repr(self):
     r = {
         "__module__": self.__module__,
         "__qualname__": self.__class__.__qualname__,
         "type": self.type,
         "source": simple_repr(self.source),
         "target": simple_repr(self.target),
     }
     return r
Exemplo n.º 5
0
 def _simple_repr(self):
     r = {
         '__module__': self.__module__,
         '__qualname__': self.__class__.__qualname__,
         'type': self.type,
         'source': simple_repr(self.source),
         'target': simple_repr(self.target)
     }
     return r
Exemplo n.º 6
0
    def _simple_repr(self):

        # Full name = module + qualifiedname (for inner classes)
        r = {
            "__module__": self.__module__,
            "__qualname__": "message_type",
            "__type__": self.__class__.__qualname__,
        }
        for arg in fields:
            try:
                val = getattr(self, arg)
                r[arg] = simple_repr(val)
            except AttributeError:
                if hasattr(self,
                           "_repr_mapping") and arg in self._repr_mapping:
                    try:
                        r[arg] = self.__getattribute__(self._repr_mapping[arg])
                    except AttributeError:
                        SimpleReprException(
                            f"Invalid repr_mapping in {self}, "
                            "no attribute for {self._repr_mapping[arg]}")

                else:
                    raise SimpleReprException(
                        "Could not build repr for {self}, "
                        "no attribute for {arg}")
        return r
Exemplo n.º 7
0
    def test_from_repr(self):
        domain = VariableDomain('d', 'd', [1, 2, 3, 4])
        v = ExternalVariable('v', domain, value=1)

        r = simple_repr(v)
        v1 = from_repr(r)
        self.assertEqual(v, v1)
Exemplo n.º 8
0
    def _simple_repr(self):

        # Full name = module + qualifiedname (for inner classes)
        r = {'__module__': self.__module__,
             '__qualname__': 'message_type',
             '__type__': self.__class__.__qualname__}
        for arg in fields:
            try:
                val = getattr(self, arg)
                r[arg] = simple_repr(val)
            except AttributeError:
                if hasattr(self, '_repr_mapping') and arg in \
                        self._repr_mapping:
                    try:
                        r[arg] = self.__getattribute__(
                            self._repr_mapping[arg])
                    except AttributeError:
                        SimpleReprException('Invalid repr_mapping in {}, '
                                            'no attribute for {}'.
                                            format(self,
                                                   self._repr_mapping[arg]))

                else:
                    raise SimpleReprException('Could not build repr for {}, '
                                              'no attribute for {}'.
                                              format(self, arg))
        return r
Exemplo n.º 9
0
    def test_simple_repr_list_based_domain(self):
        v = Variable('v1', [1, 2, 3])

        r = simple_repr(v)
        self.assertEqual(r['name'], 'v1')
        self.assertEqual(r['initial_value'], None)
        self.assertEqual(r['domain']['values'], [1, 2, 3])
Exemplo n.º 10
0
    def test_simple_repr(self):
        msg = Message("test", "str_content")

        r = simple_repr(msg)

        self.assertEqual(r["msg_type"], "test")
        self.assertEqual(r["content"], "str_content")
Exemplo n.º 11
0
    def test_from_repr(self):
        msg = Message("test", "str_content")

        r = simple_repr(msg)
        msg2 = from_repr(r)

        self.assertEqual(msg, msg2)
Exemplo n.º 12
0
    def test_simple_repr(self):
        f = ExpressionFunction('a + b ')
        self.assertEqual(f.expression, 'a + b ')

        r = simple_repr(f)

        self.assertEqual(r['expression'], 'a + b ')
    def test_from_repr(self):
        msg = Message('test', 'str_content')

        r = simple_repr(msg)
        msg2 = from_repr(r)

        self.assertEqual(msg, msg2)
    def test_simple_repr(self):
        msg = Message('test', 'str_content')

        r = simple_repr(msg)

        self.assertEqual(r['msg_type'], 'test')
        self.assertEqual(r['content'], 'str_content')
Exemplo n.º 15
0
    def test_simple_repr(self):
        domain = VariableDomain('d', 'd', [1, 2, 3, 4])
        v = ExternalVariable('v', domain, value=1)

        r = simple_repr(v)

        self.assertEqual(r['name'], 'v')
        self.assertEqual(r['value'], 1)
Exemplo n.º 16
0
    def test_simple_repr(self):
        domain = VariableDomain("d", "d", [1, 2, 3, 4])
        v = ExternalVariable("v", domain, value=1)

        r = simple_repr(v)

        self.assertEqual(r["name"], "v")
        self.assertEqual(r["value"], 1)
def test_message_factory_serialization():

    MyMessage = message_type('my_msg', ['foo', 'bar'])
    msg = MyMessage(42, 21)
    r = simple_repr(msg)
    print(r)
    obtained = from_repr(r)
    assert msg == obtained
def test_message_factory_serialization():

    MyMessage = message_type("my_msg", ["foo", "bar"])
    msg = MyMessage(42, 21)
    r = simple_repr(msg)
    print(r)
    obtained = from_repr(r)
    assert msg == obtained
Exemplo n.º 19
0
def test_path_serialization():

    p = ("a2", "a3", "__hosting__")
    r = simple_repr(p)
    print(r)

    assert "__qualname__" in r
    assert r[0] == "a2"
Exemplo n.º 20
0
def test_pathtable_serialize():
    p1 = ("a2", "a3")
    p2 = ("a2", "a4")
    table = [(2, p1), (3, p2)]

    r = simple_repr(table)
    assert r

    print(r)
Exemplo n.º 21
0
def test_from_repr():

    a = AlgorithmDef("maxsum", {"stability": 0.01}, "min")

    r = simple_repr(a)
    a2 = from_repr(r)

    assert a == a2
    assert a2.param_value("stability") == 0.01
Exemplo n.º 22
0
def test_simple_repr():

    a = AlgorithmDef("maxsum", {"stability": 0.01}, "min")

    r = simple_repr(a)

    assert r["algo"] == "maxsum"
    assert r["mode"] == "min"
    assert r["params"]["stability"] == 0.01
Exemplo n.º 23
0
    def test_simple_repr(self):

        a = AlgoDef('maxsum', 'min', stability_coef=0.01)

        r = simple_repr(a)

        self.assertEqual(r['algo'], 'maxsum')
        self.assertEqual(r['mode'], 'min')
        self.assertEqual(r['params']['stability_coef'], 0.01)
Exemplo n.º 24
0
    def test_from_repr(self):

        a = AlgoDef('maxsum', 'min', stability_coef=0.01)

        r = simple_repr(a)
        a2 = from_repr(r)

        self.assertEqual(a, a2)
        self.assertEqual(a2.param_value('stability_coef'), 0.01)
Exemplo n.º 25
0
    def test_simple_repr_list_based_domain(self):
        v = Variable("v1", [1, 2, 3])

        r = simple_repr(v)
        self.assertEqual(r["name"], "v1")
        self.assertEqual(r["initial_value"], None)

        # domain values are serialized as tuple
        self.assertIn(1, r["domain"]["values"])
Exemplo n.º 26
0
    def test_simple_repr_with_expression_function(self):
        domain = VariableDomain("d", "d", [1, 2, 3, 4])
        cost_func = ExpressionFunction("v / 2")
        v = VariableNoisyCostFunc("v", domain, cost_func=cost_func)

        r = simple_repr(v)

        self.assertEqual(r["name"], "v")
        self.assertEqual(r["cost_func"]["expression"], "v / 2")
Exemplo n.º 27
0
    def test_simple_repr(self):
        d = Domain("d", "foo", [1, 2, 3])
        r = simple_repr(d)
        print(r)

        self.assertEqual(r["__qualname__"], "Domain")
        self.assertEqual(r["__module__"], "pydcop.dcop.objects")
        self.assertEqual(r["name"], "d")
        self.assertEqual(r["domain_type"], "foo")
Exemplo n.º 28
0
    def test_simple_repr_with_expression_function(self):
        domain = VariableDomain('d', 'd', [1, 2, 3, 4])
        cost_func = ExpressionFunction('v / 2')
        v = VariableNoisyCostFunc('v', domain, cost_func=cost_func)

        r = simple_repr(v)

        self.assertEquals(r['name'], 'v')
        self.assertEquals(r['cost_func']['expression'], 'v / 2')
    def test_mapping_for_corresponding_attribute(self):
        class MappingAttr(SimpleRepr):
            def __init__(self, a1):
                self._repr_mapping = {'a1': 'foo'}
                self.foo = a1

        o = MappingAttr('bar')
        r = simple_repr(o)
        self.assertEqual(r['a1'], 'bar')
Exemplo n.º 30
0
def test_pathtable_unserialize():
    p1 = ("a2", "a3")
    p2 = ("a2", "a4")
    table = [(2, p1), (3, p2)]

    r = simple_repr(table)
    assert r

    obtained = from_repr(r)
    assert obtained == table