Python Forum
Validating the functionality of the application
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validating the functionality of the application
#1
I am trying to learn test script in python. I would like to write a test script to validate the functionality of an executable. The script should test the behaviour of the application, how the application handles error events and the specifications of the application are as follows,

The application takes input data from a file that is specified as an argument and is called by executable.exe numbers.txt
The numbers.txt file contains comma separated list of float number in each line
The application computes and prints the average and standard deviation values for the numbers on each line in the input file(numbers.txt)

I came up till here

from validator_collection import validators, errors

# This funcion can be used to execute the application
# Inputs: executable, the executable file of the application
#         data, the input data file for the application
# Outputs: return code, standard output, and error output from the execution
def execute_application(executable, data):
    proc = subprocess.run(
            [executable, data],
            encoding="utf-8",
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE)
    return proc.returncode, proc.stdout, proc.stderr

# Call application
returncode, output, error = execute_application("executable.exe", "numbers.txt")

# The output of the program is 
#Output: data.txt
#Line 1 average 11.2333 standard deviation 9.34041
#Line 2 average 7.21667 standard deviation 7.29286

# started writing the test case
val = output.split(" ")
avg1, std1 = float(val[3]), float(val[6].strip('\nLine'))
avg2, std2 = float(val[9]), float(val[12].strip('\nLine'))
try:
    ret_avg1 = validators.float(avg1)
    ret_avg2 = validators.float(avg2)
    ret_std1 = validators.float(std1)
    ret_std2 = validators.float(std2)
except ValueError:
    print('Error')

print(ret_avg1, ret_avg2, ret_std1, ret_std2)
print("Output:", output)
print("Errors:", error)
Any pointers will be helpful
Reply
#2
Can you say more about your needs please? Why aren't you writing tests in the same language as whatever this application was written in with whatever testing framework is available (e.g. if you were wanting to write tests for a Python app, you could use unittest)? That's the standard way to do things.

There could be a case for testing from completely outside the application, but unless it's really small, you don't want to all your testing at the highest level (those tests are complicated to set up, will be slower than testing at lower levels, for example). Read about the testing pyramid for more on this.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Priority Queue with update functionality PythonNewbee 4 1,950 Dec-29-2022, 12:13 PM
Last Post: Yoriz
  [split] formula for validating monetary values? kakos_k9 1 759 Dec-17-2022, 09:28 PM
Last Post: woooee
  How to send data from a python application to an external application aditya_rajiv 1 2,185 Jul-26-2021, 06:00 AM
Last Post: ndc85430
  Putting code into a function breaks its functionality, though the code is identical! PCesarano 1 2,002 Apr-05-2021, 05:40 PM
Last Post: deanhystad
  Validating user input WJSwan 2 2,134 Jul-06-2020, 07:21 AM
Last Post: menator01
  Validating information from .csv file before executemany mzmingle 7 4,443 Apr-15-2019, 01:40 PM
Last Post: mzmingle
  need help with making a validating function drasil 8 3,758 Mar-28-2019, 10:38 AM
Last Post: perfringo
  I'm having trouble with an OOP version of Pickle functionality CodeWolf 2 2,371 Dec-19-2018, 05:41 PM
Last Post: CodeWolf
  Validating credit card frequency 8 4,204 Nov-05-2018, 07:36 PM
Last Post: frequency
  Validating Input (basic check for int etc) gruntfutuk 1 2,490 Aug-06-2018, 07:43 AM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020