Skip to content

Commit

Permalink
Add docstring to functions in hawk_test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dawei-Pang committed Aug 26, 2024
1 parent a8881f4 commit 08a656a
Show file tree
Hide file tree
Showing 4 changed files with 384 additions and 9 deletions.
35 changes: 35 additions & 0 deletions e2e_test/hawk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@


def hostname(string):
'''
Check if the input string as hostname is reachable
Args:
string (str): input destination
Return:
string (str) or None
Raises:
ArgumentTypeError: via socket.gaierror: [Errno -2] Name or service not known
'''
try:
socket.getaddrinfo(string, 1)
return string
Expand All @@ -24,6 +33,15 @@ def hostname(string):


def cidr_address(string):
'''
Check if the input string is IP address format
Args:
string (str): input destination
Return:
string (str) or None
Raises:
ArgumentTypeError: via ValueError if address does not represent a valid IPv4 or IPv6 address
'''
try:
ipaddress.ip_network(string, False)
return string
Expand All @@ -32,12 +50,26 @@ def cidr_address(string):


def port(string):
'''
Check if the input string is digit and valid port number
Args:
string (str): input port number
Return:
string (str)
Raises:
ArgumentTypeError: via ValueError
'''
if string.isdigit() and 1 <= int(string) <= 65535:
return string
raise argparse.ArgumentTypeError(f"Invalid port number: {string}") from ValueError


def parse_args():
'''
Set arguments for ArgumentParser
Return:
argparse.Namespace object
'''
parser = argparse.ArgumentParser(description='HAWK GUI interface Selenium test')
parser.add_argument('-b', '--browser', default='firefox', choices=['firefox', 'chrome', 'chromium'],
help='Browser to use in the test')
Expand All @@ -60,6 +92,9 @@ def parse_args():


def main():
'''
Main test functions
'''
args = parse_args()

if args.xvfb:
Expand Down
Loading

0 comments on commit 08a656a

Please sign in to comment.