1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3# Copyright 2019 The Chromium OS Authors. All rights reserved. 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7"""Tests for misc.""" 8 9from __future__ import print_function 10 11__author__ = 'asharif@google.com (Ahmad Sharif)' 12 13# System modules 14import unittest 15 16# Local modules 17from cros_utils import misc 18 19 20class UtilsTest(unittest.TestCase): 21 """Tests for misc.""" 22 23 def testGetFilenameFromString(self): 24 string = 'a /b=c"d^$?\\' 25 filename = misc.GetFilenameFromString(string) 26 self.assertEqual(filename, 'a___bcd') 27 28 def testPrependMergeEnv(self): 29 var = 'USE' 30 use_flags = 'hello 123' 31 added_use_flags = 'bla bla' 32 env_string = '%s=%r' % (var, use_flags) 33 new_env_string = misc.MergeEnvStringWithDict(env_string, 34 {var: added_use_flags}) 35 expected_new_env = '%s=%r' % (var, ' '.join([added_use_flags, use_flags])) 36 self.assertEqual(new_env_string, ' '.join([env_string, expected_new_env])) 37 38 def testGetChromeOSVersionFromLSBVersion(self): 39 versions_dict = {'2630.0.0': '22', '2030.0.0': '19'} 40 f = misc.GetChromeOSVersionFromLSBVersion 41 for k, v in versions_dict.items(): 42 self.assertEqual(f(k), 'R%s-%s' % (v, k)) 43 44 def testPostpendMergeEnv(self): 45 var = 'USE' 46 use_flags = 'hello 123' 47 added_use_flags = 'bla bla' 48 env_string = '%s=%r' % (var, use_flags) 49 new_env_string = misc.MergeEnvStringWithDict(env_string, 50 {var: added_use_flags}, False) 51 expected_new_env = '%s=%r' % (var, ' '.join([use_flags, added_use_flags])) 52 self.assertEqual(new_env_string, ' '.join([env_string, expected_new_env])) 53 54 55if __name__ == '__main__': 56 unittest.main() 57