1+ """ Testing the API and a bit more.
2+ It will submit a number of test jobs locally (via runLocal), using the python unittest to assess the results.
3+ Can be automatized.
4+ """
5+
16from DIRAC .Core .Base .Script import parseCommandLine
27parseCommandLine ()
38
1520cwd = os .path .realpath ( '.' )
1621
1722class UserJobTestCase ( unittest .TestCase ):
18- ''' Base class for the UserJob test cases
19- '''
23+ """ Base class for the UserJob test cases
24+ """
2025 def setUp ( self ):
2126 cleanTestDir ()
2227
@@ -25,17 +30,56 @@ def setUp( self ):
2530
2631
2732class HelloWorldSuccess ( UserJobTestCase ):
33+ """ Simplest ever. helloWorld.py just calls 'echo'
34+ """
35+ def test_execute ( self ):
36+
37+ job = Job ()
38+
39+ job .setName ( "helloWorld-test" )
40+ job .setExecutable ( "helloWorld.py" )
41+ res = job .runLocal ( self .dirac )
42+ self .assertTrue ( res ['OK' ] )
43+
44+ class HelloWorldPlusSuccess ( UserJobTestCase ):
45+ """ Adding quite a lot of calls from the API, for pure test purpose
46+ """
47+
2848 def test_execute ( self ):
2949
3050 job = Job ()
3151
3252 job .setName ( "helloWorld-test" )
33- job .setExecutable ( "exe-script.py" )
53+ job .setExecutable ( "helloWorld.py" , arguments = "This is an argument" , logFile = "aLogFileForTest.txt" )
54+ job .setBannedSites ( ['LCG.SiteA.com' , 'DIRAC.SiteB.org' ] )
55+ job .setOwner ( 'ownerName' )
56+ job .setOwnerGroup ( 'ownerGroup' )
57+ job .setName ( 'jobName' )
58+ job .setJobGroup ( 'jobGroup' )
59+ job .setType ( 'jobType' )
60+ job .setDestination ( 'DIRAC.someSite.ch' )
61+ job .setCPUTime ( 12345 )
62+ job .setLogLevel ( 'DEBUG' )
63+
3464 res = job .runLocal ( self .dirac )
3565 self .assertTrue ( res ['OK' ] )
3666
67+
68+ # class CatSuccess( UserJobTestCase ):
69+ # def test_execute( self ):
70+ #
71+ # job = Job()
72+ #
73+ # job.setName( "cat-test" )
74+ # job.setExecutable( "cat.py" )
75+ # job.set
76+ # res = job.runLocal( self.dirac )
77+ # self.assertTrue( res['OK'] )
78+
79+
3780if __name__ == '__main__' :
3881 suite = unittest .defaultTestLoader .loadTestsFromTestCase ( UserJobTestCase )
3982 suite .addTest ( unittest .defaultTestLoader .loadTestsFromTestCase ( HelloWorldSuccess ) )
83+ suite .addTest ( unittest .defaultTestLoader .loadTestsFromTestCase ( HelloWorldPlusSuccess ) )
4084 testResult = unittest .TextTestRunner ( verbosity = 2 ).run ( suite )
4185
0 commit comments