If this is required, isn't it better to inherit from TestCase instead of object and use simple inheritance in tests?
@tkopecek The original idea of CliTestLib is to design a helper library. However it have to be manually initialized before use it. That's why I designed it as an independent class rather than inherited class.
rebased onto c3cfc322c6e6197b854db05b20aa84bb923f2eb2
rebased onto dd64b20dde837e5ac870ea80b37c40aee94ec865
rebased onto 51a12b5ca541a3c7b074e879bea5d14a83c2ac4f
@tkopecek I made some changes to improve the library. Changes include: * Rename CliTestLib to CliTestCase. * CliTestCase now is inherited from TestCase * initialize() takes no argument (previous was target test function but it is not needed any more) * simplify assert_system_exit interface and add help
:thumbsup:
rebased onto 99248d655ae06772524aef0882289aee6e6cbde6
Does __assert_lib_inited really need to be strictly private (the double underscore)? Makes it harder if we want to subclass in the future.
Does __assert_callable need to be private at all? For that matter, is it really any better than just using assert callable(callableObj)?
assert callable(callableObj)
I get the desire to unify some of the common code here, but is there more of a goal here? As it is, this patch adds more lines than it removes, which seems somewhat counter-intuitive.
The __assert_lib_inited is only used in the CliTestCase. in case we forget to call initialize() before using the member methods.
__assert_callable like __assert_lib_inited, are used for internal check, I don't think they should be public
Beside, I quickly realized the assert_func used in assert_system_exit needs callable check. Since there are two places need to check, and it might be useful in the future, I would like to keep __assert_callable exist.
When I was designing for other CLI unit tests, I realized there are many codes I can share in different tests. Therefore I create this patch and modify my previous tests to leverage CliTestCase.
There are several new test cases that are queued in my working repo and they all uses the class.
I also wonder about __error_format as strict private. It seems odd to me to make it private and build the setter method when it so much easier to just use attribute access.
__error_format
rebased onto 3fa1f772a8e425fc44404d1b9f9b6b9cd7c54d39
rebased onto 840a1e13691e7354929fb8b3d606e75da0a00821
rebased onto 869a0b58f761e956a8d13ace2103e307375e207b
@mikem After reviewing my commit again, I decided to make some change: 1) It seems the __init and initialize() are not necessary because all the attributes can be initialized during instance creation. So I decide to remove __init and initialize(), it makes the core more concise. 2) __error_format now is a public attribute and the setter is removed.
rebased onto b75f20e10d2d0773e40b939deb8bdd442637a288
rebased onto ed620b7e080d5f6f900f84edd75d1affed4b44b3
1 new commit added
New commit include: 1) remove debug_print and add print_message in CliTestCase. The print_message() print message on stdout without any influence from mock. 2) Add more unit tests for CLI (current coverage: 31%) test_add_tag.py test_disable_host.py test_enable_host.py test_import.py test_import_cg.py test_import_sig.py test_list_tasks.py test_mock_config.py test_restart_host.py test_search.py test_set_pkg_arches.py test_set_pkg_owner.py test_set_task_priority.py test_taskinfo.py test_unblock_pkg.py test_write_signed_rpm.py
rebased onto 2527b01fa2b4e670d333013fee9bca92fda9d582
seems to be throwing an error
PYTHONPATH=hub/.:plugins/hub/.:plugins/builder/.:plugins/cli/.:cli/.:www/lib nosetests tests/test_cli -x .........................................................................................................................................................................................F ====================================================================== FAIL: Test anon_handle_search function with argument error ---------------------------------------------------------------------- Traceback (most recent call last): File "/tmp/temp-work.CGsTR8/koji/tests/test_cli/test_search.py", line 75, in test_anon_handle_search_argument_error activate_session=None) File "/tmp/temp-work.CGsTR8/koji/tests/test_cli/utils.py", line 181, in assert_system_exit callableObj(*test_args, **test_kwargs) AssertionError: SystemExit not raised ---------------------------------------------------------------------- Ran 186 tests in 1.017s FAILED (failures=1)
and a few like this for make test3
====================================================================== ERROR: test_printTaskInfo_create_repo (tests.test_cli.test_taskinfo.TestPrintTaskInfo) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/mock/mock.py", line 1305, in patched return func(*args, **keywargs) File "/tmp/temp-work.CGsTR8/koji/tests/test_cli/test_taskinfo.py", line 427, in test_printTaskInfo_create_repo _printTaskInfo(session, 1, '/mnt/koji') File "/tmp/temp-work.CGsTR8/koji/cli/koji_cli/commands.py", line 4520, in _printTaskInfo children.sort(cmp=lambda a, b: cmp(a['id'], b['id'])) TypeError: 'cmp' is an invalid keyword argument for this function
cmp keyword in sorted()/list.sort() has been removed in python3, I had filed another PR for fixing this issue. https://pagure.io/koji/pull-request/714
and a few like this for make test3 ~~~~ ====================================================================== ERROR: test_printTaskInfo_create_repo (tests.test_cli.test_taskinfo.TestPrintTaskInfo) Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/mock/mock.py", line 1305, in patched return func(args, *keywargs) File "/tmp/temp-work.CGsTR8/koji/tests/test_cli/test_taskinfo.py", line 427, in test_printTaskInfo_create_repo _printTaskInfo(session, 1, '/mnt/koji') File "/tmp/temp-work.CGsTR8/koji/cli/koji_cli/commands.py", line 4520, in _printTaskInfo children.sort(cmp=lambda a, b: cmp(a['id'], b['id'])) TypeError: 'cmp' is an invalid keyword argument for this function ~~~~
and a few like this for make test3 ~~~~ ====================================================================== ERROR: test_printTaskInfo_create_repo (tests.test_cli.test_taskinfo.TestPrintTaskInfo)
Traceback (most recent call last): File "/usr/lib/python3.6/site-packages/mock/mock.py", line 1305, in patched return func(args, *keywargs) File "/tmp/temp-work.CGsTR8/koji/tests/test_cli/test_taskinfo.py", line 427, in test_printTaskInfo_create_repo _printTaskInfo(session, 1, '/mnt/koji') File "/tmp/temp-work.CGsTR8/koji/cli/koji_cli/commands.py", line 4520, in _printTaskInfo children.sort(cmp=lambda a, b: cmp(a['id'], b['id'])) TypeError: 'cmp' is an invalid keyword argument for this function ~~~~
seems to be throwing an error PYTHONPATH=hub/.:plugins/hub/.:plugins/builder/.:plugins/cli/.:cli/.:www/lib nosetests tests/test_cli -x .........................................................................................................................................................................................F ====================================================================== FAIL: Test anon_handle_search function with argument error Traceback (most recent call last): File "/tmp/temp-work.CGsTR8/koji/tests/test_cli/test_search.py", line 75, in test_anon_handle_search_argument_error activate_session=None) File "/tmp/temp-work.CGsTR8/koji/tests/test_cli/utils.py", line 181, in assert_system_exit callableObj(test_args, *test_kwargs) AssertionError: SystemExit not raised Ran 186 tests in 1.017s FAILED (failures=1)
seems to be throwing an error PYTHONPATH=hub/.:plugins/hub/.:plugins/builder/.:plugins/cli/.:cli/.:www/lib nosetests tests/test_cli -x .........................................................................................................................................................................................F ====================================================================== FAIL: Test anon_handle_search function with argument error
Traceback (most recent call last): File "/tmp/temp-work.CGsTR8/koji/tests/test_cli/test_search.py", line 75, in test_anon_handle_search_argument_error activate_session=None) File "/tmp/temp-work.CGsTR8/koji/tests/test_cli/utils.py", line 181, in assert_system_exit callableObj(test_args, *test_kwargs) AssertionError: SystemExit not raised
Ran 186 tests in 1.017s
FAILED (failures=1)
In order to fix https://pagure.io/koji/issue/706, The PR#707 has been filed, and this unit test is required fixed version.
@mikem When I was designing the unit tests, I figured out and filed some issue and PR separately: https://pagure.io/koji/issue/706 PR:#707 https://pagure.io/koji/issue/713 PR:#714
In order to run unit tests successfully, these PRs needs to be applied.
rebased onto 20ae22afbf9361d765522b1225e43a183f73d982
Commit #8cae09a Add unit test for koji image-build command
rebased onto f6d2c6beb38de5b878cdec392294eb87dfbee697
Commit b260aab9 fixes this pull-request
Pull-Request has been merged by mikem