Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#298: return an error in case of invalid command #3

Merged
merged 19 commits into from
May 4, 2023
Merged
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
18 changes: 18 additions & 0 deletions test/test_get_sub_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import unittest
import os
import pytest

from topydo.Commands import get_subcommand
from topydo.commands.AddCommand import AddCommand
Expand Down Expand Up @@ -410,5 +412,21 @@ def test_help(self):
self.assertFalse(real_cmd)
self.assertEqual(final_args, ['help', 'nonexisting'])

def test_invalidCommand(self):
os.system('topydo joker > test_file.txt')
test_file_name = str(open('test_file.txt').readlines())
self.assertIn('Error invalid command: joker :( Please try again. ', test_file_name )
os.remove('test_file.txt')

@pytest.fixture(autouse=True)
def _pass_fixtures(self, capsys):
self.capsys = capsys

def test_invalidCommand2(self):
get_subcommand(['helloworld'])
captured = self.capsys.readouterr()
self.assertEqual('Error invalid command: helloworld :( Please try again. \n', captured.out)


if __name__ == '__main__':
unittest.main()
1 change: 1 addition & 0 deletions topydo/Commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def resolve_alias(p_alias, p_args):
result = import_subcommand(f'help{subcommand}')
args = []
else:
print(f'Error invalid command: {subcommand} :( Please try again. ')
p_command = config().default_command()
if p_command in alias_map:
result, args = resolve_alias(p_command, args)
Expand Down
Loading