-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tests.py
105 lines (77 loc) · 3.77 KB
/
Tests.py
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
import unittest
import time
import random
import exceptions
import traceback
import os
from MySQLSetup import Hydra_rendertask
import Questions
import Answers
import Connections
import Clients
import Servers
from LoggingSetup import logger
__doc__="""Multiple tests are performed to check the performance of our modules."""""
class TestQuestionsLocal( unittest.TestCase, Clients.Client ):
"""This calls on the unit test and the client class and the client module."""
connection = Connections.LocalConnection( )
"""This defines the variable connection"""
def testQA( self ):
question = Questions.Question( )
answer = self.getAnswer( question )
self.assert_( isinstance( answer, Answers.Answer ) )
"""This class defines a test, within the class the variable question is defined as the module and subclass.
Answer is defined as well, the self.assert calls on the isinstance which only returns true if the object
argument is an instance of the classinfo argument or of a subclass."""
def testTime( self ):
time1 = time.localtime( )
question = Questions.TimeQuestion( )
answer = self.getAnswer( question )
time2 = answer.time
self.assertEqual( time1, time2 )
"""This class defines a test, that checks the time. The variables time1 and time 2 are defined
and for this test to be true time1 and time2 need to be equal"""
def testEchoSuccess( self ):
object = random.random( )
question = Questions.EchoQuestion( object )
answer = self.getAnswer( question )
self.assertEqual( question.object, answer.object )
"""In this class echo is defined as a command with multiple parameters. It checks to makes sure
the object in answer recieved is the same as the object in question."""
def testEchoFail( self ):
object = time
question = Questions.EchoQuestion( object )
if isinstance( self.connection, Connections.LocalConnection ):
self.assertEqual( object, self.getAnswer( question ).object )
else:
self.assertRaises( exceptions.TypeError, self.getAnswer, question )
"""This class defines what happens if the test fails. The object defined as time is then set into
put into an isinstance and set equal to the answer."""
def testCommand( self ):
"""Tests a CMDQuestion, a command issued to this or another host."""
question = Questions.CMDQuestion( 'cmd /c echo %computername%' )
answer = self.getAnswer( question )
thisComputerName = os.getenv( 'COMPUTERNAME' )
self.assertEqual( answer.output.strip( ), thisComputerName )
def testRenderCommand( self ):
"""Tests a Render Command, a command that invokes the Maya renderer."""
command = [
r'c:\program files\autodesk\maya2011\bin\render.exe',
'-mr:v', '5',
r'\\flex2\ProjectHydra\TestMayaFiles\Chair2.ma'
]
render_task = Hydra_rendertask()
render_task.status = 'R'
render_task.command = repr( command )
render_task.insert()
logger.debug(render_task)
render_question = Questions.RenderQuestion( render_task.id )
render_answer = self.getAnswer( render_question )
logger.debug( render_answer )
class TestQuestionsSocket( TestQuestionsLocal ):
"""Class to represent a test socket connection to send Questions to."""
connection = Connections.TCPConnection ()
if __name__ == '__main__':
socketServer = Servers.TCPServer( )
unittest.main( exit=False )
socketServer.shutdown( )