Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make program and test suite compatible with Python 3 instead of 2. #350

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

"""Youtube-dlg setup file.

Examples:
Expand Down
10 changes: 3 additions & 7 deletions tests/test_ditem.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""Contains test cases for the DownloadItem object."""

from __future__ import unicode_literals

import sys
import os.path
import unittest
Expand All @@ -15,7 +10,7 @@
try:
from youtube_dl_gui.downloadmanager import DownloadItem
except ImportError as error:
print error
print(error)
sys.exit(1)


Expand All @@ -32,7 +27,8 @@ def test_init(self):
self.assertEqual(ditem.stage, "Queued")
self.assertEqual(ditem.url, url)
self.assertEqual(ditem.options, options)
self.assertEqual(ditem.object_id, hash(url + unicode(options)))
# Python 3 has large hash; limit to C long
self.assertEqual(ditem.object_id, int(str(hash(url + str(options)))[:9]))

self.assertEqual(ditem.path, "")
self.assertEqual(ditem.filenames, [])
Expand Down
9 changes: 2 additions & 7 deletions tests/test_dlist.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""Contains test cases for the DownloadList object."""

from __future__ import unicode_literals

import sys
import os.path
import unittest
Expand All @@ -13,10 +8,10 @@
sys.path.insert(0, os.path.dirname(os.path.dirname(PATH)))

try:
import mock
import unittest.mock as mock
from youtube_dl_gui.downloadmanager import DownloadList, synchronized
except ImportError as error:
print error
print(error)
sys.exit(1)


Expand Down
19 changes: 7 additions & 12 deletions tests/test_parsers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""Contains test cases for the parsers module."""

from __future__ import unicode_literals

import sys
import os.path
import unittest
Expand All @@ -15,7 +10,7 @@
try:
from youtube_dl_gui.parsers import OptionsParser
except ImportError as error:
print error
print(error)
sys.exit(1)


Expand All @@ -39,7 +34,7 @@ def setUp(self):
def check_options_parse(self, expected_options):
options_parser = OptionsParser()

self.assertItemsEqual(options_parser.parse(self.options_dict), expected_options)
self.assertEqual(sorted(options_parser.parse(self.options_dict)), sorted(expected_options))

def test_parse_to_audio_requirement_bug(self):
"""Test case for the 'to_audio' requirement."""
Expand All @@ -56,7 +51,7 @@ def test_parse_to_audio_requirement_bug(self):
"--audio-quality",
"9",
"-o",
"/home/user/Workplace/test/youtube/%(title)s.%(ext)s"]
os.path.join("/home/user/Workplace/test/youtube", "%(title)s.%(ext)s")]

self.check_options_parse(expected_cmd_list)

Expand All @@ -82,7 +77,7 @@ def test_parse_cmd_args_with_quotes(self):
"-f",
"mp4",
"-o",
"/home/user/Workplace/test/youtube/%(title)s.%(ext)s",
os.path.join("/home/user/Workplace/test/youtube", "%(title)s.%(ext)s"),
"--recode-video",
"mkv",
"--postprocessor-args",
Expand All @@ -98,7 +93,7 @@ def test_parse_cmd_args_with_quotes(self):
"-f",
"mp4",
"-o",
"/home/user/Workplace/test/youtube/%(title)s.%(ext)s",
os.path.join("/home/user/Workplace/test/youtube", "%(title)s.%(ext)s"),
"--postprocessor-args",
"-y -report"]

Expand All @@ -112,7 +107,7 @@ def test_parse_cmd_args_with_quotes(self):
"-f",
"mp4",
"-o",
"/home/user/Workplace/test/youtube/%(title)s.%(ext)s",
os.path.join("/home/user/Workplace/test/youtube", "%(title)s.%(ext)s"),
"--postprocessor-args",
"-y",
"-v"]
Expand All @@ -126,7 +121,7 @@ def test_parse_cmd_args_with_quotes(self):

expected_cmd_list = ["--newline",
"-o",
"/home/user/Workplace/test/youtube/%(title)s.%(ext)s",
os.path.join("/home/user/Workplace/test/youtube", "%(title)s.%(ext)s"),
"-f",
"(mp4)[width<1300]"]

Expand Down
74 changes: 3 additions & 71 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Contains test cases for the utils.py module."""

from __future__ import unicode_literals

import sys
import os.path
import unittest
Expand All @@ -13,11 +8,11 @@
sys.path.insert(0, os.path.dirname(os.path.dirname(PATH)))

try:
import mock
import unittest.mock as mock

from youtube_dl_gui import utils
except ImportError as error:
print error
print(error)
sys.exit(1)


Expand Down Expand Up @@ -111,70 +106,7 @@ def test_build_command_without_spaces_windows(self):

self.run_tests("youtube-dl.exe", tmpl)


class TestConvertItem(unittest.TestCase):

"""Test case for the convert_item function."""

def setUp(self):
self.input_list_u = ["v1", "v2", "v3"]
self.input_list_s = [str("v1"), str("v2"), str("v3")]

self.input_tuple_u = ("v1", "v2", "v3")
self.input_tuple_s = (str("v1"), str("v2"), str("v3"))

self.input_dict_u = {"k1": "v1", "k2": "v2"}
self.input_dict_s = {str("k1"): str("v1"), str("k2"): str("v2")}

def check_iter(self, iterable, iter_type, is_unicode):
check_type = unicode if is_unicode else str

iterable = utils.convert_item(iterable, is_unicode)

self.assertIsInstance(iterable, iter_type)

for item in iterable:
if iter_type == dict:
self.assertIsInstance(iterable[item], check_type)

self.assertIsInstance(item, check_type)

def test_convert_item_unicode_str(self):
self.assertIsInstance(utils.convert_item("test"), str)

def test_convert_item_unicode_unicode(self):
self.assertIsInstance(utils.convert_item("test", True), unicode)

def test_convert_item_str_unicode(self):
self.assertIsInstance(utils.convert_item(str("test"), True), unicode)

def test_convert_item_str_str(self):
self.assertIsInstance(utils.convert_item(str("test")), str)

def test_convert_item_list_empty(self):
self.assertEqual(len(utils.convert_item([])), 0)

def test_convert_item_dict_empty(self):
self.assertEqual(len(utils.convert_item({})), 0)

def test_convert_item_list_unicode_str(self):
self.check_iter(self.input_list_u, list, False)

def test_convert_item_list_str_unicode(self):
self.check_iter(self.input_list_s, list, True)

def test_convert_item_tuple_unicode_str(self):
self.check_iter(self.input_tuple_u, tuple, False)

def test_convert_item_tuple_str_unicode(self):
self.check_iter(self.input_tuple_s, tuple, True)

def test_convert_item_dict_unicode_str(self):
self.check_iter(self.input_dict_u, dict, False)

def test_convert_item_dict_str_unicode(self):
self.check_iter(self.input_dict_s, dict, True)

# removed TestConvertItem for Python 3, as str is unicode

class TestGetDefaultLang(unittest.TestCase):

Expand Down
Loading