Package elisa :: Package core :: Package tests :: Module test_utils_misc
[hide private]
[frames] | no frames]

Source Code for Module elisa.core.tests.test_utils_misc

  1  # Elisa - Home multimedia server 
  2  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
  3  # All rights reserved. 
  4  # 
  5  # This file is available under one of two license agreements. 
  6  # 
  7  # This file is licensed under the GPL version 3. 
  8  # See "LICENSE.GPL" in the root of this distribution including a special 
  9  # exception to use Elisa with Fluendo's plugins. 
 10  # 
 11  # The GPL part of Elisa is also available under a commercial licensing 
 12  # agreement from Fluendo. 
 13  # See "LICENSE.Elisa" in the root directory of this distribution package 
 14  # for details on that license. 
 15   
 16  from twisted.trial import unittest 
 17  from elisa.core.tests.elisa_test_case import ElisaTestCase 
 18  from elisa.core.utils import misc 
 19  from elisa.core import media_uri 
 20  import os, platform 
 21  import random, string 
 22   
23 -class TestMisc(ElisaTestCase):
24
25 - def _random_string(self, length=10):
26 return ''.join(random.sample(string.ascii_letters, length))
27
28 - def test_env_var_explode(self):
29 var_name = self._random_string() 30 31 os.environ[var_name] = '' 32 self.assertEquals(misc.env_var_explode_list(var_name), 33 []) 34 35 if platform.system() == 'Windows': 36 os.environ[var_name] = 'test;bar' 37 self.assertEquals(misc.env_var_explode_list(var_name), 38 ['test', 'bar']) 39 os.environ[var_name] = 'test:bar' 40 self.assertEquals(misc.env_var_explode_list(var_name), 41 ['test:bar',]) 42 else: 43 os.environ[var_name] = 'test;bar' 44 self.assertEquals(misc.env_var_explode_list(var_name), 45 ['test;bar',]) 46 os.environ[var_name] = 'test:bar' 47 self.assertEquals(misc.env_var_explode_list(var_name), 48 ['test','bar'])
49 50 51
52 - def test_env_var_expand(self):
53 54 if platform.system() == 'Windows': 55 raise unittest.SkipTest("Does not works under windows, need investigation") 56 57 platform_type = platform.system().lower() 58 59 var_name = self._random_string() 60 61 os.environ[var_name] = 'test!' 62 expanded = misc.env_var_expand('$%s' % var_name) 63 self.assertEquals(expanded, 'test!') 64 65 var_name2 = self._random_string() 66 os.environ[var_name2] = 'test2' 67 os.environ[var_name] = 'test:$%s' % var_name2 68 expanded = misc.env_var_expand('$%s' % var_name) 69 self.assertEquals(expanded, 'test:test2') 70 71 if platform_type == 'windows': 72 # TODO 73 pass 74 elif platform_type == 'linux': 75 expanded = misc.env_var_expand('$HOME/Music') 76 home = os.path.expanduser('~') 77 self.assertEquals(expanded, os.path.join(home, 'Music'))
78
79 - def test_uncamelify(self):
80 81 self.assertEquals(misc.un_camelify('F'), 'f') 82 self.assertEquals(misc.un_camelify('f'), 'f') 83 84 self.assertEquals(misc.un_camelify('FooBar'), 'foo_bar') 85 self.assertEquals(misc.un_camelify('Foo Bar'), 'foo_bar') 86 self.assertEquals(misc.un_camelify('fooBar'), 'foo_bar')
87
89 90 if platform.system() == 'Windows': 91 raise unittest.SkipTest("Does not works under windows, need investigation") 92 93 uris = {'file://./foo.mp3': ('audio/mpeg', 'audio'), 94 'file://./test.ogg': ('application/ogg', 'audio'), 95 'file://./test.ogm': ('', 'video'), 96 'file:///tmp': ('', '') 97 } 98 for uri, expected in uris.iteritems(): 99 infos = misc.get_media_infos_from_mime(media_uri.MediaUri(uri)) 100 self.assertEquals(infos, expected)
101