]>
Raphaƫl G. Git Repositories - youtubedl/blob - test/helper.py
   9 import youtube_dl
.extractor
 
  10 from youtube_dl 
import YoutubeDL
 
  14     youtube_dl
._setup
_opener
(timeout
=10) 
  17 def get_params(override
=None): 
  18     PARAMETERS_FILE 
= os
.path
.join(os
.path
.dirname(os
.path
.abspath(__file__
)), 
  20     with io
.open(PARAMETERS_FILE
, encoding
='utf-8') as pf
: 
  21         parameters 
= json
.load(pf
) 
  23         parameters
.update(override
) 
  28     """ Remove a file if it exists """ 
  31     except OSError as ose
: 
  32         if ose
.errno 
!= errno
.ENOENT
: 
  36 class FakeYDL(YoutubeDL
): 
  37     def __init__(self
, override
=None): 
  38         # Different instances of the downloader can't share the same dictionary 
  39         # some test set the "sublang" parameter, which would break the md5 checks. 
  40         params 
= get_params(override
=override
) 
  41         super(FakeYDL
, self
).__init
__(params
) 
  44     def to_screen(self
, s
, skip_eol
=None): 
  47     def trouble(self
, s
, tb
=None): 
  50     def download(self
, x
): 
  53     def expect_warning(self
, regex
): 
  54         # Silence an expected warning matching a regex 
  55         old_report_warning 
= self
.report_warning
 
  56         def report_warning(self
, message
): 
  57             if re
.match(regex
, message
): return 
  58             old_report_warning(message
) 
  59         self
.report_warning 
= types
.MethodType(report_warning
, self
) 
  62     for ie 
in youtube_dl
.extractor
.gen_extractors(): 
  63         t 
= getattr(ie
, '_TEST', None) 
  65             t
['name'] = type(ie
).__name
__[:-len('IE')] 
  67         for t 
in getattr(ie
, '_TESTS', []): 
  68             t
['name'] = type(ie
).__name
__[:-len('IE')] 
  72 md5 
= lambda s
: hashlib
.md5(s
.encode('utf-8')).hexdigest()