In my #python project #xiaolongdictionary I had need for generating example data. I did not want to add more dependencies for that, so I took some time to create a function, that takes a TypedDict type and a dictionary of "constraints" to constrain the produced values and output a "factory", that can be called and outputs example values.

https://codeberg.org/ZelphirKaltstahl/xiaolong-dictionary/src/commit/9437f974e8f59a77e0052d26ee6cc10641052313/test/factories.py

It does not cover all the cases that one could imagine, but seems to cover all of mine.

#test #pytest #factory #programming #coding

xiaolong-dictionary/test/factories.py at 9437f974e8f59a77e0052d26ee6cc10641052313

xiaolong-dictionary - Xiaolong Dictionary — A GUI application to help you learn vocabulary of (probably) any language. It is written in Python using tkinter, and runs on GNU/Linux, Windows, and probably also MacOS.

Codeberg.org