File: testbase.py

package info (click to toggle)
myghtyutils 0.52-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 180 kB
  • ctags: 394
  • sloc: python: 1,761; makefile: 47
file content (56 lines) | stat: -rw-r--r-- 1,616 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import unittest, os, sys

import myghty.util as util

class MyghtyTest(unittest.TestCase):
    def __init__(self, *args, **params):
        unittest.TestCase.__init__(self, *args, **params)
        
        # make ourselves a Myghty environment
        self.root = os.path.abspath(os.path.join(os.getcwd(), 'testroot'))
        
        # some templates
        self.htdocs = os.path.join(self.root, 'htdocs')
        
        # some more templates
        self.components = os.path.join(self.root, 'components')
        
        # data dir for cache, sessions, compiled
        self.cache = os.path.join(self.root, 'cache')
        
        # lib dir for some module components
        self.lib = os.path.join(self.root, 'lib')
        sys.path.insert(0, self.lib)
        
        for path in (self.htdocs, self.components, self.cache, self.lib):
            util.verify_directory(path)
        
        self.class_set_up()

    def class_set_up(self):
        pass

    def class_tear_down(self):
        pass
        
    def __del__(self):
        self.class_tear_down()
        
    def create_file(self, dir, name, contents):
        file = os.path.join(dir, name)
        f = open(file, 'w')
        f.write(contents)
        f.close()
        
    def create_directory(self, dir, path):
        util.verify_directory(os.path.join(dir, path))
        
    def remove_file(self, dir, name):
        if os.access(os.path.join(dir, name), os.F_OK):
            os.remove(os.path.join(dir, name))


def runTests(suite):
    runner = unittest.TextTestRunner(verbosity = 2, descriptions =1)
    runner.run(suite)