This is an entry for NaNoGenMo 2022. It is an experiment in the (mis)use of factory_boy and Faker, Python packages used to create test fixtures.
For those not already familiar with software testing, the basic idea
is that by writing (and automating) tests of program components and
the overall function of a program, you can be (more) confident that a
given change to your program does not add (as many) new bugs. You
frequently want to test the operation of the program or its components
with particular inputs, and although you might hand-code these inputs,
known as fixtures, it is easier to use a system like factory_boy
to
generate them for you. Faker
is used by factory_boy
to produce
fake data, like names or addresses, to populate these fixtures.
The misuse of factory_boy
and Faker
is to create a "factory" not
for producing test fixtures, but for producing a "novel"—a text of at
least 50,000 words. This code creates
factories for Novel, Chapters,
Paragraphs, Sentences, Characters, and Titles, from bare
specifications called objects. (In other
contexts, the objects would be the actual data models used by the
application under test.) The factories at the bottom level—Sentences,
Titles, and Characters—use Faker
to generate random text; Characters
come from the person
Provider,
Titles from the lorem
Provider,
and Sentences come from a custom
Provider that uses a combination of
Characters, the lorem Provider, and, from
corpora, included here as a git
submodule, American Time Use Survey activities, Canadian
municipalities, household objects, and adjectives.
The output is entirely random, unless you add a --seed
option. Then
the output is random but repeatable :) and the seed used is recorded
in the frontmatter of the Markdown output. (A further development
could be to record the seeds used in a wholly-random run of the
program, which can probably not be reduced to a simple string of
text.)
A sample output in Markdown format is in this repo, as well as PDF and epub versions. Earlier versions' outputs are available in the same directory.
Clone this repo, install
Poetry, optionally
install Pandoc and pdflatex
(see instructions for your OS at the Pandoc installation page), then
run
cd a-novel-factory
git submodule init
git submodule update
poetry install
poetry run new_novel
This will generate Markdown, PDF, and epub files. In the absence of
Pandoc, only Markdown will be produced. (Note that on some Macs, with
Pandoc installed, if you get an error like pandoc: pdflatex: createProcess: posix_spawnp: illegal operation (Inappropriate ioctl for device)
, you may need to install or reinstall pdflatex
,
possibly with brew reinstall --cask basictex
.)
Thanks to @lizadaly for telling us about NaNoGenMo!