Chromium Code Reviews| Index: webrtc/tools/run_video_analysis_unittest.py |
| diff --git a/webrtc/tools/run_video_analysis_unittest.py b/webrtc/tools/run_video_analysis_unittest.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..5802ca1c2bd77120694d95f37d525ecaced56d4e |
| --- /dev/null |
| +++ b/webrtc/tools/run_video_analysis_unittest.py |
| @@ -0,0 +1,58 @@ |
| +#!/usr/bin/env python |
|
kjellander_webrtc
2017/04/04 14:44:23
Rename this file to run_video_analysis_test.py
It
|
| +# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| +# |
| +# Use of this source code is governed by a BSD-style license |
| +# that can be found in the LICENSE file in the root of the source |
| +# tree. An additional intellectual property rights grant can be found |
| +# in the file PATENTS. All contributing project authors may |
| +# be found in the AUTHORS file in the root of the source tree. |
| + |
| +import unittest |
| +from run_video_analysis import FindUsbPortForV4lDevices |
| +import glob |
|
kjellander_webrtc
2017/04/04 14:44:23
sort "import glob" before "import unittest"
|
| + |
| + |
| +class RunVideoAnalysisTest(unittest.TestCase): |
| + def setGlobPath(self, path1, path2): |
| + self.path1 = path1 |
| + self.path2 = path2 |
| + |
| + def setUp(self): |
| + self.path1 = '' |
| + self.path2 = '' |
| + self.requestNbr = 1 |
| + |
| + def glob_mock(): |
| + if self.requestNbr == 1: |
| + self.requestNbr += 1 |
| + return self.path1 |
| + else: |
| + self.requestNbr = 1 |
| + return self.path2 |
| + |
| + # Override the glob function with our own that returns a string set by the |
| + # test. |
| + glob.glob = glob_mock |
| + |
| + # Verifies that the correct USB id is returned. |
| + def testFindUSBPortForV4lDevices(self): |
| + short_path1 = ('/sys/bus/usb/devices/usb1/1-1/driver/4-4/4-4:1.0/' |
| + 'video4linux/video0') |
| + short_path2 = ('/sys/bus/usb/devices/usb1/1-1/driver/4-3/4-3:1.0/' |
| + 'video4linux/video1') |
| + self.setGlobPath(short_path1, short_path2) |
| + short_usb_ids = ['4-4', '4-3'] |
| + self.assertEqual(FindUsbPortForV4lDevices('video0', 'video1'), |
| + short_usb_ids) |
| + |
| + long_path1 = ('/sys/bus/usb/devices/usb1/1-1/driver/3-3/3-3.1:1.0/' |
| + 'video4linux/video0') |
| + long_path2 = ('/sys/bus/usb/devices/usb1/1-1/driver/3-2/3-2.1:1.0/' |
| + 'video4linux/video1') |
| + self.setGlobPath(long_path1, long_path2) |
| + long_usb_ids = ['3-3.1', '3-2.1'] |
| + self.assertEqual(FindUsbPortForV4lDevices('video0', 'video1'), long_usb_ids) |
| + |
| + |
| +if __name__ == "__main__": |
| + unittest.main() |