def test_etc_file(self): # Test /etc/mailman.cfg fake_etc = '/etc' fake_testdir = self._make_fake(fake_etc) config_file = os.path.join(fake_etc, '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) self.assertEqual(search_for_configuration_file(), config_file)
def test_etc_file(self): # Test /etc/mailman.cfg fake_etc = '/etc' fake_testdir = self._make_fake(fake_etc) config_file = os.path.join(fake_etc, '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 >> fp, '# Fake mailman.cfg file' self.assertEqual(search_for_configuration_file(), config_file)
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 >> fp, '# Fake mailman.cfg file' with hackenv('HOME', '/home/neil'): self.assertEqual(search_for_configuration_file(), config_file)
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)
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 >> fp, '# Fake mailman.cfg file' with hackenv('MAILMAN_CONFIG_FILE', config_file): self.assertEqual(search_for_configuration_file(), config_file)
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)
def test_current_working_directory(self): fake_cwd = '/home/alex/mailman/hacking' fake_testdir = self._make_fake(fake_cwd) config_file = os.path.realpath( os.path.join(fake_testdir, '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 >> fp, '# Fake mailman.cfg file' with chdir(fake_testdir): # Sometimes symlinks bite us (eg. OS X /var -> /private/var). found = os.path.realpath(search_for_configuration_file()) self.assertEqual(found, config_file)
def test_current_working_directory(self): fake_cwd = '/home/alex/mailman/hacking' fake_testdir = self._make_fake(fake_cwd) config_file = os.path.realpath( os.path.join(fake_testdir, '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 chdir(fake_testdir): # Sometimes symlinks bite us (eg. OS X /var -> /private/var). found = os.path.realpath(search_for_configuration_file()) self.assertEqual(found, config_file)
def test_sibling_directory(self): # Test $argv0/../../etc/mailman.cfg fake_root = '/usr/local/mm3' fake_testdir = self._make_fake(fake_root) config_file = os.path.join(fake_testdir, 'etc', 'mailman.cfg') fake_config_file = os.path.join(fake_root, 'etc', 'mailman.cfg') fake_argv0 = os.path.join(fake_root, 'bin', 'mailman') with fakedirs(fake_testdir): with argv0(fake_argv0): os.mkdir(os.path.dirname(config_file)) # Write a mostly empty configuration file. with open(config_file, 'w') as fp: print >> fp, '# Fake mailman.cfg file' self.assertEqual(search_for_configuration_file(), fake_config_file)
def test_sibling_directory(self): # Test $argv0/../../etc/mailman.cfg fake_root = '/usr/local/mm3' fake_testdir = self._make_fake(fake_root) config_file = os.path.join(fake_testdir, 'etc', 'mailman.cfg') fake_config_file = os.path.join(fake_root, 'etc', 'mailman.cfg') fake_argv0 = os.path.join(fake_root, 'bin', 'mailman') with fakedirs(fake_testdir): with argv0(fake_argv0): os.mkdir(os.path.dirname(config_file)) # Write a mostly empty configuration file. with open(config_file, 'w') as fp: print('# Fake mailman.cfg file', file=fp) self.assertEqual(search_for_configuration_file(), fake_config_file)
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)
def test_baseline(self): # With nothing set, and no configuration files, just return None. self.assertEqual(search_for_configuration_file(), None)
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)
def test_baseline(self): # With nothing set, and no configuration files, just return None. self.assertEqual(search_for_configuration_file(), None)