# This goes to Fixtures/default.py
functional_test_dir = os.path.split(__file__)[0] + "/.." 

# And this is TestCases/all_tests.py
#{{{ Marathon Fixture
from default import *
#}}} Marathon Fixture

import sys
import os

test_cases_dir = functional_test_dir + "/TestCases" 

def load_test_cases(directory):
    test_cases_directory = test_cases_dir + "/" + directory
    sys.path.append(test_cases_directory)
    dir_list = os.listdir(test_cases_directory)
    test_case_files = filter(lambda fname:(fname.endswith(".py")), dir_list)
    return map(lambda fname:fname.split('.')[0], test_case_files)

test_cases = load_test_cases("open_tests")
test_cases += load_test_cases("view_tests")

for test_case in test_cases:
    exec "import %s" % test_case

def test():
    for test_case in test_cases:
        exec "%s.test()" % test_case

An Introduction to the Python Web Server Gateway Interface

WSGI is a specification, laid out in PEP 333 , for a standardized interface between Web servers and Python Web frameworks/applications.

The goal is to provide a relatively simple yet comprehensive interface capable of supporting all (or most) interactions between a Web server and a Web framework. (Think “CGI” but programmatic rather than I/O based.)

Choice is good; WSGI makes choice a matter of developer opinion rather than technical compatibility.

从Py2Erl开始的半天搜索

October 24th, 2007

(昨天发在ECUG的一个邮件,想了一下,还是放到自己blog上)

今天上午,尝试用ErlyWeb做一个petstore,最终被击败了。CaoYuan的blog帮了很大忙:
http://blogtrader.net/page/dcaoyuan/entry/from_rails_to_erlyweb_part2

结论:ErlyWeb在开发便利性方面距离Rails不是一点半点。尤其是view可用的工具太少,有太多东西要从头做起。用来做web前端,不仅有高射炮打蚊子之嫌,而且颇费劲。不靠谱。

中午写InfoQ的这个报道,其间看了一遍"Py2Erl"那个讲稿,兴趣起来了。
InfoQ报道:http://www.infoq.com/cn/news/2007/10/cn-erlounge-ii
讲稿:http://www.erlang.org.cn/ecug/071013-erlparty2/071014-py2erl/

找到了Stackless Python,写了一段小程序。好玩,靠谱。
Stackless Python:http://www.stackless.com/
抄一段小程序:http://gigix.thoughtworkers.org/2007/10/23/is-stackless-python-the-way
有人做了benchmark,差强人意吧
http://muharem.wordpress.com/2007/07/31/erlang-vs-stackless-python-a-...

函数式编程,现在已经不成其为卖点了。Erlang最吸引我的是"那种"对并发程序设计的建模方式。从stackless那里看到,原来这个模式叫Actors Model,有年头。
C2的解释:http://c2.com/cgi/wiki?ActorsModel
这篇文章非常好看:http://www.cypherpunks.to/erights/history/actors/AIM-410.pdf
这篇也好看,就是太玄虚了点:http://www.cypherpunks.to/erights/history/actors/AIM-691.pdf

好吧……Ruby咋样呢?继续人肉搜索……要说Ruby(和/或Python)社区从Erlang那里得到什么,直接转过去是可能性不大滴,主要还是(1)学习人家的先进思想;(2)混合语言编程。Ruby在这方面的努力,包括Ruby-Erlang bridging和自己实现Actors Model。
Erlectricity是一个bridge:http://code.google.com/p/erlectricity/
Rebar是另一个bridge,成熟度更低:http://rubyisawesome.com/2007/4/30/calling-erlang-from-ruby-teaser
Omnibus实现了Actors Model,成熟度也很低:http://groups.google.com/group/ruby-talk-google/browse_frm/thread/ec4...

拿着Omnibus玩了一会儿。这个语法写出来就等而下之了。看了看源代码,没有什么奇妙的,只是把Thread封装了一下而已。倒是future的概念,是用native C代码实现的。
又搞了一段小程序:http://gigix.thoughtworkers.org/2007/10/23/is-concurrent-ruby-better
什么是future? http://www.ps.uni-sb.de/alice/manual/futures.html

听说Ruby 1.9要加入一个叫做Fiber的东西。这个,把语法糖扔掉以后,和Omnibus基本上同一回事……
http://www.infoq.com/news/2007/08/ruby-1-9-fibers

还有一个围绕着Ruby线程模型的讨论。GIL会对并发编程造成什么影响呢?没认真去想。
http://www.infoq.com/news/2007/05/ruby-threading-futures

以上。

--
Jeff Xiong
Software Journeyman - http://gigix.thoughtworkers.org
Open Source Contributor - http://rubyworks.rubyforge.org
Technical Evangelist - http://www.infoq.com/cn/

Is Stackless Python THE Way?

October 23rd, 2007

Code with Stackless Python

#
# pingpong_stackless.py
#

import stackless

ping_channel = stackless.channel()
pong_channel = stackless.channel()

def ping():
    while ping_channel.receive(): #blocks here
        print "PING" 
        pong_channel.send("from ping")

def pong():
    while pong_channel.receive():
        print "PONG" 
        ping_channel.send("from pong")

stackless.tasklet(ping)()
stackless.tasklet(pong)()

# we need to 'prime' the game by sending a start message
# if not, both tasklets will block
stackless.tasklet(ping_channel.send)('startup')

stackless.run()

And it runs…forever.