OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python2.4 |
| 2 # Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 '''Unit test that checks some of util functions. |
| 7 ''' |
| 8 |
| 9 import os |
| 10 import sys |
| 11 if __name__ == '__main__': |
| 12 sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '..')) |
| 13 |
| 14 import unittest |
| 15 |
| 16 from grit import util |
| 17 |
| 18 |
| 19 class UtilUnittest(unittest.TestCase): |
| 20 ''' Tests functions from util |
| 21 ''' |
| 22 |
| 23 def testNewClassInstance(self): |
| 24 # Test short class name with no fully qualified package name |
| 25 # Should fail, it is not supported by the function now (as documented) |
| 26 cls = util.NewClassInstance('grit.util.TestClassToLoad', |
| 27 TestBaseClassToLoad) |
| 28 self.failUnless(cls == None) |
| 29 |
| 30 # Test non existent class name |
| 31 cls = util.NewClassInstance('grit.util_unittest.NotExistingClass', |
| 32 TestBaseClassToLoad) |
| 33 self.failUnless(cls == None) |
| 34 |
| 35 # Test valid class name and valid base class |
| 36 cls = util.NewClassInstance('grit.util_unittest.TestClassToLoad', |
| 37 TestBaseClassToLoad) |
| 38 self.failUnless(isinstance(cls, TestBaseClassToLoad)) |
| 39 |
| 40 # Test valid class name with wrong hierarchy |
| 41 cls = util.NewClassInstance('grit.util_unittest.TestClassNoBase', |
| 42 TestBaseClassToLoad) |
| 43 self.failUnless(cls == None) |
| 44 |
| 45 def testCanonicalLanguage(self): |
| 46 self.failUnless(util.CanonicalLanguage('en') == 'en') |
| 47 self.failUnless(util.CanonicalLanguage('pt_br') == 'pt-BR') |
| 48 self.failUnless(util.CanonicalLanguage('pt-br') == 'pt-BR') |
| 49 self.failUnless(util.CanonicalLanguage('pt-BR') == 'pt-BR') |
| 50 self.failUnless(util.CanonicalLanguage('pt/br') == 'pt-BR') |
| 51 self.failUnless(util.CanonicalLanguage('pt/BR') == 'pt-BR') |
| 52 self.failUnless(util.CanonicalLanguage('no_no_bokmal') == 'no-NO-BOKMAL') |
| 53 |
| 54 def testUnescapeHtml(self): |
| 55 self.failUnless(util.UnescapeHtml('ϲ') == unichr(1010)) |
| 56 self.failUnless(util.UnescapeHtml('ꯍ') == unichr(43981)) |
| 57 |
| 58 class TestBaseClassToLoad(object): |
| 59 pass |
| 60 |
| 61 class TestClassToLoad(TestBaseClassToLoad): |
| 62 pass |
| 63 |
| 64 class TestClassNoBase(object): |
| 65 pass |
| 66 |
| 67 |
| 68 if __name__ == '__main__': |
| 69 unittest.main() |
| 70 |
OLD | NEW |