run_tests.py 1.04 KB
Newer Older
1
2
3
4
5
6
import sys
import os
import django
import tempfile
import unittest

Michael Salim's avatar
Michael Salim committed
7
import balsam
8

9
10
11
12
13
14
15
def set_permissions(top):
    os.chmod(top, 0o755)
    for root,subdirs,files in os.walk(top):
        for dir in (os.path.join(root, s) for s in subdirs):
            os.chmod(dir, 0o755)
        for file in (os.path.join(root, f) for f in files):
            os.chmod(file, 0o644)
16

17
def main():
18
    
19
20
21
22
    test_dir = os.path.abspath(os.path.dirname(balsam.__file__))
    tempdir = tempfile.TemporaryDirectory(dir=test_dir, prefix="testdata_")
    test_directory = tempdir.name 

23
    os.environ['BALSAM_TEST_DIRECTORY'] = test_directory
24
    os.environ['BALSAM_TEST']='1'
25
    os.environ['DJANGO_SETTINGS_MODULE'] = 'balsam.django_config.settings'
26
27
    django.setup()

28
    set_permissions(test_directory)
29

30
31
32
33
34
35
36
    loader = unittest.defaultTestLoader
    if len(sys.argv) > 1:
        names = sys.argv[1:]
        suite = loader.loadTestsFromNames(names)
    else:
        suite = loader.discover('tests')
    unittest.TextTestRunner(verbosity=2).run(suite)
37
38

if __name__ == "__main__":
39
    main()