Exemple #1
0
    def test_missing_type(self):

        with pytest.raises(MissingTypeException):
            loads("", Dict)

        with pytest.raises(MissingTypeException):
            loads("", List)
Exemple #2
0
    def test_optional(self):
        @dataclass
        class A:
            b: Optional[str] = None

        conf = ""
        assert loads(conf, A) == A(b=None)

        conf = """
        b = test
        """
        assert loads(conf, A) == A(b="test")
Exemple #3
0
    def test_empty_list(self):
        @dataclass
        class A:
            b: List[str] = field(default_factory=list)

        conf = ""
        assert loads(conf, A) == A(b=[])
Exemple #4
0
    def test_relativedelta(self):
        @dataclass
        class A:
            a: relativedelta

        conf = """
        a = 2d
        """
        assert loads(conf, A) == A(a=relativedelta(days=2))
Exemple #5
0
    def test_yaml(self):
        @dataclass
        class A:
            b: str

        conf = """
        b: c
        """
        assert loads(conf, A) == A(b="c")
Exemple #6
0
    def test_simple(self):
        @dataclass
        class A:
            a: str

        conf = """
        a = test
        """
        assert loads(conf, A) == A(a="test")
Exemple #7
0
    def test_union(self):
        @dataclass
        class B:
            a: str

        @dataclass
        class A:
            b: Union[B, str]

        conf = """
        b {
            a = test
        }
        """
        assert loads(conf, A) == A(b=B(a="test"))

        conf = """
        b = test
        """
        assert loads(conf, A) == A(b="test")
Exemple #8
0
    def test_dict(self):
        @dataclass
        class A:
            a: Dict[str, str]

        conf = """
        a {
            b = test
        }
        """
        assert loads(conf, A) == A(a={"b": "test"})
Exemple #9
0
    def test_list(self):
        @dataclass
        class A:
            a: List[str]

        conf = """
        a = [
            test
        ]
        """
        assert loads(conf, A) == A(a=["test"])
Exemple #10
0
    def test_json(self):
        @dataclass
        class A:
            b: str

        conf = """
        {
            "b": "c"
        }
        """
        assert loads(conf, A) == A(b="c")
Exemple #11
0
    def test_nested(self):
        @dataclass
        class B:
            a: str

        @dataclass
        class A:
            b: B

        conf = """
        b {
            a = test
        }
        """
        assert loads(conf, A) == A(b=B(a="test"))
Exemple #12
0
    def test_root_dict(self):

        conf = """
        b: c
        """
        assert loads(conf, Dict[str, str]) == dict(b="c")
Exemple #13
0
    def test_default_value(self):
        @dataclass
        class A:
            b: str = "c"

        assert loads("", A) == A(b="c")