Ejemplo n.º 1
0
def testNumbersAgainstExpected(datFile, expectedFile):
    ii = 0
    needLabels = 1
    jj = 0
    input = list()
    keys = list()
    expected = list()

    try:
        INPUT = open(datFile, "r")

        try:
            sys.stdout.write(
                "\n--- Testing the output against the expected file " +
                expectedFile + " ---\n\n")

            # get results from inputfile
            line = INPUT.readline()

            while line:
                RE = re.compile('^\-\-\-\-\-\-\-\-\-')
                RESULT = RE.match(line)

                if RESULT != None:
                    break

                RE = re.compile('^#Res\s+(.*)')
                RESULT = RE.match(line)

                if (RESULT != None) and (needLabels == 1):
                    keys = line.split('/\s+/')
                    needLabels = 0

                RE = re.compile('^\s*\D')
                RESULT = RE.match(line)

                if RESULT != None:
                    continue

                RE = re.compile('^\s*\d')
                RESULT = RE.match(line)

                if RESULT != None:
                    input[ii] = [line.split('/\s/')]
                    ii = ii + 1
        finally:
            INPUT.close()
    except IOerror:
        pass

    # get results from expected file
    ii = 0

    try:
        EXPECTED = open(expectedFile, "r")

        try:
            line = EXPECTED.readline()

            while line:
                RE = re.compile('^\-\-\-\-\-\-\-\-\-')
                RESULT = RE.match(line)

                # exit input if ------ is detected
                if RESULT != None:
                    break

                RE = re.compile('^\s*\D')
                RESULT = RE.match(line)

                # disregard lines starting with non-Digits
                if RESULT != None:
                    continue

                RE = re.comile('^\s*\d')
                RESULT = RE.match(line)

                if RESULT != None:
                    expected[ii] = [line.split('/\sa/')]
                    ii = ii + 1

        finally:
            EXPECTED.close()
    except IOError:
        pass

    for index, item in enumerate(input):
        if item != expected[index]:
            sys.stdout.write(
                "Error: The expected file \n\"" + expectedFile +
                "\nhas a different number of results than the test file \n\"" +
                datFile +
                "\nso the results testing can't be done.\nRemove argument '-againstExpected' to not check the resulting errors agains the expected file.\n"
            )
            sys.exit(1)

    error = 0.0
    r_error = 0.0
    r_tol = 0.05

    sys.stdout.write("relative tolerance is set to " + r_tol + "%\n")

    for ii in range(0, len(input)):
        for jj in range(1, len(keys)):
            error = abs(input[ii][jj] - expected[ii][jj])
            r_error = 100 * (error / expected[ii][jj])

            if r_error > r_tol:
                sys.stdout.write("Results of " + keys[jj - 1] +
                                 " differs by " + r_error + "\n")

            # This is to verbose be could be useful to understand error
            else:
                sys.stdout.write("Results of " + keys[jj - 1] + " are " +
                                 r_error)

    sys.stdout.write("All values within tolerance\n")
    sys.stdout.write(
        "\n-- Finished testing the output against the expected file ---\n")
Ejemplo n.º 2
0
def testNumbersAgainstExpected( datFile, expectedFile ):
	ii = 0
	needLabels = 1
	jj = 0
	input = list()
	keys = list()
	expected = list()

	try:	
		INPUT = open( datFile, "r" )
	
		try:
			sys.stdout.write( "\n--- Testing the output against the expected file " + expectedFile + " ---\n\n" )

			# get results from inputfile
			line = INPUT.readline()

			while line:
				RE = re.compile( '^\-\-\-\-\-\-\-\-\-' )
				RESULT = RE.match( line )

				if RESULT != None:
					break
	
				RE = re.compile( '^#Res\s+(.*)' ) 
				RESULT = RE.match( line )

				if (RESULT != None) and (needLabels == 1):
					keys = line.split( '/\s+/' )	
					needLabels = 0	

				RE = re.compile( '^\s*\D' )
				RESULT = RE.match( line )

				if RESULT != None:
					continue

				RE = re.compile( '^\s*\d' )
				RESULT = RE.match( line )

				if RESULT != None:
					input[ii] = [ line.split( '/\s/' ) ];
					ii = ii + 1
		finally:
			INPUT.close()
	except IOerror:
		pass

	# get results from expected file
	ii = 0

	try:
		EXPECTED = open( expectedFile, "r" )
	
		try:
			line = EXPECTED.readline()

			while line:
				RE = re.compile( '^\-\-\-\-\-\-\-\-\-' )
				RESULT = RE.match( line )

				# exit input if ------ is detected
				if RESULT != None:
					break
		
				RE = re.compile( '^\s*\D' )
				RESULT = RE.match( line )

				# disregard lines starting with non-Digits	
				if RESULT != None:
					continue

				RE = re.comile( '^\s*\d' )
				RESULT = RE.match( line )

				if RESULT != None:
					expected[ii] = [ line.split( '/\sa/' ) ]
					ii = ii + 1

		finally:
			EXPECTED.close()
	except IOError:
		pass
		
	for index, item in enumerate( input ):
		if item != expected[ index ]:
			sys.stdout.write( "Error: The expected file \n\"" + expectedFile + "\nhas a different number of results than the test file \n\"" + datFile + "\nso the results testing can't be done.\nRemove argument '-againstExpected' to not check the resulting errors agains the expected file.\n" )
			sys.exit(1)

	error = 0.0
	r_error = 0.0
	r_tol = 0.05

	sys.stdout.write( "relative tolerance is set to " + r_tol + "%\n" )

	for ii in range( 0, len(input) ):
		for jj in range( 1, len(keys) ):
			error = abs( input[ii][jj] - expected[ii][jj] )
			r_error = 100 * ( error / expected[ii][jj] )

			if r_error > r_tol:
				sys.stdout.write( "Results of " + keys[jj-1] + " differs by " + r_error + "\n" )

			# This is to verbose be could be useful to understand error
			else:
				sys.stdout.write( "Results of " + keys[jj-1] + " are " + r_error )
			
	sys.stdout.write( "All values within tolerance\n" )
	sys.stdout.write( "\n-- Finished testing the output against the expected file ---\n" )
Ejemplo n.º 3
0
import re

re_digits = re.comile(r'(\d+)')
def embedded_numbers(s):
    pieces = re_digits.split(s)
    pieces[1::2]=map(int,pieces[1::2])
    return pieces
def sort_strings_with_embedded_numbers(alist):
    aux=[(embedded_numbers(s),s) for s in alist]
    aux.sort()
    return [s for __, s in aux]
'''return sorted(alist,key=embedded_numbers)'''


print ''.join(sort_strings_with_embedded_numbers(files))

Ejemplo n.º 4
0
# encoding: utf-8

import re
import time

import requests
import urllib3
from httprunner import logger
from httprunner.exception import ParamsError
from requests import Request, Response
from requests.exceptions import (InvalidSchema, InvalidURL, MissingSchema,
                                 RequestException)

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

absolute_http_url_regexp = re.comile(r"^https?://", re.I)


class ApiResPonse(Response):
    def raise_for_status(self):
        if hasattr(self):
            raise self.error
        Response.raise_for_status(self)


class HttpSession(requests.Session):
    """
    Class for performing HTTP requests and holding (session-) cookies between requests (in order
    to be able to log in and out of websites). Each request is logged so that HttpRunner can
    display statistics.
Ejemplo n.º 5
0
 def __init__(self):
     for key, value in self.__matches.iteritems():
         self.__recomp[key] = re.comile(value)