dominiontabs
dominiontabs copied to clipboard
Unit test improvements
I recently came back to this project after several years because I bought new dominion sets. I'm pleased to see that there are unit tests, but there's a lot of room for improvement. Fortunately, the existing code is structured in such a way that makes it relatively easy to test. I want to document some of my suggestions here. Time/interest permitting, I may go ahead and implement some of these improvements myself and open a PR.
Broadly speaking, the code does four things:
- Read the card data from the "db"
- Transform the config object from the command line into the version that's used in the code. This is mostly done in the
parse_optsandclean_optsfunctions inconfig_options.py, but there's also some changes to the config made insidemain.py. - Select and sort the list of
Cardobjects to render, along with appropriate metadata. - Render the actual PDF.
There are a few exceptions, but this mostly corresponds to the code in
- db.py
- config_options.py
- main.py
- draw.py
Ideally, each of those files would have its own unit tests that test the logic that happens in that file, while "mocking" the dependencies, such as the other files or reportlab. I suspect this will be substantially harder for draw.py.
So unit tests could, for example:
- Validate that given combinations of config options are interpreted correctly, by making assertions on the
configobject that comes out ofparse_optsandclean_opts. - Validate that for a given config object, the list of cards passed into the drawing functions is expected.
- Validate that for a few specific configurations/short list of cards, the draw.py methods give the right result.
Yes!