dominiontabs icon indicating copy to clipboard operation
dominiontabs copied to clipboard

Unit test improvements

Open mbbush opened this issue 6 months ago • 1 comments

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:

  1. Read the card data from the "db"
  2. Transform the config object from the command line into the version that's used in the code. This is mostly done in the parse_opts and clean_opts functions in config_options.py, but there's also some changes to the config made inside main.py.
  3. Select and sort the list of Card objects to render, along with appropriate metadata.
  4. Render the actual PDF.

There are a few exceptions, but this mostly corresponds to the code in

  1. db.py
  2. config_options.py
  3. main.py
  4. 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 config object that comes out of parse_opts and clean_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.

mbbush avatar May 07 '25 18:05 mbbush

Yes!

sumpfork avatar May 07 '25 18:05 sumpfork