1#! /usr/bin/env vpython3 2# Copyright 2016 The Chromium Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import os 7import unittest 8 9from pylib import constants 10from pylib.utils import device_dependencies 11 12 13class DevicePathComponentsForTest(unittest.TestCase): 14 15 def testCheckedInFile(self): 16 test_path = os.path.join(constants.DIR_SOURCE_ROOT, 'foo', 'bar', 'baz.txt') 17 output_directory = os.path.join( 18 constants.DIR_SOURCE_ROOT, 'out-foo', 'Release') 19 self.assertEqual([None, 'foo', 'bar', 'baz.txt'], 20 device_dependencies.DevicePathComponentsFor( 21 test_path, output_directory)) 22 23 def testOutputDirectoryFile(self): 24 test_path = os.path.join(constants.DIR_SOURCE_ROOT, 'out-foo', 'Release', 25 'icudtl.dat') 26 output_directory = os.path.join( 27 constants.DIR_SOURCE_ROOT, 'out-foo', 'Release') 28 self.assertEqual([None, 'icudtl.dat'], 29 device_dependencies.DevicePathComponentsFor( 30 test_path, output_directory)) 31 32 def testOutputDirectorySubdirFile(self): 33 test_path = os.path.join(constants.DIR_SOURCE_ROOT, 'out-foo', 'Release', 34 'test_dir', 'icudtl.dat') 35 output_directory = os.path.join( 36 constants.DIR_SOURCE_ROOT, 'out-foo', 'Release') 37 self.assertEqual([None, 'test_dir', 'icudtl.dat'], 38 device_dependencies.DevicePathComponentsFor( 39 test_path, output_directory)) 40 41 def testOutputDirectoryPakFile(self): 42 test_path = os.path.join(constants.DIR_SOURCE_ROOT, 'out-foo', 'Release', 43 'foo.pak') 44 output_directory = os.path.join( 45 constants.DIR_SOURCE_ROOT, 'out-foo', 'Release') 46 self.assertEqual([None, 'paks', 'foo.pak'], 47 device_dependencies.DevicePathComponentsFor( 48 test_path, output_directory)) 49 50 51class SubstituteDeviceRootTest(unittest.TestCase): 52 53 def testNoneDevicePath(self): 54 self.assertEqual( 55 '/fake/device/root', 56 device_dependencies.SubstituteDeviceRootSingle(None, 57 '/fake/device/root')) 58 59 def testStringDevicePath(self): 60 self.assertEqual( 61 '/another/fake/device/path', 62 device_dependencies.SubstituteDeviceRootSingle( 63 '/another/fake/device/path', '/fake/device/root')) 64 65 def testListWithNoneDevicePath(self): 66 self.assertEqual( 67 '/fake/device/root/subpath', 68 device_dependencies.SubstituteDeviceRootSingle([None, 'subpath'], 69 '/fake/device/root')) 70 71 def testListWithoutNoneDevicePath(self): 72 self.assertEqual( 73 '/another/fake/device/path', 74 device_dependencies.SubstituteDeviceRootSingle( 75 ['/', 'another', 'fake', 'device', 'path'], '/fake/device/root')) 76 77 78if __name__ == '__main__': 79 unittest.main() 80