Home | History | Annotate | Download | only in cros_utils
      1 # Copyright 2012 Google Inc. All Rights Reserved.
      2 """Tests for misc."""
      3 
      4 from __future__ import print_function
      5 
      6 __author__ = 'asharif (at] google.com (Ahmad Sharif)'
      7 
      8 # System modules
      9 import unittest
     10 
     11 # Local modules
     12 import misc
     13 
     14 
     15 class UtilsTest(unittest.TestCase):
     16   """Tests for misc."""
     17 
     18   def testGetFilenameFromString(self):
     19     string = 'a /b=c"d^$?\\'
     20     filename = misc.GetFilenameFromString(string)
     21     self.assertEqual(filename, 'a___bcd')
     22 
     23   def testPrependMergeEnv(self):
     24     var = 'USE'
     25     use_flags = 'hello 123'
     26     added_use_flags = 'bla bla'
     27     env_string = '%s=%r' % (var, use_flags)
     28     new_env_string = misc.MergeEnvStringWithDict(env_string,
     29                                                  {var: added_use_flags})
     30     expected_new_env = '%s=%r' % (var, ' '.join([added_use_flags, use_flags]))
     31     self.assertEqual(new_env_string, ' '.join([env_string, expected_new_env]))
     32 
     33   def testGetChromeOSVersionFromLSBVersion(self):
     34     versions_dict = {'2630.0.0': '22', '2030.0.0': '19'}
     35     f = misc.GetChromeOSVersionFromLSBVersion
     36     for k, v in versions_dict.items():
     37       self.assertEqual(f(k), 'R%s-%s' % (v, k))
     38 
     39   def testPostpendMergeEnv(self):
     40     var = 'USE'
     41     use_flags = 'hello 123'
     42     added_use_flags = 'bla bla'
     43     env_string = '%s=%r' % (var, use_flags)
     44     new_env_string = misc.MergeEnvStringWithDict(env_string,
     45                                                  {var: added_use_flags}, False)
     46     expected_new_env = '%s=%r' % (var, ' '.join([use_flags, added_use_flags]))
     47     self.assertEqual(new_env_string, ' '.join([env_string, expected_new_env]))
     48 
     49 
     50 if __name__ == '__main__':
     51   unittest.main()
     52