26
26
from boots.api.nodes.node import NodeGraph, SyncNode
27
27
from boots.app import client_config
28
28
from boots.lib import console
29
from boots.lib.lingos import lingo, bash_external, lisp, piped_sql, python, sql
29
from boots.lib.lingos import lingo, bash_external, piped_sql, python, sql
44
44
class LingoBaseTester(boots_unit_test.BootsBaseTester):
46
self.config = client_config.ClientConfig()
47
self.console = console.Console(self.config)
48
self.console.connect('capstonedd.cs.pdx.edu', 9306, 'fec')
46
self.console = console.Console(client_config.ClientConfig())
47
self.console.connect(self.config["host"], self.config["port"],
48
self.config["database"], self.config["username"],
49
self.config["password"])
50
51
def tearDown(self):
69
70
result = self.bash.evaluate('echo $(( 1 + 1 ))')[0]
70
71
self.assertEqual(result, '2')
72
class TestSQL(LingoBaseTester):
73
class TestSQL(LingoBaseTester, boots_unit_test.BootsQueryTester):
74
super(TestSQL, self).setUp()
75
boots_unit_test.BootsQueryTester.setUp(self)
76
LingoBaseTester.setUp(self)
75
77
self.sql = sql.SQLInterpreter(self.console)
77
79
def test_plus(self):
78
80
result = node_graph_values(self.sql.execute('select 1 + 1;'))[0][0][0]
79
81
self.assertEqual(result, '2')
81
class TestLisp(LingoBaseTester):
83
super(TestLisp, self).setUp()
84
self.lisp = lisp.lisp.LispInterpreter(self.console)
87
result = self.lisp.execute('(+ 1 2 3 4)').python_integer()
88
self.assertEqual(result, 10)
90
def test_recursion(self):
91
self.lisp.execute('(setq len (lambda (l) (if l (+ 1 (len (cdr l))) 0)))')
92
result = self.lisp.execute('(len \'(1 2 3 4))').python_integer()
93
self.assertEqual(result, 4)
94
result = self.lisp.execute('(len nil)').python_integer()
95
self.assertEqual(result, 0)
97
83
class TestPipedSQLInterpreter(TestSQL):
99
85
super(TestPipedSQLInterpreter, self).setUp()
105
91
graph = self.sql.execute(piped_sql_query)
108
self.assertEqual(len(open(temp).readlines()), 1458)
94
self.assertEqual(len(open(temp).readlines()), 1463)
110
96
class TestPythonInterpreter(LingoBaseTester):
119
105
def test_len(self):
120
106
result = self.python.execute('len([1,2,3,4])')
121
107
self.assertEqual(result, 4)
110
from boots.lib.lingos.lisp import lisp
111
class TestLisp(LingoBaseTester):
113
super(TestLisp, self).setUp()
114
self.lisp = lisp.LispInterpreter(self.console)
117
result = self.lisp.execute('(+ 1 2 3 4)').python_integer()
118
self.assertEqual(result, 10)
120
def test_recursion(self):
121
self.lisp.execute('(setq len (lambda (l) (if l (+ 1 (len (cdr l))) 0)))')
122
result = self.lisp.execute('(len \'(1 2 3 4))').python_integer()
123
self.assertEqual(result, 4)
124
result = self.lisp.execute('(len nil)').python_integer()
125
self.assertEqual(result, 0)
b'\\ No newline at end of file'