mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-12-20 03:54:01 +00:00
[utils] Allow None in remove_{start,end}
This commit is contained in:
parent
b78531a36a
commit
46bc9b7d7c
@ -50,6 +50,8 @@ from youtube_dl.utils import (
|
|||||||
sanitize_path,
|
sanitize_path,
|
||||||
prepend_extension,
|
prepend_extension,
|
||||||
replace_extension,
|
replace_extension,
|
||||||
|
remove_start,
|
||||||
|
remove_end,
|
||||||
remove_quotes,
|
remove_quotes,
|
||||||
shell_quote,
|
shell_quote,
|
||||||
smuggle_url,
|
smuggle_url,
|
||||||
@ -215,6 +217,16 @@ class TestUtil(unittest.TestCase):
|
|||||||
self.assertEqual(replace_extension('.abc', 'temp'), '.abc.temp')
|
self.assertEqual(replace_extension('.abc', 'temp'), '.abc.temp')
|
||||||
self.assertEqual(replace_extension('.abc.ext', 'temp'), '.abc.temp')
|
self.assertEqual(replace_extension('.abc.ext', 'temp'), '.abc.temp')
|
||||||
|
|
||||||
|
def test_remove_start(self):
|
||||||
|
self.assertEqual(remove_start(None, 'A - '), None)
|
||||||
|
self.assertEqual(remove_start('A - B', 'A - '), 'B')
|
||||||
|
self.assertEqual(remove_start('B - A', 'A - '), 'B - A')
|
||||||
|
|
||||||
|
def test_remove_end(self):
|
||||||
|
self.assertEqual(remove_end(None, ' - B'), None)
|
||||||
|
self.assertEqual(remove_end('A - B', ' - B'), 'A')
|
||||||
|
self.assertEqual(remove_end('B - A', ' - B'), 'B - A')
|
||||||
|
|
||||||
def test_remove_quotes(self):
|
def test_remove_quotes(self):
|
||||||
self.assertEqual(remove_quotes(None), None)
|
self.assertEqual(remove_quotes(None), None)
|
||||||
self.assertEqual(remove_quotes('"'), '"')
|
self.assertEqual(remove_quotes('"'), '"')
|
||||||
|
@ -1549,15 +1549,11 @@ def setproctitle(title):
|
|||||||
|
|
||||||
|
|
||||||
def remove_start(s, start):
|
def remove_start(s, start):
|
||||||
if s.startswith(start):
|
return s[len(start):] if s is not None and s.startswith(start) else s
|
||||||
return s[len(start):]
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
def remove_end(s, end):
|
def remove_end(s, end):
|
||||||
if s.endswith(end):
|
return s[:-len(end)] if s is not None and s.endswith(end) else s
|
||||||
return s[:-len(end)]
|
|
||||||
return s
|
|
||||||
|
|
||||||
|
|
||||||
def remove_quotes(s):
|
def remove_quotes(s):
|
||||||
|
Loading…
Reference in New Issue
Block a user