import json, sys from pathlib import Path # I have to use `# type: ignore` so I don't get errors that these imports don't work. from helpers import error_message, getDataFolder, check_if_use_saved_directory, check_for_duplicates, set_default_directory, default_directory_exists, str2bool, dir_exists # type: ignore from parser import argc_allowed, create_parser, usage # type: ignore __doc__ = "Usage:\n" + usage argc_allowed() args = create_parser().parse_args() if args.command == 'add': if args.directory == None and not default_directory_exists(): error_message( 'Cannot use default directory if default directory not set', 3) target = args.target directory = check_if_use_saved_directory(args.directory) check_for_duplicates(target) if not Path(directory).is_dir(): # Checks if directory not found error_message("Directory not found (may be a file)", 1) create_new = "not bool" while create_new == "not bool": create_new = str2bool(input(f"Create new directory {directory}: ")) if create_new: Path(directory).mkdir(parents=True)
uids, (imap_mock.return_value.uid.return_value.__getitem__.return_value. __getitem__.return_value.split.return_value), ) def test_get_message(self): host = 'example.com' uid = 'uid1' with patch('classes.IMAP4_SSL', autospec=True) as imap_mock: with patch('classes.Parser', autospec=True) as parser_mock: imap_mock.return_value.uid.return_value = [ '', (('', sentinel.MessageText), ''), ] parser_mock.return_value.parsestr.return_value = sentinel.M checker = IMAPChecker(host) message = checker.get_message(uid) self.assertEqual( imap_mock.mock_calls, [call(host), call().uid('fetch', uid, '(RFC822)')]) self.assertEqual(parser_mock.mock_calls, [ call(), call().parsestr(sentinel.MessageText), ]) self.assertEqual(message, sentinel.M) if __name__ == "__main__": from helpers import error_message error_message()
def argc_allowed() -> None: if len(sys.argv) <= 1: error_message( 'No arguments were provided. Use -h or --help for information', 3) sys.exit(1)