blob: aea5b4948a04d97965ec32ead22be88d6a1ec6b5 (
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
111
112
113
114
115
116
117
118
119
120
|
#! /usr/bin/env python
# -*- encoding: utf-8 -*-
#test_sugarbot.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 sys import path
path.append('..')
from sugarbot import *
class rpcFailure(Exception):
pass
class test_sugarbot:
class cloneTest(activity.Activity):
def __init__(self,x):
self.clonedProperly = True
class fakeXmlRpc:
activity = "exampleActivity"
def startScript(self, *args):
return True
def fail(self, reason, *args):
raise rpcFailure
class fakeXmlRpcGood(fakeXmlRpc):
def getActivityName(self, *args):
return self.activity
class fakeXmlRpcBad(fakeXmlRpc):
def getActivityName(self, *args):
return None
def __init__(self):
self.is_setup = False
def setUp(self):
assert not self.is_setup
self.sb = sugarbot(None)
self.is_setup = True
def tearDown(self):
assert self.is_setup
sugarbot.__bases__ = (activity.Activity, )
self.is_setup = False
def test_dynamicImport1(self):
# Attempt to import a valid module
assert gobject.GObject == \
self.sb._sugarbot__dynamicImport("gobject.GObject")
def test_dynamicImport2(self):
# Attempt to import a module with a bad length or None
assert activity.Activity == self.sb._sugarbot__dynamicImport("")
assert activity.Activity == self.sb._sugarbot__dynamicImport(None)
def test_dynamicImport3(self):
# Attempt to import a module that does not exist
try:
assert activity.Activity == \
self.sb._sugarbot__dynamicImport("asdf.1231231.##fw")
assert 0
except ImportError:
pass
def test_cloneActivity1(self):
self.sb._sugarbot__parentClass = None
try:
self.sb._sugarbot__cloneActivity(None)
assert 0
except AttributeError:
pass
def test_cloneActivity2(self):
self.sb._sugarbot__parentClass = self.cloneTest
self.sb._sugarbot__cloneActivity(None)
assert self.cloneTest in sugarbot.__bases__
assert self.sb.clonedProperly
def test_cloneActivity3(self):
assert not self.cloneTest in sugarbot.__bases__
def test_initializeScript1(self):
fake = self.fakeXmlRpcGood()
self.sb._sugarbot__xmlRPC = fake
assert fake.activity == self.sb._sugarbot__initializeScript()
def test_initializeScript2(self):
fake = self.fakeXmlRpcBad()
self.sb._sugarbot__xmlRPC = fake
try:
self.sb._sugarbot__initializeScript()
assert 0
except rpcFailure:
pass
|