Changeset 5366
- Timestamp:
- 09/07/08 17:13:55 (4 months ago)
- Files:
-
- branches/1.0/turbogears/tests/test_config.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.0/turbogears/tests/test_config.py
r3366 r5366 1 import logging 2 import ntpath 3 import os 4 import re 5 import sys 6 7 from cStringIO import StringIO 8 9 import pkg_resources 1 10 import turbogears 2 import pkg_resources3 import sys4 from cStringIO import StringIO5 import logging6 import re7 8 testfile = pkg_resources.resource_filename(__name__, "configfile.cfg")9 11 10 12 rfn = pkg_resources.resource_filename 13 testfile = rfn(__name__, "configfile.cfg") 11 14 12 15 logout = StringIO() 13 16 logging.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... 14 20 15 21 def test_update_from_package(): … … 18 24 print turbogears.config.get("my.static") 19 25 assert turbogears.config.get("my.static").endswith( 20 "turbogears/tests/static")26 "turbogears%stests/static" % os.path.sep) 21 27 assert turbogears.config.get("static_filter.on", path="/static") == True 22 28 … … 28 34 assert turbogears.config.get("tg.something") == 10 29 35 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) 31 38 32 39 callnum = 0 33 40 34 41 def 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 """ 35 52 global callnum 36 53 callnum += 1 … … 40 57 return rfn(*args, **kw) 41 58 42 def test_windows_filenames(): 59 def 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 43 65 pkg_resources.resource_filename = windows_filename 44 turbogears.update_config(configfile = testfile, 66 67 turbogears.update_config(configfile=testfile, 45 68 modulename="turbogears.tests.config") 46 69 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" 49 78 50 79 def test_logging_config(): … … 57 86 'Testing', logged) 58 87 assert turbogears.config.get("tg.new_style_logging", False) 59 60 def teardown_module():61 pkg_resources.resource_filename = rfn