Jaymon / testdata

Python module to make testing easier, it can generate random data like names and text, run commands, fetch urls, create files and directories, and more
MIT License
10 stars 0 forks source link

Better interface for creating different types of files #89

Open Jaymon opened 2 years ago

Jaymon commented 2 years ago

I've had a few times come up now where I wanted to create a regular file and an image to test some server code, I've had to do something like this each time:

dirpath = testdata.create_files({
    "foo.txt": "this is foo.txt",
    "bar/che.txt": "this is che.txt",
})
imagepath = testdata.create_jpg("baz.jpg", dirpath)

server = testdata.create_fileserver({}, dirpath)

There are couple ways this could be better, one is I could have the file dict take a callback as the value, which would take the path and the base directory, so something like this:


def create_image(path, tmpdir):
    return testdata.create_jpg(path, tmpdir)

testdata.create_files({
    "foo.jpg": create_image
})

It would also be nice if anything that took a file_dict could also just take a Dirpath instance and use that as tmpdir:

basedir = testdata.create_files({
    "foo.jpg": testdata.create_jpg
})

server = testdata.create_fileserver(basedir)

I think adding both of these will make the file creation interface more fluid