Ticket #18744: test.py

File test.py, 1011 bytes (added by ty@…, 12 years ago)
Line 
1from subprocess import Popen, PIPE
2from django.core.files.temp import NamedTemporaryFile
3
4def test_no_close():
5 print '*** Testing lessc without closing temp file. ***'
6 temp = NamedTemporaryFile(mode='r+', suffix='.css')
7 run_proc('lessc', 'test.less', temp.name)
8 print 'FILE:', read_file(temp.name)
9 print
10
11def test_close():
12 print '*** Testing lessc after closing temp file. ***'
13 temp = NamedTemporaryFile(mode='r+', suffix='.css')
14 temp.close()
15 run_proc('lessc', 'test.less', temp.name)
16 print 'FILE:', read_file(temp.name)
17 print
18
19def run_proc(*args):
20 print args
21 proc = Popen(args, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
22 ret_code = proc.wait()
23 out, err = proc.communicate()
24 print 'Returned:', ret_code
25 print 'OUT:', out
26 print 'ERR:', err
27
28def read_file(filename):
29 with open(filename, 'r') as fd:
30 return fd.read()
31
32# Fails with permission error
33test_no_close()
34# Succeeds
35test_close()
Back to Top