From 57046be1262423c37a74ed607604a96730fcf189 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Tue, 12 Feb 2019 16:45:44 -0800 Subject: [PATCH] Make packager_test.py work with python 3.5 Addresses binary/str conversion problems like 'can't use a string pattern on a bytes-like object'. With this change, packager_test.py will work with any version of python after python2.5. Fixes #553. Change-Id: I02066942e4bcdddc1db1daf761abab4cc46169a9 --- packager/app/test/packager_app.py | 4 ++-- packager/app/test/packager_test.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packager/app/test/packager_app.py b/packager/app/test/packager_app.py index 81da80bcce..5bc97e6b98 100644 --- a/packager/app/test/packager_app.py +++ b/packager/app/test/packager_app.py @@ -45,11 +45,11 @@ class PackagerApp(object): def DumpStreamInfo(self, stream): input_str = 'input=%s' % stream cmd = [self.packager_binary, input_str, '--dump_stream_info'] - return subprocess.check_output(cmd, env=self.GetEnv()) + return subprocess.check_output(cmd, env=self.GetEnv()).decode() def Version(self): return subprocess.check_output( - [self.packager_binary, '--version'], env=self.GetEnv()) + [self.packager_binary, '--version'], env=self.GetEnv()).decode() def Package(self, streams, flags=None): """Executes packager command.""" diff --git a/packager/app/test/packager_test.py b/packager/app/test/packager_test.py index 1759837b66..38c420404b 100755 --- a/packager/app/test/packager_test.py +++ b/packager/app/test/packager_test.py @@ -173,7 +173,7 @@ def _UpdateMediaInfoPaths(media_info_filepath): # after: media_file_name: "bear-640x360-audio.mp4" with open(media_info_filepath, 'rb') as f: - content = f.read() + content = f.read().decode() regex = 'media_file_name: "(.*)"' for path in re.findall(regex, content): @@ -181,7 +181,7 @@ def _UpdateMediaInfoPaths(media_info_filepath): content = content.replace(path, short_path) with open(media_info_filepath, 'wb') as f: - f.write(content) + f.write(content.encode()) def _UpdateMpdTimes(mpd_filepath): @@ -200,7 +200,7 @@ def _UpdateMpdTimes(mpd_filepath): return out with open(mpd_filepath, 'rb') as f: - content = f.read() + content = f.read().decode() content = _Replace( content, @@ -213,7 +213,7 @@ def _UpdateMpdTimes(mpd_filepath): 'publishTime="some_time"') with open(mpd_filepath, 'wb') as f: - f.write(content) + f.write(content.encode()) def GetExtension(input_file_path, output_format):