Exemplo n.º 1
0
 def setUp(cls):
     cls.resources = ExitStack()
     plugin_path = os.path.join(
         os.path.dirname(resource_filename('mailman.plugins',
                                           '__init__.py')), 'testing')
     config_file = resource_filename('mailman.plugins.testing', 'rest.cfg')
     cls.resources.enter_context(hackenv('MAILMAN_CONFIG_FILE',
                                         config_file))
     cls.resources.enter_context(hackenv('PYTHONPATH', plugin_path))
     cls.server = TestableMaster(wait_for_webservice)
     cls.server.start('rest')
     cls.resources.callback(cls.server.stop)
Exemplo n.º 2
0
 def test_interact_no_upframe(self):
     upframed = False                            # noqa
     fp = self._enter(NamedTemporaryFile('w', encoding='utf-8'))
     self._enter(hackenv('PYTHONSTARTUP', fp.name))
     print('print(upframed)', file=fp)
     fp.flush()
     interact(upframe=False, banner='')
     lines = self._stderr.getvalue().splitlines()
     self.assertIn("NameError: name 'upframed' is not defined", lines)
Exemplo n.º 3
0
 def test_interact_no_upframe(self):
     upframed = False                                         # noqa: F841
     fp = self._enter(NamedTemporaryFile('w', encoding='utf-8'))
     self._enter(hackenv('PYTHONSTARTUP', fp.name))
     print('print(upframed)', file=fp)
     fp.flush()
     interact(upframe=False, banner='')
     lines = self._stderr.getvalue().splitlines()
     self.assertIn("NameError: name 'upframed' is not defined", lines)
Exemplo n.º 4
0
 def test_interact(self):
     mlist = create_list('*****@*****.**')
     results = []
     fp = self._enter(NamedTemporaryFile('w', encoding='utf-8'))
     self._enter(hackenv('PYTHONSTARTUP', fp.name))
     print('results.append(mlist.list_id)', file=fp)
     fp.flush()
     interact()
     self.assertEqual(results, [mlist.list_id])
Exemplo n.º 5
0
 def test_interact(self):
     mlist = create_list('*****@*****.**')
     results = []
     fp = self._enter(NamedTemporaryFile('w', encoding='utf-8'))
     self._enter(hackenv('PYTHONSTARTUP', fp.name))
     print('results.append(mlist.list_id)', file=fp)
     fp.flush()
     interact()
     self.assertEqual(results, [mlist.list_id])
Exemplo n.º 6
0
 def test_home_dot_file(self):
     # Test ~/.mailman.cfg
     fake_home = '/home/neil'
     fake_testdir = self._make_fake(fake_home)
     config_file = os.path.join(fake_home, '.mailman.cfg')
     with fakedirs(fake_testdir):
         # Write a mostly empty configuration file.
         with open(os.path.join(fake_testdir, '.mailman.cfg'), 'w') as fp:
             print('# Fake mailman.cfg file', file=fp)
         with hackenv('HOME', '/home/neil'):
             self.assertEqual(search_for_configuration_file(), config_file)
Exemplo n.º 7
0
 def test_interact_multiline(self):
     # GL issue #224.
     fp = self._enter(NamedTemporaryFile('w', encoding='utf-8'))
     self._enter(hackenv('PYTHONSTARTUP', fp.name))
     print('import sys', file=fp)
     print("print('hello', file=sys.stderr)", file=fp)
     print("print('world', file=sys.stderr)", file=fp)
     fp.flush()
     interact(banner='')
     lines = self._stderr.getvalue()
     self.assertEqual(lines, 'hello\nworld\n\n', lines)
Exemplo n.º 8
0
 def test_home_dot_file(self):
     # Test ~/.mailman.cfg
     fake_home = '/home/neil'
     fake_testdir = self._make_fake(fake_home)
     config_file = os.path.join(fake_home, '.mailman.cfg')
     with fakedirs(fake_testdir):
         # Write a mostly empty configuration file.
         with open(os.path.join(fake_testdir, '.mailman.cfg'), 'w') as fp:
             print('# Fake mailman.cfg file', file=fp)
         with hackenv('HOME', '/home/neil'):
             self.assertEqual(search_for_configuration_file(), config_file)
Exemplo n.º 9
0
 def test_interact_multiline(self):
     # GL issue #224.
     fp = self._enter(NamedTemporaryFile('w', encoding='utf-8'))
     self._enter(hackenv('PYTHONSTARTUP', fp.name))
     print('import sys', file=fp)
     print("print('hello', file=sys.stderr)", file=fp)
     print("print('world', file=sys.stderr)", file=fp)
     fp.flush()
     interact(banner='')
     lines = self._stderr.getvalue()
     self.assertEqual(lines, 'hello\nworld\n\n', lines)
Exemplo n.º 10
0
 def test_environment_variable(self):
     # Test that $MAILMAN_CONFIG_FILE pointing to an existing path returns
     # that path.
     fake_home = '/home/geddy/testing/mailman'
     fake_testdir = self._make_fake(fake_home)
     config_file = os.path.join(fake_home, 'mailman.cfg')
     with fakedirs(fake_testdir):
         # Write a mostly empty configuration file.
         with open(os.path.join(fake_testdir, 'mailman.cfg'), 'w') as fp:
             print('# Fake mailman.cfg file', file=fp)
         with hackenv('MAILMAN_CONFIG_FILE', config_file):
             self.assertEqual(search_for_configuration_file(), config_file)
Exemplo n.º 11
0
 def test_environment_variable(self):
     # Test that $MAILMAN_CONFIG_FILE pointing to an existing path returns
     # that path.
     fake_home = '/home/geddy/testing/mailman'
     fake_testdir = self._make_fake(fake_home)
     config_file = os.path.join(fake_home, 'mailman.cfg')
     with fakedirs(fake_testdir):
         # Write a mostly empty configuration file.
         with open(os.path.join(fake_testdir, 'mailman.cfg'), 'w') as fp:
             print('# Fake mailman.cfg file', file=fp)
         with hackenv('MAILMAN_CONFIG_FILE', config_file):
             self.assertEqual(search_for_configuration_file(), config_file)
Exemplo n.º 12
0
 def test_environment_variable_to_missing_path(self):
     # Test that $MAILMAN_CONFIG_FILE pointing to a non-existent path still
     # returns None.
     with hackenv('MAILMAN_CONFIG_FILE', '/does/not/exist'):
         self.assertEqual(search_for_configuration_file(), None)
Exemplo n.º 13
0
 def test_environment_variable_to_missing_path(self):
     # Test that $MAILMAN_CONFIG_FILE pointing to a non-existent path still
     # returns None.
     with hackenv('MAILMAN_CONFIG_FILE', '/does/not/exist'):
         self.assertEqual(search_for_configuration_file(), None)
Exemplo n.º 14
0
 def test_interact_default_banner(self):
     self._enter(hackenv('PYTHONSTARTUP', None))
     interact()
     stderr = self._stderr.getvalue().splitlines()
     banner = 'Python {} on {} '.format(sys.version, sys.platform)
     self.assertEqual(stderr[0], banner.splitlines()[0])
Exemplo n.º 15
0
 def test_interact_custom_banner(self):
     self._enter(hackenv('PYTHONSTARTUP', None))
     interact(banner='Welcome')
     stderr = self._stderr.getvalue().splitlines()
     self.assertEqual(stderr[0], 'Welcome')
Exemplo n.º 16
0
 def test_interact_custom_banner(self):
     self._enter(hackenv('PYTHONSTARTUP', None))
     interact(banner='Welcome')
     stderr = self._stderr.getvalue().splitlines()
     self.assertEqual(stderr[0], 'Welcome')
Exemplo n.º 17
0
 def test_interact_default_banner(self):
     self._enter(hackenv('PYTHONSTARTUP', None))
     interact()
     stderr = self._stderr.getvalue().splitlines()
     banner = 'Python {} on {} '.format(sys.version, sys.platform)
     self.assertEqual(stderr[0], banner.splitlines()[0])