diff -r 6a8ea0d363c1 -r 1d755df7bf97 pvl/hosts/tests.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pvl/hosts/tests.py Tue Feb 24 17:35:36 2015 +0200 @@ -0,0 +1,46 @@ +import ipaddr +import unittest + +from pvl.hosts import config +from StringIO import StringIO + +class Options(object): + hosts_charset = 'utf-8' + hosts_domain = None + hosts_include = None + +class NamedStringIO(StringIO): + def __init__(self, name, buffer): + StringIO.__init__(self, buffer) + self.name = name + +class TestConfig(unittest.TestCase): + def setUp(self): + self.options = Options() + + def testApplyHostsError(self): + with self.assertRaises(config.HostConfigError): + list(config.apply_hosts(self.options, ['nonexistant'])) + + def testApplyHosts(self): + expected = [ + ('foo', 'test', ipaddr.IPAddress('127.0.0.1')), + ('bar', 'test', ipaddr.IPAddress('127.0.0.2')), + ] + + for expect, host in zip(expected, config.apply_hosts_file(self.options, NamedStringIO('test', """ +[foo] + ip = 127.0.0.1 + +[bar] + ip = 127.0.0.2 +""" + ))): + hostname, domain, ip = expect + + self.assertEquals(str(host), hostname) + self.assertEquals(host.domain, domain) + self.assertEquals(host.ip, ip) + +if __name__ == '__main__': + unittest.main()