1 | from subprocess import Popen, PIPE
|
---|
2 | from django.core.files.temp import NamedTemporaryFile
|
---|
3 |
|
---|
4 | def 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 |
|
---|
11 | def 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 |
|
---|
19 | def 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 |
|
---|
28 | def read_file(filename):
|
---|
29 | with open(filename, 'r') as fd:
|
---|
30 | return fd.read()
|
---|
31 |
|
---|
32 | # Fails with permission error
|
---|
33 | test_no_close()
|
---|
34 | # Succeeds
|
---|
35 | test_close()
|
---|