]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/test_swfinterp.py
   2 from __future__ 
import unicode_literals
 
   4 # Allow direct execution 
   8 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
)))) 
  17 from youtube_dl
.swfinterp 
import SWFInterpreter
 
  20 TEST_DIR 
= os
.path
.join( 
  21     os
.path
.dirname(os
.path
.abspath(__file__
)), 'swftests') 
  24 class TestSWFInterpreter(unittest
.TestCase
): 
  28 def _make_testfunc(testfile
): 
  29     m 
= re
.match(r
'^(.*)\.(as)$', testfile
) 
  35         as_file 
= os
.path
.join(TEST_DIR
, testfile
) 
  36         swf_file 
= os
.path
.join(TEST_DIR
, test_id 
+ '.swf') 
  37         if ((not os
.path
.exists(swf_file
)) or 
  38                 os
.path
.getmtime(swf_file
) < os
.path
.getmtime(as_file
)): 
  41                 subprocess
.check_call([ 
  42                     'mxmlc', '-output', swf_file
, 
  43                     '-static-link-runtime-shared-libraries', as_file
]) 
  44             except OSError as ose
: 
  45                 if ose
.errno 
== errno
.ENOENT
: 
  46                     print('mxmlc not found! Skipping test.') 
  50         with open(swf_file
, 'rb') as swf_f
: 
  51             swf_content 
= swf_f
.read() 
  52         swfi 
= SWFInterpreter(swf_content
) 
  54         with io
.open(as_file
, 'r', encoding
='utf-8') as as_f
: 
  55             as_content 
= as_f
.read() 
  59                 r
'(?m)^//\s*%s:\s*(.*?)\n' % re
.escape(key
), as_content
) 
  61                 raise ValueError('Cannot find %s in %s' % (key
, testfile
)) 
  62             return json
.loads(m
.group(1)) 
  64         input_args 
= _find_spec('input') 
  65         output 
= _find_spec('output') 
  67         swf_class 
= swfi
.extract_class(test_id
) 
  68         func 
= swfi
.extract_function(swf_class
, 'main') 
  69         res 
= func(input_args
) 
  70         self
.assertEqual(res
, output
) 
  72     test_func
.__name
__ = str('test_swf_' + test_id
) 
  73     setattr(TestSWFInterpreter
, test_func
.__name
__, test_func
) 
  76 for testfile 
in os
.listdir(TEST_DIR
): 
  77     _make_testfunc(testfile
) 
  79 if __name__ 
== '__main__':