Skip to content

Commit

Permalink
additional changes done
Browse files Browse the repository at this point in the history
  • Loading branch information
Palani-SN committed Jun 2, 2024
1 parent 56d2ed0 commit 7776dcb
Show file tree
Hide file tree
Showing 34 changed files with 1,023 additions and 149 deletions.
254 changes: 129 additions & 125 deletions REPORTS/TestCaseResults.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
platform win32 -- Python 3.7.16, pytest-6.2.5, py-1.11.0, pluggy-1.2.0
rootdir: D:\GitRepos\py4cli
plugins: reporter-0.5.2, reporter-html1-0.8.2
collected 95 items
collected 125 items

test_min_call.py ...................................... [ 40%]
test_min_os.py ...................................... [ 80%]
test_min_warn.py ......... [ 89%]
test_mod_call.py ..... [ 94%]
test_mod_warn.py ..... [100%]
test_min_call.py ...................................... [ 30%]
test_min_os.py ...................................... [ 60%]
test_min_warn.py ........... [ 69%]
test_mod_call.py ..... [ 73%]
test_mod_os.py .......................... [ 94%]
test_mod_warn.py ....... [100%]

------ generated report: D:\GitRepos\py4cli\REPORTS\TestCaseResults.html ------
============================= 95 passed in 12.62s =============================
============================ 125 passed in 21.07s =============================
15 changes: 15 additions & 0 deletions REPORTS/run_2024-06-02_12-17-55.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
============================= test session starts ==============================
platform linux -- Python 3.7.16, pytest-6.2.5, py-1.11.0, pluggy-1.2.0
rootdir: /mnt/d/GitRepos/py4cli
plugins: reporter-0.5.2, reporter-html1-0.8.2
collected 125 items

test_min_call.py ...................................... [ 30%]
test_min_os.py ...................................... [ 60%]
test_min_warn.py ........... [ 69%]
test_mod_call.py ..... [ 73%]
test_mod_os.py .......................... [ 94%]
test_mod_warn.py ....... [100%]

---- generated report: /mnt/d/GitRepos/py4cli/REPORTS/TestCaseResults.html -----
============================= 125 passed in 30.33s =============================
47 changes: 33 additions & 14 deletions SRCS/py4cli/minimal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, argv=sys.argv):
self.returned = self.__func(def_func_name, args, kwargs)
if func_schema['ret_type'] != inspect._empty and type(self.returned) != func_schema['ret_type']:
print(
f"WARNING : '{def_func_name}' returns '{type(self.returned).__name__}', but defined to return '{func_schema['ret_type'].__name__}'")
f"WARNING : '{def_func_name}' returns '{type(self.returned)}', but defined to return '{func_schema['ret_type']}'")
else:
raise Exception(f"func name : '{def_func_name}' is not defined")

Expand All @@ -37,36 +37,55 @@ def __func(self, func, args, kwargs):
returned = getattr(self, func)(*args, **kwargs)
return returned

def __type(self, dtype, value):
def __type(self, var_name, dtype, value):

if dtype in [str, int, float, list, dict, bool, inspect._empty]:
casted, casted_value = self.__validate_and_typecast(dtype, value)
if casted:
type_casted_value = casted_value
else:
raise ValueError(f"Expected '{dtype}' value for '{var_name}' in kwargs of method 'parse_args', got '{value}' instead")
else:
raise Exception(f"Unsupported argument data type : '{dtype}', try using basic types (int, float, str, list, dict, bool) instead")

return type_casted_value

def __validate_and_typecast(self, dtype, value):

if dtype == str:
return value
return True, value

if dtype in [int, float]:
type_casted_value = dtype(value)
try:
type_casted_value = dtype(value)
return True, type_casted_value
except ValueError as err:
return False, value
elif dtype in [list, dict, bool]:
type_casted_value = ast.literal_eval(value)
try:
type_casted_value = ast.literal_eval(value)
return (dtype == type(type_casted_value)), type_casted_value
except (SyntaxError, ValueError, Exception) as err:
return False, value
elif dtype in [inspect._empty]:
type_casted_value = value
else:
raise Exception(
f"Unsupported argument data type : {dtype}, try using basic types (int, float, str, list, dict, bool) instead")

return type_casted_value
return True, type_casted_value

def __solve_schema(self, func, inps):

mod_args = []
for i in range(len(inps['args'])):
type = func['kwargs'][func['args'][i]]['type']
var_name = func['args'][i]
type = func['kwargs'][var_name]['type']
val = inps['args'][i]
mod_args.append(self.__type(type, val))
mod_args.append(self.__type(var_name, type, val))

mod_kwargs = {}
for key, val in inps['kwargs'].items():
var_name = key
type = func['kwargs'][key]['type']
val = val['value']
mod_kwargs[key] = self.__type(type, val)
mod_kwargs[key] = self.__type(var_name, type, val)

return mod_args, mod_kwargs

Expand Down Expand Up @@ -173,4 +192,4 @@ def __mult_repl(self, str_inp, replacements):
for key, value in replacements.items():
inp = inp.replace(key, value)

return inp
return inp
2 changes: 1 addition & 1 deletion SRCS/py4cli/moderate.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __validate_and_typecast(self, dtype, value):
try:
type_casted_value = ast.literal_eval(value)
return (dtype == type(type_casted_value)), type_casted_value
except (SyntaxError, ValueError) as err:
except (SyntaxError, ValueError, Exception) as err:
return False, value
elif dtype in [inspect._empty]:
type_casted_value = value
Expand Down
5 changes: 5 additions & 0 deletions TESTS/ref_files/mod_bool.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
['moderate_scripts/basic_usage.py', '~single_bool']

{
"single_bool": false
} <class 'dict'>
5 changes: 5 additions & 0 deletions TESTS/ref_files/mod_bool_args.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
['moderate_scripts/basic_usage.py', '~single_bool', 'True']

{
"single_bool": true
} <class 'dict'>
5 changes: 5 additions & 0 deletions TESTS/ref_files/mod_bool_kwargs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
['moderate_scripts/basic_usage.py', '~single_bool', '-inp_bool=True']

{
"single_bool": true
} <class 'dict'>
7 changes: 7 additions & 0 deletions TESTS/ref_files/mod_dict.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
['moderate_scripts/basic_usage.py', '~single_dict']

{
"single_dict": {
"null": null
}
} <class 'dict'>
7 changes: 7 additions & 0 deletions TESTS/ref_files/mod_dict_args.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
['moderate_scripts/basic_usage.py', '~single_dict', "{'hello':'world'}"]

{
"single_dict": {
"hello": "world"
}
} <class 'dict'>
7 changes: 7 additions & 0 deletions TESTS/ref_files/mod_dict_kwargs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
['moderate_scripts/basic_usage.py', '~single_dict', "-inp_dict={'hello':'world'}"]

{
"single_dict": {
"hello": "world"
}
} <class 'dict'>
5 changes: 5 additions & 0 deletions TESTS/ref_files/mod_float.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
['moderate_scripts/basic_usage.py', '~single_float']

{
"single_float": 0.0
} <class 'dict'>
5 changes: 5 additions & 0 deletions TESTS/ref_files/mod_float_args.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
['moderate_scripts/basic_usage.py', '~single_float', '10.0']

{
"single_float": 10.0
} <class 'dict'>
5 changes: 5 additions & 0 deletions TESTS/ref_files/mod_float_kwargs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
['moderate_scripts/basic_usage.py', '~single_float', '-inp_float=10.0']

{
"single_float": 10.0
} <class 'dict'>
Loading

0 comments on commit 7776dcb

Please sign in to comment.