Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
d33pster committed Apr 10, 2024
1 parent 735eb44 commit 56f1d31
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3

from sys import argv
from optioner import options

shortargs = ['o1', 'o2', 'o3']
longargs = ['option1', 'option2', 'option3']
ignore = ['--option2', '-o2']
compulsory_s = ['o3']
compulsory_l = ['option3']
ifthisthennotthat = [['o1','option1'],['o3', 'option3']]

ctrl = options(shortargs, longargs, argv[1:], compulsory_s, compulsory_l, ignore, ifthisthennotthat)
args, check, error, falseargs = ctrl._argparse()

try:
arr = args[0]
if len(args)>1:
for i in range(1, len(args)):
arr += f":{args[i]}"
else:
pass
except IndexError:
arr = ''

print(arr)
print(check)
print(error)
print(ctrl._what_is_(args[0].split('-')[len(args[0].split('-'))-1]))
19 changes: 19 additions & 0 deletions tests/demo2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python3

from sys import argv
from optioner import options

shortargs = ['o1', 'o2', 'o3']
longargs = ['option1', 'option2', 'option3']
ignore = ['--option2', '-o2']
compulsory_s = ['o3']
compulsory_l = ['option3']
ifthisthennotthat = [['o1','option1'],['o3', 'option3']]

ctrl = options(shortargs, longargs, argv[1:], compulsory_s, compulsory_l, ignore, ifthisthennotthat)
args, check, error, falseargs = ctrl._argparse()

val1, val2 = ctrl._what_is_(args[0].split('-')[len(args[0].split('-'))-1], 2)

print(val1)
print(val2)
41 changes: 41 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3

from os import popen, getcwd
from os.path import join

def test_one():
"""test case 1:
test options class methods against a predefined conditions
"""
output = popen(f"python3 {join(getcwd(), 'tests', 'demo.py')} -o2").readlines()

assert output[0].replace('\n','') == '-o2'
assert output[1].replace('\n','') == 'True'

def test_two():
"""test case 2:
test options class for wrong arg
"""
output = popen(f"python3 {join(getcwd(), 'tests', 'demo.py')} -o hehe").readlines()

assert output[1].replace('\n','') == 'False'

def test_three():
"""test case 3:
test options class for value
"""
output = popen(f"python3 {join(getcwd(), 'tests', 'demo.py')} -o3 hehe").readlines()

assert output[0].replace('\n','') == '-o3'
assert output[1].replace('\n','') == 'True'
assert output[3].replace('\n','') == 'hehe'

def test_four():
"""test case 4:
test options class for multiple values
"""

output = popen(f"python3 {join(getcwd(), 'tests', 'demo2.py')} -o3 hehe huhu").readlines()

assert output[0].replace('\n','') == 'hehe'
assert output[1].replace('\n','') == 'huhu'
13 changes: 13 additions & 0 deletions tests/test_compulsory_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python3

from os import popen, getcwd
from os.path import join

def test_one():
"""test case 5:
test compulsory arg
"""

output = popen(f"python3 {join(getcwd(), 'tests', 'demo.py')} -o1 hehe").readlines()

assert output[1].replace('\n','') == 'False'
13 changes: 13 additions & 0 deletions tests/test_ifthisthennotthat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python3

from os import popen, getcwd
from os.path import join

def test_one():
"""test case 7:
test ifthisthennotthat
"""

output = popen(f"python3 {join(getcwd(), 'tests', 'demo.py')} -o1 hehe -o3 huhu").readlines()

assert output[1].replace('\n','') == 'False'
13 changes: 13 additions & 0 deletions tests/test_ignore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env python3

from os import popen, getcwd
from os.path import join

def test_one():
"""test case 6:
test ignore
"""

output = popen(f"python3 {join(getcwd(), 'tests', 'demo.py')} -o2 hehe").readlines()

assert output[1].replace('\n','') == 'True'

0 comments on commit 56f1d31

Please sign in to comment.