#!/usr/bin/env python

from __future__ import unicode_literals

# Allow direct execution
import io
import os
import sys
import unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))


import json
from youtube_dl import update

def Prient(x):
    print x


class TestUpdate(unittest.TestCase):    
    def test_parsePage(self):
        with io.open("test/testdata/html/dlpage.html", mode="r") as f:
            text = f.read()
        self.assertTrue(update.getLatestVersion(text, True, Prient) == "2017.6.579")
        
    def test_checkHash(self):
    	with open("test/testdata/avideo.py", mode="rb") as f:
    	    code = f.read()
    	self.assertFalse(update.checkBadHash(code))


if __name__ == '__main__':
    unittest.main()