Пример #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
Пример #2
0
    def compute_lexicon_score(self):
        true_pos = 0
        true_neg = 0
        false_pos = 0
        false_neg = 0
        for article in db.articles.find():
            orgs = find_incident_orgs(article['title'])
            try:
                #print(orgs)
                if len(orgs) != 0:
                    count, num_pos, num_neg = self.num_words(
                        nltk.sent_tokenize(article['text']))
                    result = quandl.classification_decision(
                        article['text'], orgs[0], article['time_string'],
                        num_pos, num_neg)
                    if result == 'true-pos':
                        true_pos += 1
                    elif result == 'false-pos':
                        false_pos += 1
                    elif result == 'true-neg':
                        true_neg += 1
                    elif result == 'false-neg':
                        false_neg += 1
            except Exception as e:
                print(e)

        return TestResults.compute_scores(true_pos, true_neg, false_pos,
                                          false_neg)
Пример #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
Пример #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
Пример #5
0
    "--exportResults",
    action="store",
    type="string",
    dest='export',
    default=None,
    help="Exporting test plan results to testRail db using the API.")

(options, args) = parser.parse_args()

#Setting input files directory
inputFilesDirName = options.inputFilesDirName

#Creating a new project to be tested
project = TestCases()
testRuns = TestRuns()
testResults = TestResults()

#Setting main working directory
if options.mainDirectory is not None:
    testRuns.SetMainDirectory(options.mainDirectory)

#Exporting results to testRail
if options.export:
    print "Exporting results to testRail"
    if options.xml is None:
        sys.exit("Error, please specify the path to the testCases xml file.")
    testCases = project.ReadXml(options.xml)  #setting the testCases xml file
    #testRuns.SetTestCases(project)
    from TestDriverDbApi import TestDriverDbApi
    testRuns.testRail = True
    testDriverDbApi = TestDriverDbApi()
Пример #6
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
Пример #7
0
parser.add_option("-k", "--kill", action="store",dest='userDefinedKill', type="string", default=None,
                  help="Setting user-defined instruction for killing the main testing application. By default is none and main application will be killed using the standard terminate() method from the Asyncproc.py Class.")
parser.add_option("-m", "--sleepingTime", action="store",dest='sleepingTime', type="int", default=1,
                  help="Sleeping time (in seconds) which will be used for command type actions tests. By default sleepingTime = 1 second.")
parser.add_option("-e", "--exportResults", action="store", type="string", dest='export', default=None,
                  help="Exporting test plan results to testRail db using the API.")

(options, args) = parser.parse_args()

#Setting input files directory
inputFilesDirName = options.inputFilesDirName

#Creating a new project to be tested
project = TestCases()
testRuns = TestRuns()
testResults = TestResults()

#Setting main working directory
if options.mainDirectory is not None:
    testRuns.SetMainDirectory(options.mainDirectory)

#Exporting results to testRail
if options.export:
    print "Exporting results to testRail"
    if options.xml is None:
        sys.exit("Error, please specify the path to the testCases xml file.")  
    testCases = project.ReadXml(options.xml)  #setting the testCases xml file
    #testRuns.SetTestCases(project)
    from TestDriverDbApi import TestDriverDbApi
    testRuns.testRail = True
    testDriverDbApi = TestDriverDbApi()