Changeset 5366

Show
Ignore:
Timestamp:
09/07/08 17:13:55 (4 months ago)
Author:
carndt
Message:

Backport r5336 to 1.0 branch since r5328 broke test in test_config.py there too

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/turbogears/tests/test_config.py

    r3366 r5366  
     1import logging 
     2import ntpath 
     3import os 
     4import re 
     5import sys 
     6 
     7from cStringIO import StringIO 
     8 
     9import pkg_resources 
    110import turbogears 
    2 import pkg_resources 
    3 import sys 
    4 from cStringIO import StringIO 
    5 import logging 
    6 import re 
    7  
    8 testfile = pkg_resources.resource_filename(__name__, "configfile.cfg") 
    911 
    1012rfn = pkg_resources.resource_filename 
     13testfile = rfn(__name__, "configfile.cfg") 
    1114 
    1215logout = StringIO() 
    1316logging.logout = logout 
     17 
     18# last forward slash (the one before static) is hard coded in our config 
     19# file... all other path separators are calculated platform wise... 
    1420 
    1521def test_update_from_package(): 
     
    1824    print turbogears.config.get("my.static") 
    1925    assert turbogears.config.get("my.static").endswith( 
    20                                             "turbogears/tests/static"
     26            "turbogears%stests/static" % os.path.sep
    2127    assert turbogears.config.get("static_filter.on", path="/static") == True 
    2228 
     
    2834    assert turbogears.config.get("tg.something") == 10 
    2935    print turbogears.config.get("test.dir") 
    30     assert turbogears.config.get("test.dir").endswith("turbogears/tests") 
     36    assert turbogears.config.get("test.dir").endswith( 
     37        "turbogears%stests" % os.path.sep) 
    3138 
    3239callnum = 0 
    3340 
    3441def windows_filename(*args, **kw): 
     42    """Small helper function to emulate pkg_resources.resource_filename 
     43    as if it was called on a Wwindows system even if the tester is in fact 
     44    using Linux or Mac OS X. 
     45 
     46    We need to keep track how often the function was called, since 
     47    'turbogears.update_config' calls 'pkg_resources.resource_filename' at least 
     48    twice and we onyl want to return the fake Windows path the second and 
     49    following times. 
     50 
     51    """ 
    3552    global callnum 
    3653    callnum += 1 
     
    4057        return rfn(*args, **kw) 
    4158 
    42 def test_windows_filenames(): 
     59def test_update_on_windows(): 
     60    """turbogears.update_config works as we intend on Windows. 
     61    """ 
     62    # save the original function 
     63    orig_resource_fn = pkg_resources.resource_filename 
     64    # monkey patch pkg resources to emulate windows 
    4365    pkg_resources.resource_filename = windows_filename 
    44     turbogears.update_config(configfile = testfile, 
     66 
     67    turbogears.update_config(configfile=testfile, 
    4568        modulename="turbogears.tests.config") 
    4669    testdir = turbogears.config.get("test.dir") 
    47     print testdir 
    48     assert testdir == "c:/foo/bar" 
     70    # update_config calls os.normpath on package_dir, but this will have no 
     71    # effect on non-windows systems, so we call ntpath.normpath on those here 
     72    if not sys.platform.startswith('win'): 
     73        testdir = ntpath.normpath(testdir) 
     74 
     75    # restore original function 
     76    pkg_resources.resource_filename = orig_resource_fn 
     77    assert testdir == "c:\\foo\\bar" 
    4978 
    5079def test_logging_config(): 
     
    5786                    'Testing', logged) 
    5887    assert turbogears.config.get("tg.new_style_logging", False) 
    59  
    60 def teardown_module(): 
    61     pkg_resources.resource_filename = rfn