Skip to content

Commit

Permalink
docs: Update wrapper documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tefra committed Mar 21, 2024
1 parent 45f8a06 commit 1371297
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/fixtures/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ChoiceType:
{"name": "float", "type": float},
{"name": "qname", "type": QName},
{"name": "union", "type": Type["UnionType"], "namespace": "foo"},
{"name": "tokens", "type": List[Decimal], "tokens": True},
{"name": "tokens", "type": List[Decimal], "tokens": True, "default_factory": list},
{
"wildcard": True,
"type": object,
Expand Down
1 change: 1 addition & 0 deletions tests/formats/dataclass/models/test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def test_build_with_choice_field(self):
types=(Decimal,),
tokens_factory=list,
derived=True,
default=list,
factory=list,
namespaces=("bar",),
),
Expand Down
29 changes: 26 additions & 3 deletions tests/formats/dataclass/parsers/test_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
TypeD,
UnionType,
)
from tests.fixtures.wrapper import Wrapper
from tests.fixtures.wrapper import Charlie, Wrapper
from xsdata.exceptions import ParserError
from xsdata.formats.dataclass.models.generics import AnyElement, DerivedElement
from xsdata.formats.dataclass.parsers import DictDecoder
Expand Down Expand Up @@ -106,10 +106,26 @@ def test_decode_with_fail_on_converter_warnings(self):
)

def test_decode_wrapper(self):
data = {"alphas": {"alpha": "value"}}
data = {
"alphas": {"alpha": "value"},
"bravos": {"bravo": [1, 2]},
"charlies": {
"charlie": [
{"value": "first", "lang": "en"},
{"value": "second", "lang": "en"},
]
},
}

actual = self.decoder.decode(data, Wrapper)
expected = Wrapper(alpha="value")
expected = Wrapper(
alpha="value",
bravo=[1, 2],
charlie=[
Charlie(value="first", lang="en"),
Charlie(value="second", lang="en"),
],
)
self.assertEqual(expected, actual)

def test_verify_type(self):
Expand Down Expand Up @@ -383,3 +399,10 @@ def test_find_var(self):
xml_vars = meta.get_all_vars()
self.assertIsNone(self.decoder.find_var(xml_vars, "a", [1, 2]))
self.assertEqual(xml_vars[0], self.decoder.find_var(xml_vars, "a", {"x": 1}))

meta = self.decoder.context.build(Wrapper)
xml_vars = meta.get_all_vars()
self.assertIsNone(self.decoder.find_var(xml_vars, "charlies", {}))
self.assertEqual(
xml_vars[0], self.decoder.find_var(xml_vars, "alphas", {"alpha": "foo"})
)

0 comments on commit 1371297

Please sign in to comment.