Thanks Carl Meyer and Tim Graham for contributing to the patch.
This is preparation for landing the template-based widget rendering patch and goes a long way to making these tests more useful for future development. The old doctest heritage is strong here.