unittest is coming

2 views
Skip to first unread message

Junsong Li

unread,
Mar 27, 2013, 5:10:12 AM3/27/13
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

Joe Gibbs Politz

unread,
Mar 27, 2013, 9:41:54 AM3/27/13
to lamb...@googlegroups.com, skina...@126.com
Do you know if you can run any Python unit tests in their entirety with this?  Seems like there's probably still a long road ahead there.

I'm *really* glad we have a great start on this; it's forced us to handle a bunch of features that we wouldn't have otherwise.  For tomorrow's deadline, I'd honestly rather see more tests of the style we have now than trying to get this to work and not being able to say anything about it.

This will still be useful down the road: I'm going to follow up more tomorrow/Friday with some thoughts on the future of development for lambda-py.



--
You received this message because you are subscribed to the Google Groups "lambda-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lambda-py+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



Junsong Li

unread,
Mar 27, 2013, 8:33:37 PM3/27/13
to lamb...@googlegroups.com
No, we still cannot. I picked some easy tests from Lib/test/ and put them in the tests/modules/unittest/ a week ago. We cannot run those tests yet. There are really lots of things to do. If we want to run unit tests in their entirety, we need to do  many trivial things, like:

     - SyntaxError is not catched in lambda-py, OverflowError, etc. are still missing.
     - operations like pow, shift are still missing.
     - daily use methods like split, join, startwith are still missing.

Joe Gibbs Politz

unread,
Mar 27, 2013, 8:38:01 PM3/27/13
to lamb...@googlegroups.com
Yeah, that's sort of what I figured.  OK, well it's good that we have this start.  We can make progress on some of the easy stuff at a slower pace to make lambda-py more useful in the long run, we don't need it to submit the paper.
Reply all
Reply to author
Forward
0 new messages