Exemplo n.º 1
0
    def test_from_attr_value(self):
        a = Attr.from_attr_value("attr", "value", compare=False)
        assert a.name == "attr"
        assert a.default == "value"
        assert a.compare is False

        a = Attr.from_attr_value("attr", a)
        assert a.name == "attr"
        assert a.default == "value"
        assert a.compare is False

        f = dataclasses.field(
            default="value",
            init=False,
            repr=False,
            compare=False,
            hash=False,
            metadata={"foo": "bar"},
        )
        a = Attr.from_attr_value("attr", f)
        assert a.name == "attr"
        for attr in {
                "default",
                "default_factory",
                "init",
                "repr",
                "compare",
                "hash",
                "metadata",
        }:
            a_value = getattr(a, attr)
            f_value = getattr(f, attr)
            assert (a_value == f_value
                    or a_value is MISSING and f_value is dataclasses.MISSING)
Exemplo n.º 2
0
 def attr_spec2(self):
     return Attr.from_attr_value("attr", "value", type=List[Spec])
Exemplo n.º 3
0
 def attr_spec(self):
     return Attr.from_attr_value("attr",
                                 "value",
                                 type=List[str],
                                 prepare_item=lambda self, x: str(x))
Exemplo n.º 4
0
 def attr_spec2(self):
     return Attr.from_attr_value("attr", "value", type=KeyedSet[Spec, str])
Exemplo n.º 5
0
 def attr_spec2(self):
     return Attr.from_attr_value("attr", "value", type=Dict[str, Spec])