def test_4() -> None: xml = to_xml(BookDict( isbn='0134757599', title='Refactoring, 2e', authors=['Martin Fowler', 'Kent Beck'], pagecount=478)) assert xml == XML_SAMPLE
def test_1() -> None: xml = to_xml({ 'isbn': '0134757599', 'title': 'Refactoring, 2e', 'authors': ['Martin Fowler', 'Kent Beck'], 'pagecount': 478, }) assert xml == XML_SAMPLE
def test_8() -> None: book_data: BookDict = { 'isbn': '0134757599', 'title': 'Refactoring, 2e', 'authors': ['Martin Fowler', 'Kent Beck'], 'pagecount': 478, } xml = to_xml(book_data) assert xml == XML_SAMPLE
def test_6() -> None: book_data = dict( isbn='0134757599', title='Refactoring, 2e', authors=['Martin Fowler', 'Kent Beck'], pagecount=478 ) xml = to_xml(cast(BookDict, book_data)) # cast needed assert xml == XML_SAMPLE
def test_3() -> None: xml = to_xml( BookDict( dict( [ # Expected keyword arguments, {...}, or dict(...) in TypedDict constructor ('isbn', '0134757599'), ('title', 'Refactoring, 2e'), ('authors', ['Martin Fowler', 'Kent Beck']), ('pagecount', 478), ]))) assert xml == XML_SAMPLE
def demo() -> None: NOT_BOOK_JSON = """ {"title": "Andromeda Strain", "flavor": "pistachio", "authors": true} """ not_book = from_json(NOT_BOOK_JSON) # <1> if TYPE_CHECKING: # <2> reveal_type(not_book) reveal_type(not_book['authors']) print(not_book) # <3> print(not_book['flavor']) # <4> xml = to_xml(not_book) # <5> print(xml) # <6>
def test_load_book() -> None: book_data = from_json(BOOK_JSON) xml = to_xml(book_data) assert xml == XML_SAMPLE
def test_load_book_0() -> None: book_data: BookDict = json.loads(BOOK_JSON) # typed var xml = to_xml(book_data) assert xml == XML_SAMPLE