#!/usr/bin/env python
import os
import stat

virtual_env_path = os.getenv('VIRTUAL_ENV')
assert virtual_env_path, 'VIRTUAL_ENV environment variable not found'

found = False
for root, dirs, files in os.walk(virtual_env_path):
    if root.endswith('/pydf/bin') and files == ['wkhtmltopdf']:
        assert len(files) == 1, 'more than file: %r' % files
        path = os.path.join(root, files[0])
        st = os.stat(path)
        perms = oct(st[stat.ST_MODE])[-3:]
        assert perms == '775', 'wrong file permissions for "%s": "%s"' % (path, perms)
        print('"%s" has correct permissions 775' % path)
        found = True
        break

if not found:
    raise Exception('wkhtmltopdf binary not found')

@@ -37,13 +37,127 @@
 rt s
-tat%0A%0A
+ys%0Aimport stat%0A%0Aif 'setup.py' not in sys.argv:%0A    # file permissions should not be checked during %60setup.py test%60%0A    
 virt
@@ -196,16 +196,20 @@
 L_ENV')%0A
+    
 assert v
@@ -270,17 +270,81 @@
  found'%0A
-%0A
+    print('using VIRTUAL_ENV path %22%25s%22' %25 virtual_env_path)%0A%0A    
 found = 
@@ -349,16 +349,20 @@
 = False%0A
+    
 for root
@@ -405,16 +405,20 @@
 _path):%0A
+    
     if r
@@ -477,24 +477,28 @@
 '%5D:%0A        
+ 
+   
 assert len(f
@@ -538,16 +538,20 @@
 %25 files%0A
+    
         
@@ -594,16 +594,20 @@
         
+    
 st = os.
@@ -613,24 +613,28 @@
 .stat(path)%0A
+    
         perm
@@ -664,16 +664,20 @@
 %5D)%5B-3:%5D%0A
+    
         
@@ -759,24 +759,28 @@
 ms)%0A        
+   
+ 
 print('%22%25s%22 
@@ -820,24 +820,28 @@
 th)%0A        
+    
 found = True
@@ -853,15 +853,23 @@
     
+   
+ 
 break%0A%0A
+    
 if n
@@ -886,23 +886,32 @@
     
+  
+  
 raise 
-Exception
+AssertionError
 ('wk

correct when check file permissions is called