Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/my_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def run_my_tests(self, resultfile):
json.dump(self.RESULTS, f)
return resultfile

def parse_results(self, resultfile):
def parse_results(self, resultfile, config_options={}):
with open(resultfile, 'r') as f:
results = json.load(f)
return {
Expand Down
12 changes: 10 additions & 2 deletions src/oxygen/base_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

from .robot_interface import RobotInterface


class BaseHandler(object):
DEFAULT_CLI = {tuple(['resultfile']): {}}
DEFAULT_CLI = {
tuple(['resultfile']): {},
('-c', '--config'): {
'action': 'append',
'nargs': 2,
'metavar': ('name', 'value')
}
}

def __init__(self, config):
'''
Expand Down Expand Up @@ -33,7 +41,7 @@ def cli(self):
'''
return self.DEFAULT_CLI

def parse_results(self, kw_args):
def parse_results(self, resultfile, config_options={}):
raise NotImplementedError('Actual handler implementation should override '
'this with proper implementation!')

Expand Down
5 changes: 4 additions & 1 deletion src/oxygen/gatling.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ def run_gatling(self, result_file, command, check_return_code=False, **env):
logger.info('Result file: {}'.format(result_file))
return result_file

def parse_results(self, result_file):
def parse_results(self, result_file, config_options={}):
# works from python 3.5 onwards
self._config = {**self._config, **config_options}

return self._transform_tests(validate_path(result_file).resolve())

def _transform_tests(self, result_file):
Expand Down
5 changes: 4 additions & 1 deletion src/oxygen/junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def run_junit(self, result_file, command, check_return_code=False, **env):
logger.info('Result file: {}'.format(result_file))
return result_file

def parse_results(self, result_file):
def parse_results(self, result_file, config_options={}):
# works from python 3.5 onwards
self._config = {**self._config, **config_options}

result_file = self._validate_path(result_file)
try:
xml = JUnitXml.fromfile(result_file)
Expand Down
5 changes: 4 additions & 1 deletion src/oxygen/oxygen.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json

from argparse import ArgumentParser
from datetime import datetime, timedelta
Expand Down Expand Up @@ -231,7 +232,9 @@ def run(self):
if not vars(args):
parser.error('No arguments given')
output_filename = self.get_output_filename(args.resultfile)
parsed_results = args.func(args.resultfile)
config_options = {
name: json.loads(value) for (name, value) in args.config or []}
parsed_results = args.func(args.resultfile, config_options)
robot_suite = RobotInterface().running.build_suite(parsed_results)
robot_suite.run(output=output_filename,
log=None,
Expand Down
5 changes: 4 additions & 1 deletion src/oxygen/zap.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def run_zap(self, result_file, command, check_return_code=False, **env):
return result_file


def parse_results(self, result_file):
def parse_results(self, result_file, config_options={}):
# works from python 3.5 onwards
self._config = {**self._config, **config_options}

zap_dict = self._read_results(validate_path(result_file).resolve())
return self._parse_zap_dict(zap_dict)

Expand Down
3 changes: 2 additions & 1 deletion tests/utest/oxygen/test_oxygen_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def setUp(self):
@patch('oxygen.oxygen.OxygenCLI.parse_args')
def test_run(self, mock_parse_args, mock_robot_iface):
mock_parse_args.return_value = Mock(resultfile='path/to/file.xml',
func=lambda _: {'some': 'results'})
config=[],
func=lambda *_: {'some': 'results'})
expected_suite = create_autospec(TestSuite)
mock = Mock()
mock.running.build_suite = Mock(return_value=expected_suite)
Expand Down