-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |