X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=inline;f=test%2Fgentests.py;h=9352d6d94931812f1cfb79519801d52bd1a5456d;hb=e387eb5aba241e55e38e8bd5b57cc76b082ac6b9;hp=8a76ff9f71575fc98ca5f9eb701d0daeae81df34;hpb=cdab8aa389a81b82ed3a2d72b05df5445d4b0668;p=youtube-dl diff --git a/test/gentests.py b/test/gentests.py index 8a76ff9f7..9352d6d94 100755 --- a/test/gentests.py +++ b/test/gentests.py @@ -34,17 +34,21 @@ import youtube_dl.InfoExtractors def _file_md5(fn): with open(fn, 'rb') as f: return hashlib.md5(f.read()).hexdigest() - -def md5_for_file(filename, block_size=2**20): - with open(filename) as f: - md5 = hashlib.md5() - while True: - data = f.read(block_size) - if not data: - break - md5.update(data) - return md5.hexdigest() -_file_md5 = md5_for_file +try: + _skip_unless = unittest.skipUnless +except AttributeError: # Python 2.6 + def _skip_unless(cond, reason='No reason given'): + def resfunc(f): + # Start the function name with test to appease nosetests-2.6 + def test_wfunc(*args, **kwargs): + if cond: + return f(*args, **kwargs) + else: + print('Skipped test') + return + return test_wfunc + return resfunc +_skip = lambda *args, **kwargs: _skip_unless(False, *args, **kwargs) class DownloadTest(unittest.TestCase): PARAMETERS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), "parameters.json") @@ -78,17 +82,15 @@ def gentests(): name = d['name'] ie = getattr(youtube_dl.InfoExtractors, name + 'IE') testf.write('\n') - if not ie._WORKING: - write('@unittest.skip("IE marked as not _WORKING")') - elif not d['file']: - write('@unittest.skip("No output file specified")') + write('@_skip_unless(youtube_dl.InfoExtractors.' + name + 'IE._WORKING, "IE marked as not _WORKING")') + if not d['file']: + write('@_skip("No output file specified")') elif 'skip' in d: - write('@unittest.skip(' + repr(d['skip']) + ')') + write('@_skip(' + repr(d['skip']) + ')') write('def test_' + name + '(self):') - write(' ' + name + 'IE = youtube_dl.InfoExtractors.' + name + 'IE') write(' filename = ' + repr(d['file'])) write(' fd = FileDownloader(self.parameters)') - write(' fd.add_info_extractor(' + name + 'IE())') + write(' fd.add_info_extractor(youtube_dl.InfoExtractors.' + name + 'IE())') for ien in d.get('addIEs', []): write(' fd.add_info_extractor(youtube_dl.InfoExtractors.' + ien + 'IE())') write(' fd.download([' + repr(d['url']) + '])')