Skip to content

Commit

Permalink
Merge pull request #3 from mariabui/298_st
Browse files Browse the repository at this point in the history
topydo#298: return an error in case of invalid command
  • Loading branch information
mariabui committed May 4, 2023
2 parents 36bb1a3 + 364e2d0 commit bb25fe1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit bb25fe1

Please sign in to comment.