diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/helper.py | 7 | ||||
| -rw-r--r-- | test/swftests/.gitignore | 1 | ||||
| -rw-r--r-- | test/swftests/ArrayAccess.as | 19 | ||||
| -rw-r--r-- | test/swftests/ClassCall.as | 17 | ||||
| -rw-r--r-- | test/swftests/ClassConstruction.as | 15 | ||||
| -rw-r--r-- | test/swftests/LocalVars.as | 13 | ||||
| -rw-r--r-- | test/swftests/PrivateCall.as | 21 | ||||
| -rw-r--r-- | test/swftests/StaticAssignment.as | 13 | ||||
| -rw-r--r-- | test/swftests/StaticRetrieval.as | 16 | ||||
| -rw-r--r-- | test/test_playlists.py | 47 | ||||
| -rw-r--r-- | test/test_swfinterp.py | 77 | ||||
| -rw-r--r-- | test/test_youtube_signature.py | 18 | 
12 files changed, 238 insertions, 26 deletions
| diff --git a/test/helper.py b/test/helper.py index 230d2bd67..84b16f770 100644 --- a/test/helper.py +++ b/test/helper.py @@ -148,3 +148,10 @@ def assertRegexpMatches(self, text, regexp, msg=None):              else:                  msg = note + ', ' + msg              self.assertTrue(m, msg) + + +def assertGreaterEqual(self, got, expected, msg=None): +    if not (got >= expected): +        if msg is None: +            msg = '%r not greater than or equal to %r' % (got, expected) +        self.assertTrue(got >= expected, msg) diff --git a/test/swftests/.gitignore b/test/swftests/.gitignore new file mode 100644 index 000000000..da97ff7ca --- /dev/null +++ b/test/swftests/.gitignore @@ -0,0 +1 @@ +*.swf diff --git a/test/swftests/ArrayAccess.as b/test/swftests/ArrayAccess.as new file mode 100644 index 000000000..e22caa386 --- /dev/null +++ b/test/swftests/ArrayAccess.as @@ -0,0 +1,19 @@ +// input: [["a", "b", "c", "d"]] +// output: ["c", "b", "a", "d"] + +package { +public class ArrayAccess { +    public static function main(ar:Array):Array { +    	var aa:ArrayAccess = new ArrayAccess(); +    	return aa.f(ar, 2); +    } + +    private function f(ar:Array, num:Number):Array{ +        var x:String = ar[0]; +        var y:String = ar[num % ar.length]; +        ar[0] = y; +        ar[num] = x; +        return ar; +    } +} +} diff --git a/test/swftests/ClassCall.as b/test/swftests/ClassCall.as new file mode 100644 index 000000000..aef58daf3 --- /dev/null +++ b/test/swftests/ClassCall.as @@ -0,0 +1,17 @@ +// input: [] +// output: 121 + +package { +public class ClassCall { +    public static function main():int{ +    	var f:OtherClass = new OtherClass(); +        return f.func(100,20); +    } +} +} + +class OtherClass { +	public function func(x: int, y: int):int { +		return x+y+1; +	} +} diff --git a/test/swftests/ClassConstruction.as b/test/swftests/ClassConstruction.as new file mode 100644 index 000000000..436479f8f --- /dev/null +++ b/test/swftests/ClassConstruction.as @@ -0,0 +1,15 @@ +// input: [] +// output: 0 + +package { +public class ClassConstruction { +    public static function main():int{ +    	var f:Foo = new Foo(); +        return 0; +    } +} +} + +class Foo { + +} diff --git a/test/swftests/LocalVars.as b/test/swftests/LocalVars.as new file mode 100644 index 000000000..b2911a9f3 --- /dev/null +++ b/test/swftests/LocalVars.as @@ -0,0 +1,13 @@ +// input: [1, 2] +// output: 3 + +package { +public class LocalVars { +    public static function main(a:int, b:int):int{ +        var c:int = a + b + b; +        var d:int = c - b; +        var e:int = d; +        return e; +    } +} +} diff --git a/test/swftests/PrivateCall.as b/test/swftests/PrivateCall.as new file mode 100644 index 000000000..f1c110a37 --- /dev/null +++ b/test/swftests/PrivateCall.as @@ -0,0 +1,21 @@ +// input: [] +// output: 9 + +package { +public class PrivateCall { +    public static function main():int{ +    	var f:OtherClass = new OtherClass(); +        return f.func(); +    } +} +} + +class OtherClass { +	private function pf():int { +		return 9; +	} + +	public function func():int { +		return this.pf(); +	} +} diff --git a/test/swftests/StaticAssignment.as b/test/swftests/StaticAssignment.as new file mode 100644 index 000000000..b061c219d --- /dev/null +++ b/test/swftests/StaticAssignment.as @@ -0,0 +1,13 @@ +// input: [1] +// output: 1 + +package { +public class StaticAssignment { +	public static var v:int; + +    public static function main(a:int):int{ +        v = a; +        return v; +    } +} +} diff --git a/test/swftests/StaticRetrieval.as b/test/swftests/StaticRetrieval.as new file mode 100644 index 000000000..c8352d819 --- /dev/null +++ b/test/swftests/StaticRetrieval.as @@ -0,0 +1,16 @@ +// input: [] +// output: 1 + +package { +public class StaticRetrieval { +	public static var v:int; + +    public static function main():int{ +        if (v) { +        	return 0; +        } else { +        	return 1; +        } +    } +} +} diff --git a/test/test_playlists.py b/test/test_playlists.py index 1a38a667b..4789200e9 100644 --- a/test/test_playlists.py +++ b/test/test_playlists.py @@ -11,6 +11,7 @@ sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))  from test.helper import (      assertRegexpMatches, +    assertGreaterEqual,      expect_info_dict,      FakeYDL,  ) @@ -71,8 +72,8 @@ class TestPlaylists(unittest.TestCase):          ie = DailymotionUserIE(dl)          result = ie.extract('https://www.dailymotion.com/user/nqtv')          self.assertIsPlaylist(result) +        assertGreaterEqual(self, len(result['entries']), 100)          self.assertEqual(result['title'], 'Rémi Gaillard') -        self.assertTrue(len(result['entries']) >= 100)      def test_vimeo_channel(self):          dl = FakeYDL() @@ -111,7 +112,7 @@ class TestPlaylists(unittest.TestCase):          ie = VineUserIE(dl)          result = ie.extract('https://vine.co/Visa')          self.assertIsPlaylist(result) -        self.assertTrue(len(result['entries']) >= 47) +        assertGreaterEqual(self, len(result['entries']), 47)      def test_ustream_channel(self):          dl = FakeYDL() @@ -119,7 +120,7 @@ class TestPlaylists(unittest.TestCase):          result = ie.extract('http://www.ustream.tv/channel/channeljapan')          self.assertIsPlaylist(result)          self.assertEqual(result['id'], '10874166') -        self.assertTrue(len(result['entries']) >= 54) +        assertGreaterEqual(self, len(result['entries']), 54)      def test_soundcloud_set(self):          dl = FakeYDL() @@ -127,7 +128,7 @@ class TestPlaylists(unittest.TestCase):          result = ie.extract('https://soundcloud.com/the-concept-band/sets/the-royal-concept-ep')          self.assertIsPlaylist(result)          self.assertEqual(result['title'], 'The Royal Concept EP') -        self.assertTrue(len(result['entries']) >= 6) +        assertGreaterEqual(self, len(result['entries']), 6)      def test_soundcloud_user(self):          dl = FakeYDL() @@ -135,7 +136,7 @@ class TestPlaylists(unittest.TestCase):          result = ie.extract('https://soundcloud.com/the-concept-band')          self.assertIsPlaylist(result)          self.assertEqual(result['id'], '9615865') -        self.assertTrue(len(result['entries']) >= 12) +        assertGreaterEqual(self, len(result['entries']), 12)      def test_soundcloud_likes(self):          dl = FakeYDL() @@ -143,7 +144,7 @@ class TestPlaylists(unittest.TestCase):          result = ie.extract('https://soundcloud.com/the-concept-band/likes')          self.assertIsPlaylist(result)          self.assertEqual(result['id'], '9615865') -        self.assertTrue(len(result['entries']) >= 1) +        assertGreaterEqual(self, len(result['entries']), 1)      def test_soundcloud_playlist(self):          dl = FakeYDL() @@ -162,7 +163,7 @@ class TestPlaylists(unittest.TestCase):          result = ie.extract('http://new.livestream.com/tedx/cityenglish')          self.assertIsPlaylist(result)          self.assertEqual(result['title'], 'TEDCity2.0 (English)') -        self.assertTrue(len(result['entries']) >= 4) +        assertGreaterEqual(self, len(result['entries']), 4)      def test_livestreamoriginal_folder(self):          dl = FakeYDL() @@ -170,7 +171,7 @@ class TestPlaylists(unittest.TestCase):          result = ie.extract('https://www.livestream.com/newplay/folder?dirId=a07bf706-d0e4-4e75-a747-b021d84f2fd3')          self.assertIsPlaylist(result)          self.assertEqual(result['id'], 'a07bf706-d0e4-4e75-a747-b021d84f2fd3') -        self.assertTrue(len(result['entries']) >= 28) +        assertGreaterEqual(self, len(result['entries']), 28)      def test_nhl_videocenter(self):          dl = FakeYDL() @@ -187,7 +188,7 @@ class TestPlaylists(unittest.TestCase):          result = ie.extract('http://bambuser.com/channel/pixelversity')          self.assertIsPlaylist(result)          self.assertEqual(result['title'], 'pixelversity') -        self.assertTrue(len(result['entries']) >= 60) +        assertGreaterEqual(self, len(result['entries']), 60)      def test_bandcamp_album(self):          dl = FakeYDL() @@ -195,7 +196,7 @@ class TestPlaylists(unittest.TestCase):          result = ie.extract('http://mpallante.bandcamp.com/album/nightmare-night-ep')          self.assertIsPlaylist(result)          self.assertEqual(result['title'], 'Nightmare Night EP') -        self.assertTrue(len(result['entries']) >= 4) +        assertGreaterEqual(self, len(result['entries']), 4)      def test_smotri_community(self):          dl = FakeYDL() @@ -204,7 +205,7 @@ class TestPlaylists(unittest.TestCase):          self.assertIsPlaylist(result)          self.assertEqual(result['id'], 'kommuna')          self.assertEqual(result['title'], 'КПРФ') -        self.assertTrue(len(result['entries']) >= 4) +        assertGreaterEqual(self, len(result['entries']), 4)      def test_smotri_user(self):          dl = FakeYDL() @@ -213,7 +214,7 @@ class TestPlaylists(unittest.TestCase):          self.assertIsPlaylist(result)          self.assertEqual(result['id'], 'inspector')          self.assertEqual(result['title'], 'Inspector') -        self.assertTrue(len(result['entries']) >= 9) +        assertGreaterEqual(self, len(result['entries']), 9)      def test_AcademicEarthCourse(self):          dl = FakeYDL() @@ -232,7 +233,7 @@ class TestPlaylists(unittest.TestCase):          self.assertIsPlaylist(result)          self.assertEqual(result['id'], 'dvoe_iz_lartsa')          self.assertEqual(result['title'], 'Двое из ларца (2006 - 2008)') -        self.assertTrue(len(result['entries']) >= 24) +        assertGreaterEqual(self, len(result['entries']), 24)      def test_ivi_compilation_season(self):          dl = FakeYDL() @@ -241,7 +242,7 @@ class TestPlaylists(unittest.TestCase):          self.assertIsPlaylist(result)          self.assertEqual(result['id'], 'dvoe_iz_lartsa/season1')          self.assertEqual(result['title'], 'Двое из ларца (2006 - 2008) 1 сезон') -        self.assertTrue(len(result['entries']) >= 12) +        assertGreaterEqual(self, len(result['entries']), 12)      def test_imdb_list(self):          dl = FakeYDL() @@ -260,7 +261,7 @@ class TestPlaylists(unittest.TestCase):          self.assertEqual(result['id'], 'cryptography')          self.assertEqual(result['title'], 'Journey into cryptography')          self.assertEqual(result['description'], 'How have humans protected their secret messages through history? What has changed today?') -        self.assertTrue(len(result['entries']) >= 3) +        assertGreaterEqual(self, len(result['entries']), 3)      def test_EveryonesMixtape(self):          dl = FakeYDL() @@ -277,7 +278,7 @@ class TestPlaylists(unittest.TestCase):          result = ie.extract('http://rutube.ru/tags/video/1800/')          self.assertIsPlaylist(result)          self.assertEqual(result['id'], '1800') -        self.assertTrue(len(result['entries']) >= 68) +        assertGreaterEqual(self, len(result['entries']), 68)      def test_rutube_person(self):          dl = FakeYDL() @@ -285,7 +286,7 @@ class TestPlaylists(unittest.TestCase):          result = ie.extract('http://rutube.ru/video/person/313878/')          self.assertIsPlaylist(result)          self.assertEqual(result['id'], '313878') -        self.assertTrue(len(result['entries']) >= 37) +        assertGreaterEqual(self, len(result['entries']), 37)      def test_multiple_brightcove_videos(self):          # https://github.com/rg3/youtube-dl/issues/2283 @@ -322,7 +323,7 @@ class TestPlaylists(unittest.TestCase):          self.assertIsPlaylist(result)          self.assertEqual(result['id'], '10')          self.assertEqual(result['title'], 'Who are the hackers?') -        self.assertTrue(len(result['entries']) >= 6) +        assertGreaterEqual(self, len(result['entries']), 6)      def test_toypics_user(self):          dl = FakeYDL() @@ -330,7 +331,7 @@ class TestPlaylists(unittest.TestCase):          result = ie.extract('http://videos.toypics.net/Mikey')          self.assertIsPlaylist(result)          self.assertEqual(result['id'], 'Mikey') -        self.assertTrue(len(result['entries']) >= 17) +        assertGreaterEqual(self, len(result['entries']), 17)      def test_xtube_user(self):          dl = FakeYDL() @@ -338,7 +339,7 @@ class TestPlaylists(unittest.TestCase):          result = ie.extract('http://www.xtube.com/community/profile.php?user=greenshowers')          self.assertIsPlaylist(result)          self.assertEqual(result['id'], 'greenshowers') -        self.assertTrue(len(result['entries']) >= 155) +        assertGreaterEqual(self, len(result['entries']), 155)      def test_InstagramUser(self):          dl = FakeYDL() @@ -346,7 +347,7 @@ class TestPlaylists(unittest.TestCase):          result = ie.extract('http://instagram.com/porsche')          self.assertIsPlaylist(result)          self.assertEqual(result['id'], 'porsche') -        self.assertTrue(len(result['entries']) >= 2) +        assertGreaterEqual(self, len(result['entries']), 2)          test_video = next(              e for e in result['entries']              if e['id'] == '614605558512799803_462752227') @@ -385,7 +386,7 @@ class TestPlaylists(unittest.TestCase):          self.assertEqual(result['id'], '152147')          self.assertEqual(              result['title'], 'Brace Yourself - Today\'s Weirdest News') -        self.assertTrue(len(result['entries']) >= 10) +        assertGreaterEqual(self, len(result['entries']), 10)      def test_TeacherTubeUser(self):          dl = FakeYDL() @@ -393,7 +394,7 @@ class TestPlaylists(unittest.TestCase):          result = ie.extract('http://www.teachertube.com/user/profile/rbhagwati2')          self.assertIsPlaylist(result)          self.assertEqual(result['id'], 'rbhagwati2') -        self.assertTrue(len(result['entries']) >= 179) +        assertGreaterEqual(self, len(result['entries']), 179)  if __name__ == '__main__':      unittest.main() diff --git a/test/test_swfinterp.py b/test/test_swfinterp.py new file mode 100644 index 000000000..b42cd74c7 --- /dev/null +++ b/test/test_swfinterp.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python + +# Allow direct execution +import os +import sys +import unittest +sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + + +import errno +import io +import json +import re +import subprocess + +from youtube_dl.swfinterp import SWFInterpreter + + +TEST_DIR = os.path.join( +    os.path.dirname(os.path.abspath(__file__)), 'swftests') + + +class TestSWFInterpreter(unittest.TestCase): +    pass + + +def _make_testfunc(testfile): +    m = re.match(r'^(.*)\.(as)$', testfile) +    if not m: +        return +    test_id = m.group(1) + +    def test_func(self): +        as_file = os.path.join(TEST_DIR, testfile) +        swf_file = os.path.join(TEST_DIR, test_id + '.swf') +        if ((not os.path.exists(swf_file)) +                or os.path.getmtime(swf_file) < os.path.getmtime(as_file)): +            # Recompile +            try: +                subprocess.check_call(['mxmlc', '-output', swf_file, as_file]) +            except OSError as ose: +                if ose.errno == errno.ENOENT: +                    print('mxmlc not found! Skipping test.') +                    return +                raise + +        with open(swf_file, 'rb') as swf_f: +            swf_content = swf_f.read() +        swfi = SWFInterpreter(swf_content) + +        with io.open(as_file, 'r', encoding='utf-8') as as_f: +            as_content = as_f.read() + +        def _find_spec(key): +            m = re.search( +                r'(?m)^//\s*%s:\s*(.*?)\n' % re.escape(key), as_content) +            if not m: +                raise ValueError('Cannot find %s in %s' % (key, testfile)) +            return json.loads(m.group(1)) + +        input_args = _find_spec('input') +        output = _find_spec('output') + +        swf_class = swfi.extract_class(test_id) +        func = swfi.extract_function(swf_class, 'main') +        res = func(input_args) +        self.assertEqual(res, output) + +    test_func.__name__ = str('test_swf_' + test_id) +    setattr(TestSWFInterpreter, test_func.__name__, test_func) + + +for testfile in os.listdir(TEST_DIR): +    _make_testfunc(testfile) + +if __name__ == '__main__': +    unittest.main() diff --git a/test/test_youtube_signature.py b/test/test_youtube_signature.py index d95533959..e8a67c4c0 100644 --- a/test/test_youtube_signature.py +++ b/test/test_youtube_signature.py @@ -45,6 +45,18 @@ _TESTS = [          u'2ACFC7A61CA478CD21425E5A57EBD73DDC78E22A.2094302436B2D377D14A3BBA23022D023B8BC25AA',          u'A52CB8B320D22032ABB3A41D773D2B6342034902.A22E87CDD37DBE75A5E52412DC874AC16A7CFCA2',      ), +    ( +        u'http://s.ytimg.com/yts/swfbin/player-vfl5vIhK2/watch_as3.swf', +        u'swf', +        86, +        u'O1I3456789abcde0ghijklmnopqrstuvwxyzABCDEFGHfJKLMN2PQRSTUVWXY\\!"#$%&\'()*+,-./:;<=>?' +    ), +    ( +        u'http://s.ytimg.com/yts/swfbin/player-vflmDyk47/watch_as3.swf', +        u'swf', +        u'F375F75BF2AFDAAF2666E43868D46816F83F13E81C46.3725A8218E446A0DECD33F79DC282994D6AA92C92C9', +        u'9C29AA6D499282CD97F33DCED0A644E8128A5273.64C18E31F38361864D86834E6662FAADFA2FB57F' +    ),  ] @@ -57,12 +69,12 @@ class TestSignature(unittest.TestCase):  def make_tfunc(url, stype, sig_input, expected_sig): -    basename = url.rpartition('/')[2] -    m = re.match(r'.*-([a-zA-Z0-9_-]+)\.[a-z]+$', basename) -    assert m, '%r should follow URL format' % basename +    m = re.match(r'.*-([a-zA-Z0-9_-]+)(?:/watch_as3)?\.[a-z]+$', url) +    assert m, '%r should follow URL format' % url      test_id = m.group(1)      def test_func(self): +        basename = 'player-%s.%s' % (test_id, stype)          fn = os.path.join(self.TESTDATA_DIR, basename)          if not os.path.exists(fn): | 
