浏览代码

First tests

Philipp Hagemeister 13 年之前
父节点
当前提交
e33e3045c6
共有 3 个文件被更改,包括 25 次插入0 次删除
  1. 21 0
      test/test_div.py
  2. 2 0
      youtube-dl
  3. 2 0
      youtube_dl/__init__.py

+ 21 - 0
test/test_div.py

@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+
+# Various small unit tests
+
+import os,sys
+sys.path.append(os.path.dirname(os.path.dirname(__file__)))
+
+import youtube_dl
+
+def test_simplify_title():
+	assert youtube_dl._simplify_title('abc') == 'abc'
+	assert youtube_dl._simplify_title('abc_d-e') == 'abc_d-e'
+
+	assert '/' not in youtube_dl._simplify_title('abc/de')
+	assert 'abc' in youtube_dl._simplify_title('abc/de')
+	assert 'de' in youtube_dl._simplify_title('abc/de')
+
+	assert '\\' not in youtube_dl._simplify_title('abc\\de')
+	assert 'abc' in youtube_dl._simplify_title('abc\\de')
+	assert 'de' in youtube_dl._simplify_title('abc\\de')
+

+ 2 - 0
youtube-dl

@@ -279,6 +279,8 @@ def timeconvert(timestr):
 		timestamp = email.utils.mktime_tz(timetuple)
 	return timestamp
 
+def _simplify_title(title):
+	return re.sub(ur'[^\w\d_\-]+', u'_', title)
 
 class DownloadError(Exception):
 	"""Download Error exception.

+ 2 - 0
youtube_dl/__init__.py

@@ -279,6 +279,8 @@ def timeconvert(timestr):
 		timestamp = email.utils.mktime_tz(timetuple)
 	return timestamp
 
+def _simplify_title(title):
+	return re.sub(ur'[^\w\d_\-]+', u'_', title)
 
 class DownloadError(Exception):
 	"""Download Error exception.