summaryrefslogtreecommitdiffhomepage
path: root/test/test_python_atexit.py
blob: 6c1b636511a43fccabe19728addf42c2b151379e (plain) (blame)
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
57
58
59
60
61
62
63
64
65
import os
import time
import unittest
import unit

class TestUnitApplication(unit.TestUnitControl):

    def setUpClass():
        u = unit.TestUnit()

        u.check_modules('python')
        u.check_version('0.3')

    def test_python_application(self):
        code, name = """
import atexit

def create_file():
    open('%s', 'w')

atexit.register(create_file)

def application(env, start_response):
    start_response('200', [('Content-Length', '0')])
    return []

""" % (self.testdir + '/atexit'), 'py_app'

        self.python_application(name, code)

        self.put('/', """
            {
                "listeners": {
                    "*:7080": {
                        "application": "app"
                    }
                },
                "applications": {
                    "app": {
                        "type": "python",
                        "workers": 1,
                        "path": "%s",
                        "module": "wsgi"
                    }
                }
            }
            """ % (self.testdir + '/' + name))

        unit.TestUnitHTTP.get()

        self.put('/', """
            {
                "listeners": {},
                "applications": {}
            }
            """)

        time.sleep(0.2)   # wait for 'atexit' file

        self.assertEqual(os.path.exists(self.testdir + '/atexit'), True,
            'python atexit')


if __name__ == '__main__':
    unittest.main()