Skip to content

Commit

Permalink
Move functions to create and delete test file to module
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciusban committed Oct 6, 2013
1 parent 23f6b4f commit cadb76b
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions modules/web2pytest/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python

"""Infrastructure to run an Web2py application under test environment.
We create a temporary file to indicate the application she's running
under test.
By default this file is created in ramdisk (Ubuntu) to speed up
execution.
Web2py applications need this external injection mainly to know
where to create their test database.
Note: if you don't use webclient interface to run your tests, you don't
need to use this module.
"""

import os

#default_dirname = "/tmp"
default_dirname = "/dev/shm/web2py_test" # Ubuntu native ramdisk is faster
default_filename = "web2py_test_indicator"

test_filename = None


def create_testfile(dirname=None, filename=None):
"""Creates a temp file to tell application she's running under a
test environment.
"""

dirname = dirname or default_dirname
filename = filename or default_filename
test_filename = "%s/%s.tmp" % (dirname, filename)

os.mkdir(dirname)

with open(test_filename, "w+") as f:
f.write("web2py running in test mode.")


def delete_testfile():
os.remove(test_filename)

0 comments on commit cadb76b

Please sign in to comment.