def test_resolve_fail(self, mock_path): mock_path.isfile.return_value = False with self.assertRaises(RuntimeError): Config.resolve()
def setUpClass(cls): cls.config = Config(cls._HOSTS)
def test_from_ini_host_vendor_undefined(self): with six.assertRaisesRegex(self, ValueError, 'Undefined vendor .+ for host'): Config.from_ini(_HOST_VENDOR_UNDEFINED_INI)
def test_from_ini_explicit_vendor(self): config = Config.from_ini(_EXPLICIT_VENDOR_INI) self.assertEqual( config.find_host(self._HOST_A_NAME).vendor, self._HOST_B_VENDOR)
def test_from_ini_missing_host_key(self): with six.assertRaisesRegex(self, ValueError, 'key'): Config.from_ini(_MISSING_HOST_KEY_INI)
def test_from_ini_missing_host_hash(self): with six.assertRaisesRegex(self, ValueError, 'hash'): Config.from_ini(_MISSING_HOST_HASH_INI)
def test_from_ini_default_vendor_unspecified(self): with six.assertRaisesRegex(self, ValueError, 'when more than one is'): Config.from_ini(_DEFAULT_VENDOR_UNSPECIFIED_INI)
def test_from_ini_empty(self): with self.assertRaises(ValueError): Config.from_ini(_EMPTY_INI)
def test_from_ini_default_vendor_invalid(self): with six.assertRaisesRegex(self, ValueError, 'specified does not correspond'): Config.from_ini(_DEFAULT_VENDOR_INVALID_INI)
def test_from_ini_default_vendor_undefined(self): with six.assertRaisesRegex(self, ValueError, 'At least one'): Config.from_ini(_DEFAULT_VENDOR_UNDEFINED_INI)
def test_from_ini_empty_vendors(self): with six.assertRaisesRegex(self, ValueError, 'At least one'): Config.from_ini(_EMPTY_VENDORS_INI)
def test_from_ini_missing_vendors(self): with six.assertRaisesRegex(self, ValueError, 'special:vendors section'): Config.from_ini(_MISSING_VENDORS_INI)
def test_from_ini_malformed(self): # must be compatible with 2 and 3 - malformed ini treated differently with self.assertRaises(ValueError): Config.from_ini(_MALFORMED_INI)
def test_init_none(self): with self.assertRaises(ValueError): Config(None)
def test_from_ini_missing_hosts(self): with six.assertRaisesRegex(self, ValueError, 'at least one'): Config.from_ini(_MISSING_HOSTS_INI)
def test_init_empty(self): with self.assertRaises(ValueError): Config([])
def _read_file(name, encoding='utf-8'): """ Read the contents of a file. :param name: The name of the file in the current directory. :param encoding: The encoding of the file; defaults to utf-8. :return: The contents of the file. """ with codecs.open(name, encoding=encoding) as f: return f.read() __version__ = _read_file(path.join(path.dirname(__file__), 'VERSION')).strip() _config = Config.resolve() def host(identifier): """ Retrieve information about a host. :param identifier: The host's name, key or hash. :return: The matching host. """ identity = _config.find_host(identifier) return Host.request_from_identity(identity) def hosts(): """