-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now marshalling OptionalExternalTypes
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from typing import Optional | ||
from unittest import TestCase | ||
|
||
import marshy | ||
from marshy import ExternalType | ||
from marshy.types import ExternalItemType | ||
|
||
|
||
class TestMarshallJsonStr(TestCase): | ||
|
||
def test_marshall_external_type(self): | ||
value = {"foo": [1, True, "bar"]} | ||
dumped = marshy.dump(value, ExternalType) | ||
self.assertEqual('{"foo": [1, true, "bar"]}', dumped) | ||
result = marshy.load(ExternalType, dumped) | ||
self.assertEqual(value, result) | ||
|
||
def test_marshall_external_item_type(self): | ||
value = {"foo": [1, True, "bar"]} | ||
dumped = marshy.dump(value, ExternalItemType) | ||
self.assertEqual('{"foo": [1, true, "bar"]}', dumped) | ||
result = marshy.load(ExternalItemType, dumped) | ||
self.assertEqual(value, result) | ||
|
||
def test_marshall_optional_external_item_type(self): | ||
value = {"foo": [1, True, "bar"]} | ||
dumped = marshy.dump(value, Optional[ExternalItemType]) | ||
self.assertEqual('{"foo": [1, true, "bar"]}', dumped) | ||
result = marshy.load(Optional[ExternalItemType], dumped) | ||
self.assertEqual(value, result) | ||
dumped = marshy.dump(None, Optional[ExternalItemType]) | ||
self.assertEqual("null", dumped) | ||
result = marshy.load(Optional[ExternalType], dumped) | ||
self.assertIsNone(result) |