TestDictableNamedtuple

class tests.test_collections.TestDictableNamedtuple(methodName='runTest')[source]

Test the function dictable_namedtuple() and compare it against collections.namedtuple() to ensure that dictable_namedtuple’s should be backwards compatible with code that takes namedtuple’s.

Also tests new functionality that only exists in dictable_namedtuple’s, and compares it against standard namedtuples, including:

  • Test getting by item/key, i.e. john['first_name'], and confirm normal namedtuples raise exceptions

  • Test setting new item/key’s and attributes item['color'] = 'Brown', and confirm normal namedtuples raise exceptions

  • Test casting dictable namedtuple’s to dict’s dict(item), and confirm normal namedtuples raise exceptions

__init__(methodName='runTest')

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

Methods

Methods

setUp()

At the start of each test, reset example_items, Item and NmItem in-case any tests have modified them

test_asdict()

Test ._asdict works on both dictable + normal namedtuple

test_convert()

Test convert_dictable_namedtuple converts example namedtuple instance into a dictable_namedtuple instance

test_dict_cast()

Test casting dictable_namedtuple using dict works as expected, but fails on normal namedtuple

test_get_attr()

Confirm getting attributes is equivalent on dictable namedtuple to standard namedtuple

test_get_index()

Test we can access by integer index on dictable + normal namedtuple

test_get_item()

Test we can access named items on on dictable namedtuple while standard namedtuple raises exceptions

test_metadata()

Confirm sameness of class/instance metadata such as class name/qualname, module name, and stringification between dictable_namedtuple() and collections.namedtuple()

test_set_attr()

Test that we can create the new attribute color on the dictable_namedtuple

test_set_item()

Test that we can create the new item/key color on the dictable_namedtuple

test_subclass()

Test subclass_dictable_namedtuple converts NmItem into a dictable_namedtuple type

Attributes

Attributes

example_items

A tuple containing an instance of both Item and NmItem