Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Experior.Activity/test_sbexecutionengine.py
blob: 29582c0e664b9af4e36271e78a04e040373eb31d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python
# encoding: utf-8
"""
test_sbexecutionengine.py

This file is part of sugarbot.

sugarbot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

sugarbot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with sugarbot.  If not, see <http://www.gnu.org/licenses/>.
"""
from sbexecutionengine import *

logging.raiseExceptions = 0

class failException(Exception): pass
class successException(Exception): pass

class test_sbExecutionEngine:
		
	class fakeXmlRpc:
		def __init__(self):
			self.assertionValue = 1
			self.restart 	= False
			self.kill 		= False
			self.status		= False
			
		def success(self, clientID=None):
			# raise successException
			# We can't raise exceptions on success, because of the way
			# sbExecutionEngine works.  Any exceptions call fail()
			self.status = True
			
		def fail(self, reason=None, clientID=None):
			raise failException	
			
		def getRestartFlag(self):
			return self.restart
			
		def getKillFlag(self):
			return self.kill
			
		def getScript(self, dontCare):
			return \
"""
def sugarbot_main(param):
	assert param
"""	

	def __init__(self):
		self.is_setup = False
		
	def setUp(self):
		assert not self.is_setup
							
		self.xml 	= self.fakeXmlRpc()
		self.ee 	= sbExecutionEngine(None,self.xml)
				
		self.is_setup 	= True
		
	def tearDown(self):
		assert self.is_setup
		
		self.is_setup 	= False
			
	def test_setComplete(self):
		assert not self.ee.isComplete()
		self.ee.executionComplete = True
		assert self.ee.isComplete()
		
	def test_killSugarbot(self):
		try:
			self.ee.killSugarbot()
			assert 0
		except SystemExit:
			pass
			
	def test_executePy_Fail(self):
		try:
			self.ee.widgets.__nonzero__ = lambda: False
			self.ee.executePy()
			assert 0
		except failException:
			pass
			
	def test_executePy_Success(self):	
		# try:
		self.ee.widgets.__nonzero__ = lambda: True
		self.ee.executePy()

		assert self.xml.status == True

	def test_executePy_UnexpectedException(self):
		try:
			def raiseException():	raise ValueError
			
			self.ee.widgets.__nonzero__ = raiseException
			self.ee.executePy()
			assert 0
		except:
			pass