| 1 |
"Test rpc, coverage 20%." |
| 2 |
|
| 3 |
from idlelib import rpc |
| 4 |
import unittest |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
class CodePicklerTest(unittest.TestCase): |
| 9 |
|
| 10 |
def test_pickle_unpickle(self): |
| 11 |
def f(): return a + b + c |
| 12 |
func, (cbytes,) = rpc.pickle_code(f.__code__) |
| 13 |
self.assertIs(func, rpc.unpickle_code) |
| 14 |
self.assertIn(b'test_rpc.py', cbytes) |
| 15 |
code = rpc.unpickle_code(cbytes) |
| 16 |
self.assertEqual(code.co_names, ('a', 'b', 'c')) |
| 17 |
|
| 18 |
def test_code_pickler(self): |
| 19 |
self.assertIn(type((lambda:None).__code__), |
| 20 |
rpc.CodePickler.dispatch_table) |
| 21 |
|
| 22 |
def test_dumps(self): |
| 23 |
def f(): pass |
| 24 |
# The main test here is that pickling code does not raise. |
| 25 |
self.assertIn(b'test_rpc.py', rpc.dumps(f.__code__)) |
| 26 |
|
| 27 |
|
| 28 |
if __name__ == '__main__': |
| 29 |
unittest.main(verbosity=2) |