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

directory testdata class #24

Closed Jaymon closed 6 years ago

Jaymon commented 6 years ago

This is the one from Wishlist:

class BaseTestCase(TestCase):
    def get_body(self, filename):
        basepath = os.path.abspath(os.path.expanduser(os.path.dirname(__file__)))
        path = os.path.join(basepath, "testdata", filename)
        with codecs.open(path, encoding='utf-8', mode='r') as f:
        #with open(path) as f:
            body = f.read()
        return body

but I've done a very similar thing in a few different projects, basically I have a testdata directory that contains files that my tests will parse, so something like:

Contents(str):
    directory = "/some/environ/setting?"
    def __new__(cls, fileroot):
        # glob for directory/fileroot.* and load that into the contents of this string