Junsong Li
unread,Mar 27, 2013, 5:10:12 AM3/27/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to lamb...@googlegroups.com, skina...@126.com
Hi,
The unittest is coming. The unittest.py is in python-lib directory, and you can directly use import unittest to get the module. Here are two examples(by default, the debug is on, you can turn it off):
ljs@Candy-2:~/github/lambda-py/base$ racket python-main.rkt --python-path `which python3` --interp < modules/test_unary.py
[unittest debug] starts to find tests
[unittest debug] test found: UnaryOpTestCase
[unittest debug] begin to run
test_negative (<class UnaryOpTestCase>)
ok
test_invert (<class UnaryOpTestCase>)
ok
test_positive (<class UnaryOpTestCase>)
ok
Ran 3 tests
OK
ljs@Candy-2:~/github/lambda-py/base$ racket python-main.rkt --python-path `which python3` --interp < modules/test_1.py
[unittest debug] starts to find tests
[unittest debug] test found: TestClass1
[unittest debug] test found: TestClass2
[unittest debug] begin to run
test_1 (<class TestClass1>)
ok
test_11 (<class TestClass1>)
FAIL
test_2 (<class TestClass2>)
ok
test_24 (<class TestClass2>)
ok
test_22 (<class TestClass2>)
ok
Ran 5 tests
FAILED( failures=1 )
Two things to NOTE:
1.
the unittest relies heavily on __main__ modules, but the __main__module is still not perfect. The __main__ module is constructed at the beginning of a program, collecting global variables information(symbols and their address), and then __main__ module is assign by (CObject '$module (none) (filtered env)), where (filtered env) is the hash of non-builtin-id and their address.
However, This method actually has a serious bug. Look at this example
x = 1
y = 2
print(__main__.__dict__)
z = 3
exception: local variable 'val' referenced before assignment
the 'z' in __main__, which is something like (CObject '$module (none) #hash((x . 68361) (y . 68362) (z . 68372)), is used before 'z' is assigned, so exception happens.
Along with this bug, since our interpreter will treat unrecognized id as global id, any small, unintentional scope problem will cause the __main__ module failed and will raise exception.
2.
Now the sys.modules['__main__'] does not equal with __main__ yet. use __main__ to retrieve globals information if you need, like:
def globals():
return __main__.__dict__
I don't know if we still have time to improve it or not, but, anyway, the unittest is working now.
Cheers,
Junsong