Esempio n. 1
0
    def processTestDef(self, file, testCase, results, directory):
        """
        
    """
        output_dir = os.path.abspath(os.path.join(directory, "output"))
        rendering_dir = os.path.join(directory, output_dir, 'renderings')
        text_dir = os.path.join(directory, output_dir, 'text')
        for dir in [output_dir, rendering_dir, text_dir]:
            if not os.path.exists(dir):
                os.mkdir(dir)

        script = """
    <MetadataString DEF='TestCaseName' value='%s'/>
    <MetadataString DEF='TestCaseScriptFolder' value='%s'/>
    <MetadataString DEF='TestCaseScriptFilename' value='%s'/>
    <MetadataString DEF='TestCaseDefFolder' value='%s'/>
    <MetadataString DEF='TestBaseFolder' value='%s'/>
    <MetadataFloat DEF='StartTime' value='%f'/>
    <PythonScript DEF='TestScript' url='%s'></PythonScript>""" % (
            testCase.name,
            os.path.split(
                os.path.abspath(os.path.join(
                    directory, testCase.script)))[0].replace('\\', '/'),
            os.path.splitext(os.path.split(testCase.script)[1])[0],
            os.path.abspath(directory), args.RunTestsDir, testCase.starttime,
            os.path.join(args.RunTestsDir, 'UnitTestBoilerplate.py'))
        v = Variation(testCase.name, script)
        if not args.only_validate:
            # Create a temporary x3d file containing our injected script
            success, variation_path = self._createVariationFile(
                v, os.path.join(directory, testCase.x3d))
            # Run that H3DViewer with that x3d file
            result = self.runTestCase(file, testCase, variation_path,
                                      os.path.join(directory, testCase.x3d),
                                      v.name, v)
            print result.std_err
            print result.std_out
            #      print os.path.abspath(output_dir + '\\validation.txt')
            result.parseValidationFile(
                os.path.abspath(output_dir + '\\validation.txt'),
                os.path.abspath(os.path.join(directory, testCase.baseline)),
                os.path.abspath(output_dir + '\\text\\'))
        else:
            result = TestResults('')
            result.filename = file
            result.name = testCase.name
            result.url = os.path.join(directory, testCase.x3d)

        if not args.only_validate:
            os.remove(variation_path)

        return result
Esempio n. 2
0
  def runTestCase (self, filename, test_case, url, orig_url= None, var_name= "", variation = None):

    if orig_url is None:
      orig_url= url
    
    test_results= TestResults( )
    test_results.filename= filename
    test_results.name= test_case.name
    test_results.url= orig_url

    self.startup_time = test_case.starttime
    self.shutdown_time = test_case.runtime + 5
    cwd= os.path.abspath(os.path.split ( orig_url )[0])
    filename= os.path.abspath ( url )
    
    if os.path.isfile( self.early_shutdown_file ):
      os.remove( self.early_shutdown_file )
    process= self.launchTest ( url, cwd )
    for i in range( 0, int(test_case.runtime) ):
      time.sleep(1)
      if os.path.isfile( self.early_shutdown_file ) or not process.isRunning():
        break
    if not process.isRunning ():
      test_results.std_out= process.getStdOut()
      test_results.std_err= process.getStdErr()
      test_results.warnings, test_results.errors= self._countWarnings ( test_results )
      test_results.terminates_ok = os.path.isfile(self.early_shutdown_file)
      return test_results
   
    self.shutdown_timeout = 10
    time_slept = 0.0
    while time_slept < self.shutdown_timeout and process.isRunning():
      time.sleep(0.5)
      time_slept += 0.5
    
    if not process.isRunning ():
      test_results.terminates_ok= True
      test_results.std_out= process.getStdOut()
      test_results.std_err= process.getStdErr()
      test_results.warnings, test_results.errors= self._countWarnings ( test_results )
      return test_results
    else:
      process.kill ()
      time_slept = 0
      while time_slept < self.shutdown_time and process.isRunning():
        time.sleep(0.5)
        time_slept += 0.5
      test_results.std_out= process.getStdOut()
      test_results.std_err= process.getStdErr()
      test_results.warnings, test_results.errors= self._countWarnings ( test_results )
      return test_results
Esempio n. 3
0
  def processTestDef(self, file, testCase, results, directory):
    """
        
    """
    output_dir = os.path.abspath(os.path.join(directory, "output"))
    rendering_dir = os.path.join(directory, output_dir, 'renderings')
    text_dir = os.path.join(directory, output_dir, 'text')
    for dir in [output_dir, rendering_dir, text_dir]:
      if not os.path.exists(dir):
        os.mkdir(dir)

                
    script = """
    <MetadataString DEF='TestCaseName' value='%s'/>
    <MetadataString DEF='TestCaseScriptFolder' value='%s'/>
    <MetadataString DEF='TestCaseScriptFilename' value='%s'/>
    <MetadataString DEF='TestCaseDefFolder' value='%s'/>
    <MetadataString DEF='TestBaseFolder' value='%s'/>
    <MetadataFloat DEF='StartTime' value='%f'/>
    <PythonScript DEF='TestScript' url='%s'></PythonScript>""" % (testCase.name,
                                                                  os.path.split(os.path.abspath(os.path.join(directory, testCase.script)))[0].replace('\\', '/'),
                                                                  os.path.splitext(os.path.split(testCase.script)[1])[0],
                                                                  os.path.abspath(directory),
                                                                  args.RunTestsDir,
                                                                  testCase.starttime,
                                                                  os.path.join(args.RunTestsDir, 'UnitTestBoilerplate.py'))
    v = Variation (testCase.name, script)
    if not args.only_validate:
      # Create a temporary x3d file containing our injected script
      success, variation_path= self._createVariationFile ( v, os.path.join(directory, testCase.x3d))
      # Run that H3DViewer with that x3d file
      result = self.runTestCase (file, testCase, variation_path, os.path.join(directory, testCase.x3d), v.name, v)
      print result.std_err
      print result.std_out
#      print os.path.abspath(output_dir + '\\validation.txt')
      result.parseValidationFile(os.path.abspath(output_dir + '\\validation.txt'), os.path.abspath(os.path.join(directory, testCase.baseline)), os.path.abspath(output_dir + '\\text\\'))
    else:
      result = TestResults('')
      result.filename= file
      result.name= testCase.name
      result.url= os.path.join(directory, testCase.x3d)

    if not args.only_validate:
      os.remove ( variation_path )

    return result
Esempio n. 4
0
    def runTestCase(self,
                    filename,
                    test_case,
                    url,
                    orig_url=None,
                    var_name="",
                    variation=None):

        if orig_url is None:
            orig_url = url

        test_results = TestResults()
        test_results.filename = filename
        test_results.name = test_case.name
        test_results.url = orig_url

        self.startup_time = test_case.starttime
        self.shutdown_time = test_case.runtime + 5
        cwd = os.path.abspath(os.path.split(orig_url)[0])
        filename = os.path.abspath(url)

        if os.path.isfile(self.early_shutdown_file):
            os.remove(self.early_shutdown_file)
        process = self.launchTest(url, cwd)
        for i in range(0, int(test_case.runtime)):
            time.sleep(1)
            if os.path.isfile(
                    self.early_shutdown_file) or not process.isRunning():
                break
        if not process.isRunning():
            test_results.std_out = process.getStdOut()
            test_results.std_err = process.getStdErr()
            test_results.warnings, test_results.errors = self._countWarnings(
                test_results)
            test_results.terminates_ok = os.path.isfile(
                self.early_shutdown_file)
            return test_results

        self.shutdown_timeout = 10
        time_slept = 0.0
        while time_slept < self.shutdown_timeout and process.isRunning():
            time.sleep(0.5)
            time_slept += 0.5

        if not process.isRunning():
            test_results.terminates_ok = True
            test_results.std_out = process.getStdOut()
            test_results.std_err = process.getStdErr()
            test_results.warnings, test_results.errors = self._countWarnings(
                test_results)
            return test_results
        else:
            process.kill()
            time_slept = 0
            while time_slept < self.shutdown_time and process.isRunning():
                time.sleep(0.5)
                time_slept += 0.5
            test_results.std_out = process.getStdOut()
            test_results.std_err = process.getStdErr()
            test_results.warnings, test_results.errors = self._countWarnings(
                test_results)
            return test_results