"Fossies" - the Fresh Open Source Software Archive

Member "cheetah3-3.2.6.post2/Cheetah/Tests/NameMapper_pure.py" (20 Apr 2021, 1265 Bytes) of package /linux/www/cheetah3-3.2.6.post2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "NameMapper_pure.py": 3-3.2.2_vs_3-3.2.3.

    1 import sys
    2 import unittest
    3 
    4 try:
    5     from Cheetah import _namemapper  # noqa
    6 except ImportError:
    7     # _namemapper hasn't been compiled so Tests/NameMapper.py
    8     # tests pure-python NameMapper.py; no need to duplicate these tests.
    9     pass
   10 
   11 
   12 def _setNameMapperFunctions():
   13     from Cheetah.NameMapper import NotFound, \
   14         valueForName, valueFromSearchList, valueFromFrame, \
   15         valueFromFrameOrSearchList
   16     from Cheetah.Tests import NameMapper
   17     for func in [
   18         NotFound, valueForName, valueFromSearchList,
   19         valueFromFrame, valueFromFrameOrSearchList
   20     ]:
   21         setattr(NameMapper, func.__name__, func)
   22 
   23 
   24 def setUpModule():
   25     if 'Cheetah.NameMapper' in sys.modules:
   26         del sys.modules['Cheetah.NameMapper']
   27     sys.modules['Cheetah._namemapper'] = None  # emulate absence of the module
   28     _setNameMapperFunctions()
   29 
   30 
   31 def tearDownModule():
   32     del sys.modules['Cheetah.NameMapper']
   33     del sys.modules['Cheetah._namemapper']
   34     del sys.modules['Cheetah.Tests.NameMapper']
   35     _setNameMapperFunctions()  # restore NameMapper
   36 
   37 
   38 class NameMapperTest(unittest.TestCase):
   39     def test_valueForName(self):
   40         from Cheetah.NameMapper import valueForName
   41         self.assertEqual(valueForName('upper', 'upper', True), 'UPPER')