From 9993976ae436c62ef86c2c45f0f001e5f7e471bd Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Fri, 28 Sep 2012 14:06:37 +0200 Subject: correction on the sanitize title method, change in title resulting --- test/test_utils.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 test/test_utils.py (limited to 'test/test_utils.py') diff --git a/test/test_utils.py b/test/test_utils.py new file mode 100644 index 000000000..614ef1b03 --- /dev/null +++ b/test/test_utils.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- + +# Various small unit tests + +from youtube_dl.utils import sanitize_filename + +def test_sanitize_filename(): + assert sanitize_filename(u'abc') == u'abc' + assert sanitize_filename(u'abc_d-e') == u'abc_d-e' + + assert sanitize_filename(u'123') == u'123' + + assert u'/' not in sanitize_filename(u'abc/de') + assert u'abc' in sanitize_filename(u'abc/de') + assert u'de' in sanitize_filename(u'abc/de') + assert u'/' not in sanitize_filename(u'abc/de///') + + assert u'\\' not in sanitize_filename(u'abc\\de') + assert u'abc' in sanitize_filename(u'abc\\de') + assert u'de' in sanitize_filename(u'abc\\de') + + assert sanitize_filename(u'ä') == u'ä' + assert sanitize_filename(u'кириллица') == u'кириллица' -- cgit v1.2.3 From 44fb345437553801184377dde05cc8a312fd2da2 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Fri, 28 Sep 2012 14:47:01 +0200 Subject: adding TestCase class and corresponding test --- test/test_utils.py | 51 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 13 deletions(-) (limited to 'test/test_utils.py') diff --git a/test/test_utils.py b/test/test_utils.py index 614ef1b03..d4b4cb920 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -2,22 +2,47 @@ # Various small unit tests +import unittest + +#from youtube_dl.utils import htmlentity_transform +from youtube_dl.utils import timeconvert from youtube_dl.utils import sanitize_filename +from youtube_dl.utils import unescapeHTML +from youtube_dl.utils import orderedSet + + +class TestUtil(unittest.TestCase): + def test_timeconvert(self): + self.assertIsNone(timeconvert('')) + self.assertIsNone(timeconvert('bougrg')) + + def test_sanitize_filename(self): + self.assertEqual(sanitize_filename(u'abc'), u'abc') + self.assertEqual(sanitize_filename(u'abc_d-e'), u'abc_d-e') + + self.assertEqual(sanitize_filename(u'123'), u'123') + + self.assertNotIn(u'/', sanitize_filename(u'abc/de')) + self.assertNotIn(u'abc', sanitize_filename(u'abc/de')) + self.assertIn(u'de', sanitize_filename(u'abc/de')) + self.assertNotIn(u'/', sanitize_filename(u'abc/de///')) + + self.assertIn(u'\\', sanitize_filename(u'abc\\de')) + self.assertIn(u'abc', sanitize_filename(u'abc\\de')) + self.assertIn(u'de', sanitize_filename(u'abc\\de')) -def test_sanitize_filename(): - assert sanitize_filename(u'abc') == u'abc' - assert sanitize_filename(u'abc_d-e') == u'abc_d-e' + self.assertEqual(sanitize_filename(u'ä'), u'ä') + self.assertEqual(sanitize_filename(u'кириллица'), u'кириллица') - assert sanitize_filename(u'123') == u'123' + def test_ordered_set(self): + self.assertEqual(orderedSet([1,1,2,3,4,4,5,6,7,3,5]), [1,2,3,4,5,6,7]) + self.assertEqual(orderedSet([]), []) + self.assertEqual(orderedSet([1]), [1]) + #keep the list ordered + self.assertEqual(orderedSet([135,1,1,1]), [135,1]) - assert u'/' not in sanitize_filename(u'abc/de') - assert u'abc' in sanitize_filename(u'abc/de') - assert u'de' in sanitize_filename(u'abc/de') - assert u'/' not in sanitize_filename(u'abc/de///') + def test_unescape_html(self): + self.assertEqual(unescapeHTML(u"%20;"), u"%20;") + self.assertEqual(unescapeHTML(u"gre&tre&yre"), [u'gre', u'tre', u'yre']) - assert u'\\' not in sanitize_filename(u'abc\\de') - assert u'abc' in sanitize_filename(u'abc\\de') - assert u'de' in sanitize_filename(u'abc\\de') - assert sanitize_filename(u'ä') == u'ä' - assert sanitize_filename(u'кириллица') == u'кириллица' -- cgit v1.2.3 From 80a846e119af18bb7da005c3d267a7af7a7b6a0d Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Fri, 28 Sep 2012 18:00:20 +0200 Subject: correction on the test for the utils.py --- test/test_utils.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'test/test_utils.py') diff --git a/test/test_utils.py b/test/test_utils.py index d4b4cb920..910fcfad4 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -22,13 +22,12 @@ class TestUtil(unittest.TestCase): self.assertEqual(sanitize_filename(u'123'), u'123') - self.assertNotIn(u'/', sanitize_filename(u'abc/de')) - self.assertNotIn(u'abc', sanitize_filename(u'abc/de')) + self.assertEqual(u'abc_de', sanitize_filename(u'abc/de')) self.assertIn(u'de', sanitize_filename(u'abc/de')) self.assertNotIn(u'/', sanitize_filename(u'abc/de///')) - self.assertIn(u'\\', sanitize_filename(u'abc\\de')) - self.assertIn(u'abc', sanitize_filename(u'abc\\de')) + self.assertEqual(u'abc_de', sanitize_filename(u'abc\\de')) + self.assertEqual(u'abc_de', sanitize_filename(u'abc\\de')) self.assertIn(u'de', sanitize_filename(u'abc\\de')) self.assertEqual(sanitize_filename(u'ä'), u'ä') @@ -43,6 +42,5 @@ class TestUtil(unittest.TestCase): def test_unescape_html(self): self.assertEqual(unescapeHTML(u"%20;"), u"%20;") - self.assertEqual(unescapeHTML(u"gre&tre&yre"), [u'gre', u'tre', u'yre']) -- cgit v1.2.3 From 137c5803c35f3e06d821ede1ef69733c3b8d338c Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Wed, 3 Oct 2012 14:25:54 +0200 Subject: some changes to keep the same standard --- test/test_utils.py | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) (limited to 'test/test_utils.py') diff --git a/test/test_utils.py b/test/test_utils.py index 910fcfad4..fd3ac4d46 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -12,35 +12,33 @@ from youtube_dl.utils import orderedSet class TestUtil(unittest.TestCase): - def test_timeconvert(self): - self.assertIsNone(timeconvert('')) - self.assertIsNone(timeconvert('bougrg')) + def test_timeconvert(self): + self.assertIsNone(timeconvert('')) + self.assertIsNone(timeconvert('bougrg')) - def test_sanitize_filename(self): - self.assertEqual(sanitize_filename(u'abc'), u'abc') - self.assertEqual(sanitize_filename(u'abc_d-e'), u'abc_d-e') + def test_sanitize_filename(self): + self.assertEqual(sanitize_filename(u'abc'), u'abc') + self.assertEqual(sanitize_filename(u'abc_d-e'), u'abc_d-e') - self.assertEqual(sanitize_filename(u'123'), u'123') + self.assertEqual(sanitize_filename(u'123'), u'123') - self.assertEqual(u'abc_de', sanitize_filename(u'abc/de')) - self.assertIn(u'de', sanitize_filename(u'abc/de')) - self.assertNotIn(u'/', sanitize_filename(u'abc/de///')) + self.assertEqual(u'abc_de', sanitize_filename(u'abc/de')) + self.assertIn(u'de', sanitize_filename(u'abc/de')) + self.assertNotIn(u'/', sanitize_filename(u'abc/de///')) - self.assertEqual(u'abc_de', sanitize_filename(u'abc\\de')) - self.assertEqual(u'abc_de', sanitize_filename(u'abc\\de')) - self.assertIn(u'de', sanitize_filename(u'abc\\de')) + self.assertEqual(u'abc_de', sanitize_filename(u'abc\\de')) + self.assertEqual(u'abc_de', sanitize_filename(u'abc\\de')) + self.assertIn(u'de', sanitize_filename(u'abc\\de')) - self.assertEqual(sanitize_filename(u'ä'), u'ä') - self.assertEqual(sanitize_filename(u'кириллица'), u'кириллица') - - def test_ordered_set(self): - self.assertEqual(orderedSet([1,1,2,3,4,4,5,6,7,3,5]), [1,2,3,4,5,6,7]) - self.assertEqual(orderedSet([]), []) - self.assertEqual(orderedSet([1]), [1]) - #keep the list ordered - self.assertEqual(orderedSet([135,1,1,1]), [135,1]) - - def test_unescape_html(self): - self.assertEqual(unescapeHTML(u"%20;"), u"%20;") + self.assertEqual(sanitize_filename(u'ä'), u'ä') + self.assertEqual(sanitize_filename(u'кириллица'), u'кириллица') + def test_ordered_set(self): + self.assertEqual(orderedSet([1,1,2,3,4,4,5,6,7,3,5]), [1,2,3,4,5,6,7]) + self.assertEqual(orderedSet([]), []) + self.assertEqual(orderedSet([1]), [1]) + #keep the list ordered + self.assertEqual(orderedSet([135,1,1,1]), [135,1]) + def test_unescape_html(self): + self.assertEqual(unescapeHTML(u"%20;"), u"%20;") -- cgit v1.2.3 From 4279a0ca983476a0bdf86e23251b866616cbd434 Mon Sep 17 00:00:00 2001 From: gcmalloc Date: Mon, 15 Oct 2012 14:34:54 +0200 Subject: correcting test to be compatible with python2.6 --- test/test_utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test/test_utils.py') diff --git a/test/test_utils.py b/test/test_utils.py index fd3ac4d46..eb0af703f 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -13,8 +13,8 @@ from youtube_dl.utils import orderedSet class TestUtil(unittest.TestCase): def test_timeconvert(self): - self.assertIsNone(timeconvert('')) - self.assertIsNone(timeconvert('bougrg')) + self.assertTrue(timeconvert('') is None) + self.assertTrue(timeconvert('bougrg') is None) def test_sanitize_filename(self): self.assertEqual(sanitize_filename(u'abc'), u'abc') @@ -23,12 +23,12 @@ class TestUtil(unittest.TestCase): self.assertEqual(sanitize_filename(u'123'), u'123') self.assertEqual(u'abc_de', sanitize_filename(u'abc/de')) - self.assertIn(u'de', sanitize_filename(u'abc/de')) - self.assertNotIn(u'/', sanitize_filename(u'abc/de///')) + self.assertTrue(u'de' in sanitize_filename(u'abc/de')) + self.assertFalse(u'/' in sanitize_filename(u'abc/de///')) self.assertEqual(u'abc_de', sanitize_filename(u'abc\\de')) self.assertEqual(u'abc_de', sanitize_filename(u'abc\\de')) - self.assertIn(u'de', sanitize_filename(u'abc\\de')) + self.assertTrue(u'de' in sanitize_filename(u'abc\\de')) self.assertEqual(sanitize_filename(u'ä'), u'ä') self.assertEqual(sanitize_filename(u'кириллица'), u'кириллица') -- cgit v1.2.3