import  unittest  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								import  os  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								import  inspect  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								import  utils . path_tool  
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								import  basic . program  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								import  basic . constants  as  B  
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								import  test . constants  
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								import  test . testtools  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								import  utils . path_const  as  P  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								HOME_PATH  =  test . constants . HOME_PATH  
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								OS_SYSTEM  =  test . constants . OS_SYSTEM  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								# here you can select single testfunction for developping the tests  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								TEST_FUNCTIONS  =  [ " test_key " ,  " test_rejoinPath " ,  " test_rejoinPath " ,  " test_composePath " ,  " test_composePattern " ,  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								                  " test_extractPath " ,   " test_extractPattern " ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								#TEST_FUNCTIONS = [ "test_extractPath"]  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								class  MyTestCase ( unittest . TestCase ) :  
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								    mymsg  =  " -------------------------------------------------------------- " 
							 
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								    def  setTestPaths ( self ,  job ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        # here you can overwrite your workspace-configuration in order to get stable unittests 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        job . conf . confs [ B . SUBJECT_PATH ] [ B . ATTR_PATH_HOME ]  =  " home/unittest " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        job . conf . confs [ B . SUBJECT_PATH ] [ B . ATTR_PATH_TDATA ]  =  " home/unittest/tdata " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        job . conf . confs [ B . SUBJECT_PATH ] [ B . ATTR_PATH_ENV ]  =  " home/unittest/env " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        job . conf . confs [ B . SUBJECT_PATH ] [ B . ATTR_PATH_ARCHIV ]  =  " home/unittest/archiv " 
							 
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								        pass 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								    def  setPathConfig ( self ,  pt ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        # here you can overwrite your workspace-configuration in order to get stable unittests 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        paths  =  pt . getInstance ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        paths . pattern [ P . P_ENVBASE ]  =  " {job.conf.environment} / {job.par.environment} " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								    def  test_key ( self ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        global  mymsg 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        actfunction  =  str ( inspect . currentframe ( ) . f_code . co_name ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        cnttest  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        if  actfunction  not  in  TEST_FUNCTIONS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        job  =  test . testtools . getJob ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        res  =  utils . path_tool . getKeyValue ( " job.par. " + B . PAR_ENV ,  None ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        self . assertEqual ( res ,  test . testtools . DEFAULT_ENV ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        cnttest  + =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        for  par  in  [ B . ATTR_PATH_TDATA ,  B . ATTR_PATH_ARCHIV ,  B . ATTR_PATH_ENV ,  B . ATTR_PATH_PROGRAM ] : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            res  =  utils . path_tool . getKeyValue ( " job.conf. " + par ,  None ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            self . assertIn ( HOME_PATH ,  res ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            cnttest  + =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        MyTestCase . mymsg  + =  " \n -----  " + actfunction + "  :  " + str ( cnttest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								    def  test_rejoinPath ( self ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        global  mymsg 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        actfunction  =  str ( inspect . currentframe ( ) . f_code . co_name ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        cnttest  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        if  actfunction  not  in  TEST_FUNCTIONS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        if  OS_SYSTEM  ==  " linux " : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            res  =  utils . path_tool . rejoinPath ( " home " ,  " ulrich " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            self . assertEqual ( res ,  " /home/ulrich " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            cnttest  + =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            res  =  utils . path_tool . rejoinPath ( " opt " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            self . assertEqual ( res ,  " /opt " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            cnttest  + =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            res  =  utils . path_tool . rejoinPath ( " http://domain.com " ,  " application " ,  " function " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            self . assertEqual ( res ,  " http://domain.com/application/function " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            cnttest  + =  1 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        MyTestCase . mymsg  + =  " \n -----  " + actfunction + "  :  " + str ( cnttest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								    def  test_composePath ( self ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        global  mymsg 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        actfunction  =  str ( inspect . currentframe ( ) . f_code . co_name ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        cnttest  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        if  actfunction  not  in  TEST_FUNCTIONS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        # set the relevant datastrutures 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        job  =  test . testtools . getJob ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        comp  =  test . testtools . getComp ( ) 
							 
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								        pt  =  utils . path_tool . PathConf ( ) 
							 
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								        self . setTestPaths ( job ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        self . setPathConfig ( pt ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        # tests 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        path  =  utils . path_tool . composePath ( P . P_ENVBASE ,  None ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        self . assertIn ( job . conf . confs [ B . SUBJECT_PATH ] [ B . ATTR_PATH_ENV ] ,  path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        self . assertIn ( getattr ( job . par ,  B . PAR_ENV ) ,  path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        cnttest  + =  2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        path  =  utils . path_tool . composePath ( P . P_TCLOG ,  None ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        self . assertIn ( job . conf . confs [ B . SUBJECT_PATH ] [ B . ATTR_PATH_ARCHIV ] ,  path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        self . assertIn ( getattr ( job . par ,  B . PAR_TESTCASE ) ,  path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        cnttest  + =  2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        MyTestCase . mymsg  + =  " \n -----  " + actfunction + "  :  " + str ( cnttest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								    def  test_composePattern ( self ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        global  mymsg 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        actfunction  =  str ( inspect . currentframe ( ) . f_code . co_name ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        cnttest  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        if  actfunction  not  in  TEST_FUNCTIONS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        # set the relevant datastrutures 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        job  =  test . testtools . getJob ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        comp  =  test . testtools . getComp ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        pt  =  utils . path_tool . PathConf ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        self . setTestPaths ( job ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        self . setPathConfig ( pt ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        # tests 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        path  =  utils . path_tool . composePattern ( " { " + P . P_ENVBASE + " } " ,  None ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        self . assertIn ( job . conf . confs [ B . SUBJECT_PATH ] [ B . ATTR_PATH_ENV ] ,  path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        self . assertIn ( getattr ( job . par ,  B . PAR_ENV ) ,  path ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        cnttest  + =  2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        MyTestCase . mymsg  + =  " \n -----  " + actfunction + "  :  " + str ( cnttest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								    def  test_extractPattern ( self ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        global  mymsg 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        actfunction  =  str ( inspect . currentframe ( ) . f_code . co_name ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        cnttest  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        if  actfunction  not  in  TEST_FUNCTIONS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        job  =  test . testtools . getJob ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        pt  =  utils . path_tool . PathConf ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        job  =  test . testtools . getJob ( " ts " ,  test . testtools . DEFAULT_APP ,  test . testtools . DEFAULT_ENV ,  " 2021-08-21_18-ß2-01 " ) 
							 
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								        r  =  utils . path_tool . extractPattern ( " tsbase "  ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        self . assertEqual ( r [ 0 ] [ 1 ] ,  " job.conf.archiv " ) 
							 
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								        self . assertEqual ( r [ 1 ] [ 1 ] ,  P . KEY_TESTSUITE ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        self . assertEqual ( r [ 1 ] [ 2 ] ,  " testlauf " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        cnttest  + =  3 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        MyTestCase . mymsg  + =  " \n -----  " + actfunction + "  :  " + str ( cnttest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								    def  test_extractPath ( self ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        global  mymsg 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        actfunction  =  str ( inspect . currentframe ( ) . f_code . co_name ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        cnttest  =  0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        if  actfunction  not  in  TEST_FUNCTIONS : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								            return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        job  =  test . testtools . getJob ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        pt  =  utils . path_tool . PathConf ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        r  =  utils . path_tool . extractPath ( " tsbase "  ,  os . path . join ( HOME_PATH ,  " test " , " conf " , " lauf " , " testlauf " , " startjob_2021-08-21_10-02-01 " ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        print ( " r  "  +  str ( r ) ) 
							 
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								        #print(vars(job.par)) 
							 
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								        #self.assertEqual(job.par.release, "V0.1") 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        self . assertEqual ( job . par . usecase ,  " startjob " ) 
							 
						 
					
						
							
								
							 
							
								
									
										 
								
							 
							
								 
							
								        self . assertEqual ( job . par . tstime ,  " 2021-08-21_10-02-01 " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        cnttest  + =  2 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        MyTestCase . mymsg  + =  " \n -----  " + actfunction + "  :  " + str ( cnttest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								    def  test_zzz ( self ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								        print ( MyTestCase . mymsg ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								if  __name__  ==  ' __main__ ' :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
								    unittest . main ( )