Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
#59: Tests coverage for --imports
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Nov 23, 2020
1 parent 620b952 commit a5935a7
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
55 changes: 55 additions & 0 deletions test/test_argparsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,58 @@ def test_global_arguments_are_changed_when_using_at_symbol_twice(self):
"Task<:send:mail ([])>]",
str(parsed)
)

def test_preparse_args_tolerates_not_recognized_args(self):
"""
Normally argparse would break the test. If it returns a value EVEN if there are unrecognized arguments,
then it works
"""

args = CommandlineParsingHelper.preparse_args(['--import', 'rkd_python', ':sh'])

self.assertIn('imports', args)
self.assertEqual(['rkd_python'], args['imports'])

def test_preparse_ignores_arguments_after_tasks(self):
"""
Arguments that could be preparsed should be placed behind any task
"""

args = CommandlineParsingHelper.preparse_args([':sh', '--import', 'rkd_python'])

self.assertEqual([], args['imports'])

def test_has_any_task(self):
"""
Checks if a commandline string has any task
"""

with self.subTest(':task'):
self.assertTrue(CommandlineParsingHelper.has_any_task([':task']))

with self.subTest('--help :task'):
self.assertTrue(CommandlineParsingHelper.has_any_task(['--help', ':task']))

with self.subTest(':task --test'):
self.assertTrue(CommandlineParsingHelper.has_any_task([':task', '--test']))

with self.subTest('--import rkd_python --help'):
self.assertFalse(CommandlineParsingHelper.has_any_task(['--import', 'rkd_python', '--help']))

def test_was_help_used(self):
"""
Checks if "--help" switch was used at all
:return:
"""

with self.subTest('--help'):
self.assertTrue(CommandlineParsingHelper.was_help_used(['--help']))

with self.subTest('-h'):
self.assertTrue(CommandlineParsingHelper.was_help_used(['-h']))

with self.subTest('Not used - empty string'):
self.assertFalse(CommandlineParsingHelper.was_help_used([]))

with self.subTest('Not used - non empty string - :tasks --print'):
self.assertFalse(CommandlineParsingHelper.was_help_used([':tasks', '--print']))
18 changes: 17 additions & 1 deletion test/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ def test_env_variables_are_escaped_when_coming_from_external(self):
"""
We assume that if "$" is in environment variable, then it is because it was previously escaped
else the shell would automatically inject a variable in its place - so we keep the escaping
:return:
"""

with self.environment({'RKD_PATH': SCRIPT_DIR_PATH + '/../docs/examples/recursive-env-in-yaml/.rkd'}):
Expand All @@ -271,3 +270,20 @@ def test_env_variables_are_escaped_when_coming_from_external(self):
full_output, exit_code = self.run_and_capture_output(['--no-ui', ':external-env'])

self.assertIn('This is $PATH', full_output)

def test_help_shows_imports_switch_only_behind_tasks(self):
"""
Checks that preparsed argument "--import" is available in --help only behind any task
"""

with self.subTest('Behind tasks'):
full_output, exit_code = self.run_and_capture_output(['--help'])
self.assertIn('--import', full_output)

with self.subTest('--help of a task'):
full_output, exit_code = self.run_and_capture_output([':sh', '--help'])
self.assertNotIn('--import', full_output)

with self.subTest('Behind tasks, but task defined'):
full_output, exit_code = self.run_and_capture_output(['--help', ':sh'])
self.assertIn('--import', full_output)

0 comments on commit a5935a7

Please sign in to comment.