#!/usr/bin/env python # Copyright (c) 2012 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file.
'''Unit test that checks some of util functions. '''
from __future__ import print_function
import os import sys if __name__ == '__main__':
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import unittest
import six
from grit import util
class UtilUnittest(unittest.TestCase): ''' Tests functions from util '''
def testNewClassInstance(self): # Test short class name with no fully qualified package name # Should fail, it is not supported by the function now (as documented)
cls = util.NewClassInstance('grit.util.TestClassToLoad',
TestBaseClassToLoad)
self.failUnless(cls == None)
# Test non existent class name
cls = util.NewClassInstance('grit.util_unittest.NotExistingClass',
TestBaseClassToLoad)
self.failUnless(cls == None)
# Test valid class name and valid base class
cls = util.NewClassInstance('grit.util_unittest.TestClassToLoad',
TestBaseClassToLoad)
self.failUnless(isinstance(cls, TestBaseClassToLoad))
# Test valid class name with wrong hierarchy
cls = util.NewClassInstance('grit.util_unittest.TestClassNoBase',
TestBaseClassToLoad)
self.failUnless(cls == None)
def testRelativePath(self): """ Verify that MakeRelativePath works in some tricky cases."""
def TestRelativePathCombinations(base_path, other_path, expected_result): """ Verify that the relative path function works for
the given paths regardless of whether ornot they end with
a trailing slash.""" for path1 in [base_path, base_path + os.path.sep]: for path2 in [other_path, other_path + os.path.sep]:
result = util.MakeRelativePath(path1, path2)
self.failUnless(result == expected_result)
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.