def test_update_from_package(): gearshift.update_config(modulename="gearshift.tests.config") assert gearshift.config.get("foo.bar") == "BAZ!" print gearshift.config.get("my.static") assert gearshift.config.get("my.static").endswith( "gearshift%stests/static" % os.path.sep) assert gearshift.config.app["/static"]["tools.staticdir.on"] == True
def test_update_from_both(): gearshift.update_config(configfile=testfile, modulename="gearshift.tests.config") print gearshift.config.get("foo.bar") assert gearshift.config.get("foo.bar") == "blurb" assert gearshift.config.get("tg.something") == 10 print gearshift.config.get("test.dir") assert gearshift.config.get("test.dir").endswith("gearshift%stests" % os.path.sep)
def test_update_from_both(): gearshift.update_config(configfile = testfile, modulename="gearshift.tests.config") print gearshift.config.get("foo.bar") assert gearshift.config.get("foo.bar") == "blurb" assert gearshift.config.get("tg.something") == 10 print gearshift.config.get("test.dir") assert gearshift.config.get("test.dir").endswith( "gearshift%stests" % os.path.sep)
def test_update_on_windows(): """gearshift.update_config works as we intend on Windows. """ # save the original function orig_resource_fn = pkg_resources.resource_filename # monkey patch pkg resources to emulate windows pkg_resources.resource_filename = windows_filename gearshift.update_config(configfile=testfile, modulename="gearshift.tests.config") testdir = gearshift.config.get("test.dir") # update_config calls os.normpath on package_dir, but this will have no # effect on non-windows systems, so we call ntpath.normpath on those here if not sys.platform.startswith('win'): testdir = ntpath.normpath(testdir) # restore original function pkg_resources.resource_filename = orig_resource_fn assert testdir == "c:\\foo\\bar"
os.remove(f) # Load test configuration if os.path.exists('test.cfg'): # Look for a 'config' package for dirpath, dirs, dummy2 in os.walk('.'): basename = os.path.basename(dirpath) dirname = os.path.normpath(os.path.dirname(dirpath)) init_py = os.path.join(dirpath, '__init__.py') if basename == 'config' and os.path.exists(init_py) and \ dirname[0] in string.ascii_letters + '_': modulename = "%s.app" % dirpath[2:].replace(os.sep, ".") break else: modulename = None update_config(configfile="test.cfg", modulename=modulename) else: database.set_db_uri("sqlite:///:memory:") config.update({'global': {'autoreload.on': False, 'tg.new_style_logging': True, 'tools.expose.on' : True}}) def start_server(): """Start the server if it's not already.""" if not config.get("cp_started"): cherrypy.engine.start() config.update({"cp_started" : True}) if not config.get("server_started"): startup.startTurboGears()