-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding some unit tests for the core.
- Loading branch information
Showing
5 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 *-* | ||
|
||
import ndb | ||
|
||
class MockDebugger(ndb.Debugger): | ||
|
||
def __init__(self): | ||
ndb.Debugger.__init__(self, 'mock.py') | ||
|
||
def run(self): | ||
# bla bla debugging | ||
self._state = ndb.STATE_TERMINATED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 *-* | ||
import tempfile | ||
import os | ||
import unittest | ||
|
||
import process | ||
|
||
|
||
class TestCodeExecutor(unittest.TestCase): | ||
|
||
code_a_eq_3 = '#/usr/env/python\na = 3' | ||
|
||
def test_load_file(self): | ||
# Write a small temporary script | ||
osfd, tp = tempfile.mkstemp() | ||
try: | ||
with os.fdopen(osfd, 'w') as fd: | ||
fd.write(self.code_a_eq_3) | ||
|
||
ce = process.CodeExecutor(filename=tp) | ||
self.assertEquals(ce._code.rstrip(), self.code_a_eq_3) | ||
finally: | ||
os.remove(tp) | ||
|
||
def test_run_with_file(self): | ||
# Write a small temporary script | ||
osfd, tp = tempfile.mkstemp() | ||
try: | ||
with os.fdopen(osfd, 'w') as fd: | ||
fd.write(self.code_a_eq_3) | ||
|
||
global_run = {'a': 2} | ||
ce = process.CodeExecutor(filename=tp) | ||
ce.run(global_run) | ||
self.assertEquals(global_run['a'], 3) | ||
finally: | ||
os.remove(tp) | ||
|
||
def test_load_string(self): | ||
ce = process.CodeExecutor(string=self.code_a_eq_3) | ||
self.assertEquals(ce._code.rstrip(), self.code_a_eq_3) | ||
|
||
def test_run_with_string(self): | ||
global_run = {'a': 2} | ||
ce = process.CodeExecutor(string=self.code_a_eq_3) | ||
ce.run(global_run) | ||
self.assertEquals(global_run['a'], 3) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 *-* | ||
""" | ||
This module provides RPC interaction with the debugger. | ||
""" | ||
|
||
import unittest | ||
import xmlrpclib | ||
import test.helpers | ||
|
||
import rpc_adapter | ||
import ndb | ||
|
||
|
||
class TestRPCDebuggerAdapter(unittest.TestCase): | ||
|
||
def test_start(self): | ||
tst_dbg = test.helpers.MockDebugger() | ||
|
||
self.assertEquals(tst_dbg._state, ndb.STATE_PAUSED) | ||
server = rpc_adapter.RPCDebuggerAdapter(tst_dbg) | ||
server.export_start() | ||
self.assertEquals(tst_dbg._state, ndb.STATE_RUNNING) | ||
server.export_stop() | ||
self.assertEquals(tst_dbg._state, ndb.STATE_TERMINATED) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 *-* | ||
import unittest | ||
|
||
import serialize | ||
|
||
|
||
class TestSerialization(unittest.TestCase): | ||
|
||
def test_serialize_basic(self): | ||
res = serialize.serialize('i', 'i', 1) | ||
self.assertEquals(res['name'], 'i') | ||
self.assertFalse(res['has_childs']) | ||
|
||
def test_serialize_flat_dict(self): | ||
f_dict = {'a': 'First','b': 'Second','c': 'Third'} | ||
res = serialize.serialize('f', 'f', f_dict) | ||
|
||
self.assertEquals(res['name'], 'f') | ||
self.assertTrue(res['has_childs']) | ||
self.assertEquals(res['type'], 'dict') | ||
self.assertEquals(len(res['childs']), 3) | ||
|
||
# Check the first child | ||
f_child = res['childs'][0] | ||
self.assertEquals(f_child['type'], 'str') | ||
|
||
def test_serialize_deep_dict(self): | ||
d_dict = { 'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [7, 8, 9]} | ||
res = serialize.serialize('d', 'd', d_dict, 2) | ||
|
||
self.assertEquals(res['name'], 'd') | ||
self.assertTrue(res['has_childs']) | ||
self.assertEquals(len(res['childs']), 3) | ||
|
||
# Check the first child | ||
f_child = res['childs'][0] | ||
self.assertTrue(f_child['has_childs']) | ||
self.assertEquals(f_child['type'], 'list') | ||
self.assertEquals(len(f_child['childs']), 3) | ||
|
||
def test_serialize_object(self): | ||
class _TestObject(object): | ||
"""Class object to test serialization of object types.""" | ||
def __init__(self): | ||
"""Testing method.""" | ||
self._attr = "a" | ||
def un_metodo(self, unarg = None): | ||
"""Testing method.""" | ||
return "Hola" + self._attr + repr(unarg) | ||
def otro_metodo(self): | ||
"""Testing method.""" | ||
return "Chau" + self._attr | ||
|
||
c_obj = _TestObject() | ||
res = serialize.serialize('c', 'c', c_obj) | ||
|
||
self.assertEquals(res['name'], 'c') | ||
self.assertTrue(res['has_childs']) | ||
self.assertEquals(res['type'], '_TestObject') | ||
# Check the first child | ||
f_child = res['childs'][0] | ||
self.assertEquals(f_child['type'], 'instancemethod') | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |