You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.8 KiB

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2019 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Tests for misc."""
from __future__ import print_function
__author__ = 'asharif@google.com (Ahmad Sharif)'
# System modules
import unittest
# Local modules
from cros_utils import misc
class UtilsTest(unittest.TestCase):
"""Tests for misc."""
def testGetFilenameFromString(self):
string = 'a /b=c"d^$?\\'
filename = misc.GetFilenameFromString(string)
self.assertEqual(filename, 'a___bcd')
def testPrependMergeEnv(self):
var = 'USE'
use_flags = 'hello 123'
added_use_flags = 'bla bla'
env_string = '%s=%r' % (var, use_flags)
new_env_string = misc.MergeEnvStringWithDict(env_string,
{var: added_use_flags})
expected_new_env = '%s=%r' % (var, ' '.join([added_use_flags, use_flags]))
self.assertEqual(new_env_string, ' '.join([env_string, expected_new_env]))
def testGetChromeOSVersionFromLSBVersion(self):
versions_dict = {'2630.0.0': '22', '2030.0.0': '19'}
f = misc.GetChromeOSVersionFromLSBVersion
for k, v in versions_dict.items():
self.assertEqual(f(k), 'R%s-%s' % (v, k))
def testPostpendMergeEnv(self):
var = 'USE'
use_flags = 'hello 123'
added_use_flags = 'bla bla'
env_string = '%s=%r' % (var, use_flags)
new_env_string = misc.MergeEnvStringWithDict(env_string,
{var: added_use_flags}, False)
expected_new_env = '%s=%r' % (var, ' '.join([use_flags, added_use_flags]))
self.assertEqual(new_env_string, ' '.join([env_string, expected_new_env]))
if __name__ == '__main__':
unittest.main()