-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from eficode/feat/multiple-params
Add support for passing multiple args from handler's keyword method
- Loading branch information
Showing
11 changed files
with
311 additions
and
4 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
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
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
Empty file.
17 changes: 17 additions & 0 deletions
17
tests/resources/my_dummy_handlers/dummy_handler_default_params.py
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,17 @@ | ||
from oxygen import BaseHandler | ||
|
||
|
||
class MyDummyHandler(BaseHandler): | ||
''' | ||
A test handler that throws mismatch argument exception if single argument | ||
is passed with multiple accepted | ||
''' | ||
|
||
def run_my_dummy_handler(self, result_file): | ||
return result_file | ||
|
||
def parse_results(self, result_file, foo='foo'): | ||
return { | ||
'name': result_file, | ||
'foo': foo | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/resources/my_dummy_handlers/dummy_handler_multiple_args.py
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,17 @@ | ||
from oxygen import BaseHandler | ||
|
||
|
||
class MyDummyHandler(BaseHandler): | ||
''' | ||
A test handler for unfolding parse_results arguments | ||
if it has multiple parameters | ||
''' | ||
|
||
def run_my_dummy_handler(self, result_file): | ||
return result_file, 'foo' | ||
|
||
def parse_results(self, result_file, foo): | ||
return { | ||
'name': result_file, | ||
'foo': foo | ||
} |
18 changes: 18 additions & 0 deletions
18
tests/resources/my_dummy_handlers/dummy_handler_multiple_args_too_few.py
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,18 @@ | ||
from oxygen import BaseHandler | ||
|
||
|
||
class MyDummyHandler(BaseHandler): | ||
''' | ||
A test handler that throws mismatch argument exception because | ||
parse_results expects too many arguments | ||
''' | ||
|
||
def run_my_dummy_handler(self, result_file): | ||
return result_file, 'foo' | ||
|
||
def parse_results(self, result_file, foo, bar): | ||
return { | ||
'name': result_file, | ||
'foo': foo, | ||
'bar': bar | ||
} |
15 changes: 15 additions & 0 deletions
15
tests/resources/my_dummy_handlers/dummy_handler_single_arg.py
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,15 @@ | ||
from oxygen import BaseHandler | ||
|
||
|
||
class MyDummyHandler(BaseHandler): | ||
''' | ||
A test handler for passing tuple if parse_results accepts one parameter | ||
''' | ||
|
||
def run_my_dummy_handler(self, result_file): | ||
return result_file, 'foo' | ||
|
||
def parse_results(self, result_file): | ||
return { | ||
'name': result_file | ||
} |
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
Empty file.
150 changes: 150 additions & 0 deletions
150
tests/utest/my_dummy_handler/test_basic_functionality.py
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,150 @@ | ||
import sys | ||
from unittest import TestCase | ||
from oxygen.errors import MismatchArgumentException | ||
from ..helpers import RESOURCES_PATH, get_config, example_robot_output | ||
|
||
sys.path.append(str(RESOURCES_PATH / 'my_dummy_handlers')) | ||
|
||
from dummy_handler_single_arg import ( | ||
MyDummyHandler as DummyHandlerSingleArg, | ||
) | ||
from dummy_handler_multiple_args import ( | ||
MyDummyHandler as DummyHandlerMultipleArgs, | ||
) | ||
from dummy_handler_multiple_args_too_few import ( | ||
MyDummyHandler as DummyHandlerMultipleArgsTooFew, | ||
) | ||
from dummy_handler_default_params import ( | ||
MyDummyHandler as DummyHandlerDefaultParams, | ||
) | ||
|
||
|
||
class DummyHandlerSingleArgTests(TestCase): | ||
''' | ||
A test for passing tuple if parse_results accepts one parameter | ||
''' | ||
|
||
def setUp(self): | ||
self.handler = DummyHandlerSingleArg( | ||
get_config()['oxygen.my_dummy_handler'] | ||
) | ||
|
||
def test_run_my_dummy_handler(self): | ||
return_value = self.handler.run_my_dummy_handler('/some/path/to.ext') | ||
self.assertTupleEqual(return_value, ('/some/path/to.ext', 'foo')) | ||
|
||
def test_parse_results(self): | ||
fake_test = example_robot_output().suite.suites[0].tests[6] | ||
expected_data = {'Atest.Test.My Fifth Test': '/some/path/to.ext'} | ||
|
||
self.handler.check_for_keyword(fake_test, expected_data) | ||
|
||
self.assertEqual(self.handler.run_time_data, '/some/path/to.ext') | ||
|
||
|
||
class DummyHandlerMultipleArgsTests(TestCase): | ||
''' | ||
A test for unfolding parse_results arguments | ||
if it has multiple parameters | ||
''' | ||
|
||
def setUp(self): | ||
self.handler = DummyHandlerMultipleArgs( | ||
get_config()['oxygen.my_dummy_handler'] | ||
) | ||
|
||
def test_parse_results(self): | ||
fake_test = example_robot_output().suite.suites[0].tests[6] | ||
expected_data = { | ||
'Atest.Test.My Fifth Test': ('/some/path/to.ext', 'foo') | ||
} | ||
|
||
self.handler.check_for_keyword(fake_test, expected_data) | ||
|
||
self.assertEqual( | ||
self.handler.run_time_data, ('/some/path/to.ext', 'foo') | ||
) | ||
|
||
|
||
class DummyHandlerMultipleArgsTooFewTests(TestCase): | ||
''' | ||
A test for testing if it throws mismatch argument exception because | ||
parse_results expects too many arguments | ||
''' | ||
|
||
def setUp(self): | ||
self.handler = DummyHandlerMultipleArgsTooFew( | ||
get_config()['oxygen.my_dummy_handler'] | ||
) | ||
|
||
def test_parse_results(self): | ||
fake_test = example_robot_output().suite.suites[0].tests[6] | ||
expected_data = { | ||
'Atest.Test.My Fifth Test': ('/some/path/to.ext', 'foo') | ||
} | ||
|
||
self.assertRaises( | ||
MismatchArgumentException, | ||
self.handler.check_for_keyword, | ||
fake_test, | ||
expected_data, | ||
) | ||
|
||
|
||
class DummyHandlerMultipleArgsSingleTests(TestCase): | ||
''' | ||
A test for testing if it throws mismatch argument exception because | ||
parse_results expects multiple arguments but we do not pass multiple | ||
''' | ||
|
||
def setUp(self): | ||
self.handler = DummyHandlerMultipleArgsTooFew( | ||
get_config()['oxygen.my_dummy_handler'] | ||
) | ||
|
||
def test_parse_results(self): | ||
fake_test = example_robot_output().suite.suites[0].tests[6] | ||
expected_data = {'Atest.Test.My Fifth Test': 'some/path/to.ext'} | ||
|
||
self.assertRaises( | ||
MismatchArgumentException, | ||
self.handler.check_for_keyword, | ||
fake_test, | ||
expected_data, | ||
) | ||
|
||
|
||
class DummyHandlerDefaultParamsTests(TestCase): | ||
''' | ||
A test for testing arguments with defaults | ||
''' | ||
|
||
def setUp(self): | ||
self.handler = DummyHandlerDefaultParams( | ||
get_config()['oxygen.my_dummy_handler'] | ||
) | ||
|
||
def test_parse_results_with_one(self): | ||
fake_test = example_robot_output().suite.suites[0].tests[6] | ||
expected_data = {'Atest.Test.My Fifth Test': 'some/path/to.ext'} | ||
self.handler.check_for_keyword(fake_test, expected_data) | ||
self.assertEqual(self.handler.run_time_data, 'some/path/to.ext') | ||
|
||
def test_parse_results_with_multiple(self): | ||
fake_test = example_robot_output().suite.suites[0].tests[6] | ||
expected_data = { | ||
'Atest.Test.My Fifth Test': ('some/path/to.ext', 'foo')} | ||
self.handler.check_for_keyword(fake_test, expected_data) | ||
self.assertTupleEqual( | ||
self.handler.run_time_data, ('some/path/to.ext', 'foo')) | ||
|
||
def test_parse_results_with_too_many(self): | ||
fake_test = example_robot_output().suite.suites[0].tests[6] | ||
expected_data = { | ||
'Atest.Test.My Fifth Test': ('some/path/to.ext', 'foo', 'bar')} | ||
self.assertRaises( | ||
MismatchArgumentException, | ||
self.handler.check_for_keyword, | ||
fake_test, | ||
expected_data, | ||
) |