]> git.bitcoin.ninja Git - youtube-dl/blob - test/test_utils.py
[test/test_youtube_signature] Use fake YDL
[youtube-dl] / test / test_utils.py
1 #!/usr/bin/env python
2 # coding: utf-8
3
4 from __future__ import unicode_literals
5
6 # Allow direct execution
7 import os
8 import sys
9 import unittest
10 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
11
12
13 # Various small unit tests
14 import io
15 import json
16 import xml.etree.ElementTree
17
18 from youtube_dl.utils import (
19     age_restricted,
20     args_to_str,
21     clean_html,
22     DateRange,
23     detect_exe_version,
24     encodeFilename,
25     escape_rfc3986,
26     escape_url,
27     find_xpath_attr,
28     fix_xml_ampersands,
29     InAdvancePagedList,
30     intlist_to_bytes,
31     is_html,
32     js_to_json,
33     limit_length,
34     OnDemandPagedList,
35     orderedSet,
36     parse_duration,
37     parse_filesize,
38     parse_iso8601,
39     read_batch_urls,
40     sanitize_filename,
41     shell_quote,
42     smuggle_url,
43     str_to_int,
44     strip_jsonp,
45     struct_unpack,
46     timeconvert,
47     unescapeHTML,
48     unified_strdate,
49     unsmuggle_url,
50     uppercase_escape,
51     url_basename,
52     urlencode_postdata,
53     version_tuple,
54     xpath_with_ns,
55     render_table,
56     match_str,
57 )
58
59
60 class TestUtil(unittest.TestCase):
61     def test_timeconvert(self):
62         self.assertTrue(timeconvert('') is None)
63         self.assertTrue(timeconvert('bougrg') is None)
64
65     def test_sanitize_filename(self):
66         self.assertEqual(sanitize_filename('abc'), 'abc')
67         self.assertEqual(sanitize_filename('abc_d-e'), 'abc_d-e')
68
69         self.assertEqual(sanitize_filename('123'), '123')
70
71         self.assertEqual('abc_de', sanitize_filename('abc/de'))
72         self.assertFalse('/' in sanitize_filename('abc/de///'))
73
74         self.assertEqual('abc_de', sanitize_filename('abc/<>\\*|de'))
75         self.assertEqual('xxx', sanitize_filename('xxx/<>\\*|'))
76         self.assertEqual('yes no', sanitize_filename('yes? no'))
77         self.assertEqual('this - that', sanitize_filename('this: that'))
78
79         self.assertEqual(sanitize_filename('AT&T'), 'AT&T')
80         aumlaut = 'ä'
81         self.assertEqual(sanitize_filename(aumlaut), aumlaut)
82         tests = '\u043a\u0438\u0440\u0438\u043b\u043b\u0438\u0446\u0430'
83         self.assertEqual(sanitize_filename(tests), tests)
84
85         self.assertEqual(
86             sanitize_filename('New World record at 0:12:34'),
87             'New World record at 0_12_34')
88
89         forbidden = '"\0\\/'
90         for fc in forbidden:
91             for fbc in forbidden:
92                 self.assertTrue(fbc not in sanitize_filename(fc))
93
94     def test_sanitize_filename_restricted(self):
95         self.assertEqual(sanitize_filename('abc', restricted=True), 'abc')
96         self.assertEqual(sanitize_filename('abc_d-e', restricted=True), 'abc_d-e')
97
98         self.assertEqual(sanitize_filename('123', restricted=True), '123')
99
100         self.assertEqual('abc_de', sanitize_filename('abc/de', restricted=True))
101         self.assertFalse('/' in sanitize_filename('abc/de///', restricted=True))
102
103         self.assertEqual('abc_de', sanitize_filename('abc/<>\\*|de', restricted=True))
104         self.assertEqual('xxx', sanitize_filename('xxx/<>\\*|', restricted=True))
105         self.assertEqual('yes_no', sanitize_filename('yes? no', restricted=True))
106         self.assertEqual('this_-_that', sanitize_filename('this: that', restricted=True))
107
108         tests = 'a\xe4b\u4e2d\u56fd\u7684c'
109         self.assertEqual(sanitize_filename(tests, restricted=True), 'a_b_c')
110         self.assertTrue(sanitize_filename('\xf6', restricted=True) != '')  # No empty filename
111
112         forbidden = '"\0\\/&!: \'\t\n()[]{}$;`^,#'
113         for fc in forbidden:
114             for fbc in forbidden:
115                 self.assertTrue(fbc not in sanitize_filename(fc, restricted=True))
116
117         # Handle a common case more neatly
118         self.assertEqual(sanitize_filename('\u5927\u58f0\u5e26 - Song', restricted=True), 'Song')
119         self.assertEqual(sanitize_filename('\u603b\u7edf: Speech', restricted=True), 'Speech')
120         # .. but make sure the file name is never empty
121         self.assertTrue(sanitize_filename('-', restricted=True) != '')
122         self.assertTrue(sanitize_filename(':', restricted=True) != '')
123
124     def test_sanitize_ids(self):
125         self.assertEqual(sanitize_filename('_n_cd26wFpw', is_id=True), '_n_cd26wFpw')
126         self.assertEqual(sanitize_filename('_BD_eEpuzXw', is_id=True), '_BD_eEpuzXw')
127         self.assertEqual(sanitize_filename('N0Y__7-UOdI', is_id=True), 'N0Y__7-UOdI')
128
129     def test_ordered_set(self):
130         self.assertEqual(orderedSet([1, 1, 2, 3, 4, 4, 5, 6, 7, 3, 5]), [1, 2, 3, 4, 5, 6, 7])
131         self.assertEqual(orderedSet([]), [])
132         self.assertEqual(orderedSet([1]), [1])
133         # keep the list ordered
134         self.assertEqual(orderedSet([135, 1, 1, 1]), [135, 1])
135
136     def test_unescape_html(self):
137         self.assertEqual(unescapeHTML('%20;'), '%20;')
138         self.assertEqual(
139             unescapeHTML('&eacute;'), 'é')
140
141     def test_daterange(self):
142         _20century = DateRange("19000101", "20000101")
143         self.assertFalse("17890714" in _20century)
144         _ac = DateRange("00010101")
145         self.assertTrue("19690721" in _ac)
146         _firstmilenium = DateRange(end="10000101")
147         self.assertTrue("07110427" in _firstmilenium)
148
149     def test_unified_dates(self):
150         self.assertEqual(unified_strdate('December 21, 2010'), '20101221')
151         self.assertEqual(unified_strdate('8/7/2009'), '20090708')
152         self.assertEqual(unified_strdate('Dec 14, 2012'), '20121214')
153         self.assertEqual(unified_strdate('2012/10/11 01:56:38 +0000'), '20121011')
154         self.assertEqual(unified_strdate('1968 12 10'), '19681210')
155         self.assertEqual(unified_strdate('1968-12-10'), '19681210')
156         self.assertEqual(unified_strdate('28/01/2014 21:00:00 +0100'), '20140128')
157         self.assertEqual(
158             unified_strdate('11/26/2014 11:30:00 AM PST', day_first=False),
159             '20141126')
160         self.assertEqual(
161             unified_strdate('2/2/2015 6:47:40 PM', day_first=False),
162             '20150202')
163
164     def test_find_xpath_attr(self):
165         testxml = '''<root>
166             <node/>
167             <node x="a"/>
168             <node x="a" y="c" />
169             <node x="b" y="d" />
170         </root>'''
171         doc = xml.etree.ElementTree.fromstring(testxml)
172
173         self.assertEqual(find_xpath_attr(doc, './/fourohfour', 'n', 'v'), None)
174         self.assertEqual(find_xpath_attr(doc, './/node', 'x', 'a'), doc[1])
175         self.assertEqual(find_xpath_attr(doc, './/node', 'y', 'c'), doc[2])
176
177     def test_xpath_with_ns(self):
178         testxml = '''<root xmlns:media="http://example.com/">
179             <media:song>
180                 <media:author>The Author</media:author>
181                 <url>http://server.com/download.mp3</url>
182             </media:song>
183         </root>'''
184         doc = xml.etree.ElementTree.fromstring(testxml)
185         find = lambda p: doc.find(xpath_with_ns(p, {'media': 'http://example.com/'}))
186         self.assertTrue(find('media:song') is not None)
187         self.assertEqual(find('media:song/media:author').text, 'The Author')
188         self.assertEqual(find('media:song/url').text, 'http://server.com/download.mp3')
189
190     def test_smuggle_url(self):
191         data = {"ö": "ö", "abc": [3]}
192         url = 'https://foo.bar/baz?x=y#a'
193         smug_url = smuggle_url(url, data)
194         unsmug_url, unsmug_data = unsmuggle_url(smug_url)
195         self.assertEqual(url, unsmug_url)
196         self.assertEqual(data, unsmug_data)
197
198         res_url, res_data = unsmuggle_url(url)
199         self.assertEqual(res_url, url)
200         self.assertEqual(res_data, None)
201
202     def test_shell_quote(self):
203         args = ['ffmpeg', '-i', encodeFilename('ñ€ß\'.mp4')]
204         self.assertEqual(shell_quote(args), """ffmpeg -i 'ñ€ß'"'"'.mp4'""")
205
206     def test_str_to_int(self):
207         self.assertEqual(str_to_int('123,456'), 123456)
208         self.assertEqual(str_to_int('123.456'), 123456)
209
210     def test_url_basename(self):
211         self.assertEqual(url_basename('http://foo.de/'), '')
212         self.assertEqual(url_basename('http://foo.de/bar/baz'), 'baz')
213         self.assertEqual(url_basename('http://foo.de/bar/baz?x=y'), 'baz')
214         self.assertEqual(url_basename('http://foo.de/bar/baz#x=y'), 'baz')
215         self.assertEqual(url_basename('http://foo.de/bar/baz/'), 'baz')
216         self.assertEqual(
217             url_basename('http://media.w3.org/2010/05/sintel/trailer.mp4'),
218             'trailer.mp4')
219
220     def test_parse_duration(self):
221         self.assertEqual(parse_duration(None), None)
222         self.assertEqual(parse_duration(False), None)
223         self.assertEqual(parse_duration('invalid'), None)
224         self.assertEqual(parse_duration('1'), 1)
225         self.assertEqual(parse_duration('1337:12'), 80232)
226         self.assertEqual(parse_duration('9:12:43'), 33163)
227         self.assertEqual(parse_duration('12:00'), 720)
228         self.assertEqual(parse_duration('00:01:01'), 61)
229         self.assertEqual(parse_duration('x:y'), None)
230         self.assertEqual(parse_duration('3h11m53s'), 11513)
231         self.assertEqual(parse_duration('3h 11m 53s'), 11513)
232         self.assertEqual(parse_duration('3 hours 11 minutes 53 seconds'), 11513)
233         self.assertEqual(parse_duration('3 hours 11 mins 53 secs'), 11513)
234         self.assertEqual(parse_duration('62m45s'), 3765)
235         self.assertEqual(parse_duration('6m59s'), 419)
236         self.assertEqual(parse_duration('49s'), 49)
237         self.assertEqual(parse_duration('0h0m0s'), 0)
238         self.assertEqual(parse_duration('0m0s'), 0)
239         self.assertEqual(parse_duration('0s'), 0)
240         self.assertEqual(parse_duration('01:02:03.05'), 3723.05)
241         self.assertEqual(parse_duration('T30M38S'), 1838)
242         self.assertEqual(parse_duration('5 s'), 5)
243         self.assertEqual(parse_duration('3 min'), 180)
244         self.assertEqual(parse_duration('2.5 hours'), 9000)
245         self.assertEqual(parse_duration('02:03:04'), 7384)
246         self.assertEqual(parse_duration('01:02:03:04'), 93784)
247
248     def test_fix_xml_ampersands(self):
249         self.assertEqual(
250             fix_xml_ampersands('"&x=y&z=a'), '"&amp;x=y&amp;z=a')
251         self.assertEqual(
252             fix_xml_ampersands('"&amp;x=y&wrong;&z=a'),
253             '"&amp;x=y&amp;wrong;&amp;z=a')
254         self.assertEqual(
255             fix_xml_ampersands('&amp;&apos;&gt;&lt;&quot;'),
256             '&amp;&apos;&gt;&lt;&quot;')
257         self.assertEqual(
258             fix_xml_ampersands('&#1234;&#x1abC;'), '&#1234;&#x1abC;')
259         self.assertEqual(fix_xml_ampersands('&#&#'), '&amp;#&amp;#')
260
261     def test_paged_list(self):
262         def testPL(size, pagesize, sliceargs, expected):
263             def get_page(pagenum):
264                 firstid = pagenum * pagesize
265                 upto = min(size, pagenum * pagesize + pagesize)
266                 for i in range(firstid, upto):
267                     yield i
268
269             pl = OnDemandPagedList(get_page, pagesize)
270             got = pl.getslice(*sliceargs)
271             self.assertEqual(got, expected)
272
273             iapl = InAdvancePagedList(get_page, size // pagesize + 1, pagesize)
274             got = iapl.getslice(*sliceargs)
275             self.assertEqual(got, expected)
276
277         testPL(5, 2, (), [0, 1, 2, 3, 4])
278         testPL(5, 2, (1,), [1, 2, 3, 4])
279         testPL(5, 2, (2,), [2, 3, 4])
280         testPL(5, 2, (4,), [4])
281         testPL(5, 2, (0, 3), [0, 1, 2])
282         testPL(5, 2, (1, 4), [1, 2, 3])
283         testPL(5, 2, (2, 99), [2, 3, 4])
284         testPL(5, 2, (20, 99), [])
285
286     def test_struct_unpack(self):
287         self.assertEqual(struct_unpack('!B', b'\x00'), (0,))
288
289     def test_read_batch_urls(self):
290         f = io.StringIO('''\xef\xbb\xbf foo
291             bar\r
292             baz
293             # More after this line\r
294             ; or after this
295             bam''')
296         self.assertEqual(read_batch_urls(f), ['foo', 'bar', 'baz', 'bam'])
297
298     def test_urlencode_postdata(self):
299         data = urlencode_postdata({'username': 'foo@bar.com', 'password': '1234'})
300         self.assertTrue(isinstance(data, bytes))
301
302     def test_parse_iso8601(self):
303         self.assertEqual(parse_iso8601('2014-03-23T23:04:26+0100'), 1395612266)
304         self.assertEqual(parse_iso8601('2014-03-23T22:04:26+0000'), 1395612266)
305         self.assertEqual(parse_iso8601('2014-03-23T22:04:26Z'), 1395612266)
306         self.assertEqual(parse_iso8601('2014-03-23T22:04:26.1234Z'), 1395612266)
307
308     def test_strip_jsonp(self):
309         stripped = strip_jsonp('cb ([ {"id":"532cb",\n\n\n"x":\n3}\n]\n);')
310         d = json.loads(stripped)
311         self.assertEqual(d, [{"id": "532cb", "x": 3}])
312
313         stripped = strip_jsonp('parseMetadata({"STATUS":"OK"})\n\n\n//epc')
314         d = json.loads(stripped)
315         self.assertEqual(d, {'STATUS': 'OK'})
316
317     def test_uppercase_escape(self):
318         self.assertEqual(uppercase_escape('aä'), 'aä')
319         self.assertEqual(uppercase_escape('\\U0001d550'), '𝕐')
320
321     def test_limit_length(self):
322         self.assertEqual(limit_length(None, 12), None)
323         self.assertEqual(limit_length('foo', 12), 'foo')
324         self.assertTrue(
325             limit_length('foo bar baz asd', 12).startswith('foo bar'))
326         self.assertTrue('...' in limit_length('foo bar baz asd', 12))
327
328     def test_escape_rfc3986(self):
329         reserved = "!*'();:@&=+$,/?#[]"
330         unreserved = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~'
331         self.assertEqual(escape_rfc3986(reserved), reserved)
332         self.assertEqual(escape_rfc3986(unreserved), unreserved)
333         self.assertEqual(escape_rfc3986('тест'), '%D1%82%D0%B5%D1%81%D1%82')
334         self.assertEqual(escape_rfc3986('%D1%82%D0%B5%D1%81%D1%82'), '%D1%82%D0%B5%D1%81%D1%82')
335         self.assertEqual(escape_rfc3986('foo bar'), 'foo%20bar')
336         self.assertEqual(escape_rfc3986('foo%20bar'), 'foo%20bar')
337
338     def test_escape_url(self):
339         self.assertEqual(
340             escape_url('http://wowza.imust.org/srv/vod/telemb/new/UPLOAD/UPLOAD/20224_IncendieHavré_FD.mp4'),
341             'http://wowza.imust.org/srv/vod/telemb/new/UPLOAD/UPLOAD/20224_IncendieHavre%CC%81_FD.mp4'
342         )
343         self.assertEqual(
344             escape_url('http://www.ardmediathek.de/tv/Sturm-der-Liebe/Folge-2036-Zu-Mann-und-Frau-erklärt/Das-Erste/Video?documentId=22673108&bcastId=5290'),
345             'http://www.ardmediathek.de/tv/Sturm-der-Liebe/Folge-2036-Zu-Mann-und-Frau-erkl%C3%A4rt/Das-Erste/Video?documentId=22673108&bcastId=5290'
346         )
347         self.assertEqual(
348             escape_url('http://тест.рф/фрагмент'),
349             'http://тест.рф/%D1%84%D1%80%D0%B0%D0%B3%D0%BC%D0%B5%D0%BD%D1%82'
350         )
351         self.assertEqual(
352             escape_url('http://тест.рф/абв?абв=абв#абв'),
353             'http://тест.рф/%D0%B0%D0%B1%D0%B2?%D0%B0%D0%B1%D0%B2=%D0%B0%D0%B1%D0%B2#%D0%B0%D0%B1%D0%B2'
354         )
355         self.assertEqual(escape_url('http://vimeo.com/56015672#at=0'), 'http://vimeo.com/56015672#at=0')
356
357     def test_js_to_json_realworld(self):
358         inp = '''{
359             'clip':{'provider':'pseudo'}
360         }'''
361         self.assertEqual(js_to_json(inp), '''{
362             "clip":{"provider":"pseudo"}
363         }''')
364         json.loads(js_to_json(inp))
365
366         inp = '''{
367             'playlist':[{'controls':{'all':null}}]
368         }'''
369         self.assertEqual(js_to_json(inp), '''{
370             "playlist":[{"controls":{"all":null}}]
371         }''')
372
373     def test_js_to_json_edgecases(self):
374         on = js_to_json("{abc_def:'1\\'\\\\2\\\\\\'3\"4'}")
375         self.assertEqual(json.loads(on), {"abc_def": "1'\\2\\'3\"4"})
376
377         on = js_to_json('{"abc": true}')
378         self.assertEqual(json.loads(on), {'abc': True})
379
380         # Ignore JavaScript code as well
381         on = js_to_json('''{
382             "x": 1,
383             y: "a",
384             z: some.code
385         }''')
386         d = json.loads(on)
387         self.assertEqual(d['x'], 1)
388         self.assertEqual(d['y'], 'a')
389
390     def test_clean_html(self):
391         self.assertEqual(clean_html('a:\nb'), 'a: b')
392         self.assertEqual(clean_html('a:\n   "b"'), 'a:    "b"')
393
394     def test_intlist_to_bytes(self):
395         self.assertEqual(
396             intlist_to_bytes([0, 1, 127, 128, 255]),
397             b'\x00\x01\x7f\x80\xff')
398
399     def test_args_to_str(self):
400         self.assertEqual(
401             args_to_str(['foo', 'ba/r', '-baz', '2 be', '']),
402             'foo ba/r -baz \'2 be\' \'\''
403         )
404
405     def test_parse_filesize(self):
406         self.assertEqual(parse_filesize(None), None)
407         self.assertEqual(parse_filesize(''), None)
408         self.assertEqual(parse_filesize('91 B'), 91)
409         self.assertEqual(parse_filesize('foobar'), None)
410         self.assertEqual(parse_filesize('2 MiB'), 2097152)
411         self.assertEqual(parse_filesize('5 GB'), 5000000000)
412         self.assertEqual(parse_filesize('1.2Tb'), 1200000000000)
413         self.assertEqual(parse_filesize('1,24 KB'), 1240)
414
415     def test_version_tuple(self):
416         self.assertEqual(version_tuple('1'), (1,))
417         self.assertEqual(version_tuple('10.23.344'), (10, 23, 344))
418         self.assertEqual(version_tuple('10.1-6'), (10, 1, 6))  # avconv style
419
420     def test_detect_exe_version(self):
421         self.assertEqual(detect_exe_version('''ffmpeg version 1.2.1
422 built on May 27 2013 08:37:26 with gcc 4.7 (Debian 4.7.3-4)
423 configuration: --prefix=/usr --extra-'''), '1.2.1')
424         self.assertEqual(detect_exe_version('''ffmpeg version N-63176-g1fb4685
425 built on May 15 2014 22:09:06 with gcc 4.8.2 (GCC)'''), 'N-63176-g1fb4685')
426         self.assertEqual(detect_exe_version('''X server found. dri2 connection failed!
427 Trying to open render node...
428 Success at /dev/dri/renderD128.
429 ffmpeg version 2.4.4 Copyright (c) 2000-2014 the FFmpeg ...'''), '2.4.4')
430
431     def test_age_restricted(self):
432         self.assertFalse(age_restricted(None, 10))  # unrestricted content
433         self.assertFalse(age_restricted(1, None))  # unrestricted policy
434         self.assertFalse(age_restricted(8, 10))
435         self.assertTrue(age_restricted(18, 14))
436         self.assertFalse(age_restricted(18, 18))
437
438     def test_is_html(self):
439         self.assertFalse(is_html(b'\x49\x44\x43<html'))
440         self.assertTrue(is_html(b'<!DOCTYPE foo>\xaaa'))
441         self.assertTrue(is_html(  # UTF-8 with BOM
442             b'\xef\xbb\xbf<!DOCTYPE foo>\xaaa'))
443         self.assertTrue(is_html(  # UTF-16-LE
444             b'\xff\xfe<\x00h\x00t\x00m\x00l\x00>\x00\xe4\x00'
445         ))
446         self.assertTrue(is_html(  # UTF-16-BE
447             b'\xfe\xff\x00<\x00h\x00t\x00m\x00l\x00>\x00\xe4'
448         ))
449         self.assertTrue(is_html(  # UTF-32-BE
450             b'\x00\x00\xFE\xFF\x00\x00\x00<\x00\x00\x00h\x00\x00\x00t\x00\x00\x00m\x00\x00\x00l\x00\x00\x00>\x00\x00\x00\xe4'))
451         self.assertTrue(is_html(  # UTF-32-LE
452             b'\xFF\xFE\x00\x00<\x00\x00\x00h\x00\x00\x00t\x00\x00\x00m\x00\x00\x00l\x00\x00\x00>\x00\x00\x00\xe4\x00\x00\x00'))
453
454     def test_render_table(self):
455         self.assertEqual(
456             render_table(
457                 ['a', 'bcd'],
458                 [[123, 4], [9999, 51]]),
459             'a    bcd\n'
460             '123  4\n'
461             '9999 51')
462
463     def test_match_str(self):
464         self.assertRaises(ValueError, match_str, 'xy>foobar', {})
465         self.assertFalse(match_str('xy', {'x': 1200}))
466         self.assertTrue(match_str('!xy', {'x': 1200}))
467         self.assertTrue(match_str('x', {'x': 1200}))
468         self.assertFalse(match_str('!x', {'x': 1200}))
469         self.assertTrue(match_str('x', {'x': 0}))
470         self.assertFalse(match_str('x>0', {'x': 0}))
471         self.assertFalse(match_str('x>0', {}))
472         self.assertTrue(match_str('x>?0', {}))
473         self.assertTrue(match_str('x>1K', {'x': 1200}))
474         self.assertFalse(match_str('x>2K', {'x': 1200}))
475         self.assertTrue(match_str('x>=1200 & x < 1300', {'x': 1200}))
476         self.assertFalse(match_str('x>=1100 & x < 1200', {'x': 1200}))
477         self.assertFalse(match_str('y=a212', {'y': 'foobar42'}))
478         self.assertTrue(match_str('y=foobar42', {'y': 'foobar42'}))
479         self.assertFalse(match_str('y!=foobar42', {'y': 'foobar42'}))
480         self.assertTrue(match_str('y!=foobar2', {'y': 'foobar42'}))
481         self.assertFalse(match_str(
482             'like_count > 100 & dislike_count <? 50 & description',
483             {'like_count': 90, 'description': 'foo'}))
484         self.assertTrue(match_str(
485             'like_count > 100 & dislike_count <? 50 & description',
486             {'like_count': 190, 'description': 'foo'}))
487         self.assertFalse(match_str(
488             'like_count > 100 & dislike_count <? 50 & description',
489             {'like_count': 190, 'dislike_count': 60, 'description': 'foo'}))
490         self.assertFalse(match_str(
491             'like_count > 100 & dislike_count <? 50 & description',
492             {'like_count': 190, 'dislike_count': 10}))
493
494
495 if __name__ == '__main__':
496     unittest.main()