summaryrefslogtreecommitdiffhomepage
path: root/test/test_python_atexit.py
diff options
context:
space:
mode:
authorAndrey Zelenkov <zelenkov@nginx.com>2018-01-15 16:06:33 +0300
committerAndrey Zelenkov <zelenkov@nginx.com>2018-01-15 16:06:33 +0300
commit43e36d91e5501fa5df33e1cbc6cddabae6fef5e8 (patch)
tree0261e97545d9416cb25aa8d3e51ec20a9e28e45f /test/test_python_atexit.py
parentb217a1e058715b2769f5ac71af22b41ff7616319 (diff)
downloadunit-43e36d91e5501fa5df33e1cbc6cddabae6fef5e8.tar.gz
unit-43e36d91e5501fa5df33e1cbc6cddabae6fef5e8.tar.bz2
Tests: added test for 'atexit'.
Diffstat (limited to '')
-rw-r--r--test/test_python_atexit.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/test_python_atexit.py b/test/test_python_atexit.py
new file mode 100644
index 00000000..28b6f67b
--- /dev/null
+++ b/test/test_python_atexit.py
@@ -0,0 +1,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 OK', [('Content-Type','text/html')])
+ return [b'body']
+
+""" % (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)
+
+ self.assertEqual(os.path.exists(self.testdir + '/atexit'), True,
+ 'python atexit')
+
+
+if __name__ == '__main__':
+ unittest.main()