コード例 #1
0
def import21(ctx, charset, listspec, pickle_file):
    mlist = getUtility(IListManager).get(listspec)
    if mlist is None:
        ctx.fail(_('No such list: $listspec'))
    with ExitStack() as resources:
        resources.enter_context(hacked_sys_modules('Mailman', _Mailman))
        resources.enter_context(hacked_sys_modules('Mailman.Bouncer',
                                                   _Bouncer))
        resources.enter_context(transaction())
        while True:
            try:
                config_dict = pickle.load(pickle_file,
                                          encoding=charset,
                                          errors='ignore')
            except EOFError:
                break
            except pickle.UnpicklingError:
                ctx.fail(
                    _('Not a Mailman 2.1 configuration file: $pickle_file'))
            else:
                if not isinstance(config_dict, dict):
                    print(_('Ignoring non-dictionary: {0!r}').format(
                        config_dict),
                          file=sys.stderr)
                    continue
                try:
                    import_config_pck(mlist, config_dict)
                except Import21Error as error:
                    print(error, file=sys.stderr)
                    sys.exit(1)
コード例 #2
0
ファイル: test_cli_shell.py プロジェクト: inonit/mailman
 def test_start_ipython_debug(self):
     mock = MagicMock()
     with hacked_sys_modules('IPython.terminal.embed', mock):
         self._command.invoke(shell, ('--interactive',))
     posargs, kws = mock.InteractiveShellEmbed.instance().mainloop.call_args
     self.assertEqual(
         kws['display_banner'], 'Welcome to the GNU Mailman shell\n')
コード例 #3
0
ファイル: test_cli_shell.py プロジェクト: inonit/mailman
 def test_run_without_listspec(self):
     something = ModuleType('something')
     something.something = lambda: print('I am a something!')
     with hacked_sys_modules('something', something):
         results = self._command.invoke(shell, ('--run', 'something'))
     self.assertEqual(results.exit_code, 0)
     self.assertEqual(results.output, 'I am a something!\n')
コード例 #4
0
 def test_start_ipython_invalid(self):
     mock = MagicMock()
     with hacked_sys_modules('IPython.terminal.embed', mock):
         results = self._command.invoke(shell, ('--interactive', ))
     self.assertEqual(results.output,
                      'Invalid value for [shell]use_python: oops\n')
     # mainloop() never got called.
     self.assertIsNone(
         mock.InteractiveShellEmbed.instance().mainloop.call_args)
コード例 #5
0
    def test_start_ipython1(self):
        mock = MagicMock()
        with hacked_sys_modules('IPython.frontend.terminal.embed', mock):
            self._command.invoke(shell, ('--interactive',))
        posargs, kws = mock.InteractiveShellEmbed.instance.call_args
        self.assertEqual(
            kws['banner1'], """Welcome to the GNU Mailman shell
Use commit() to commit changes.
Use abort() to discard changes since the last commit.
Exit with ctrl+D does an implicit commit() but exit() does not.\n""")
コード例 #6
0
 def test_listspec_without_run(self):
     create_list('*****@*****.**')
     mock = MagicMock()
     with ExitStack() as resources:
         resources.enter_context(
             hacked_sys_modules('IPython.terminal.embed', mock))
         interactive_mock = resources.enter_context(
             patch('mailman.commands.cli_withlist.do_interactive'))
         self._command.invoke(shell, ('-l', 'ant.example.com'))
     posargs, kws = interactive_mock.call_args
     self.assertEqual(
         posargs[1], "The variable 'm' is the ant.example.com mailing list")
コード例 #7
0
 def test_hacked_sys_modules_restore(self):
     email_package = sys.modules['email']
     sentinel = object()
     with hacked_sys_modules('email', sentinel):
         self.assertEqual(sys.modules.get('email'), sentinel)
     self.assertEqual(sys.modules.get('email'), email_package)
コード例 #8
0
 def test_hacked_sys_modules(self):
     self.assertIsNone(sys.modules.get('mailman.not_a_module'))
     with hacked_sys_modules('mailman.not_a_module', object()):
         self.assertIsNotNone(sys.modules.get('mailman.not_a_module'))