def test_length(self): hosts = HostnameList() hosts.add("test1") hosts.add("test2") assert_equals(len(hosts), 2) hosts.add("test1") assert_equals(len(hosts), 2)
def test_indexing(self): hosts = HostnameList() hosts.add("test1") assert_equals(hosts[0].name, "test1") hosts.add("test2") assert_equals(hosts[1].name, "test2") assert_equals(hosts[-1].name, "test2")
def test_str(self): hosts = HostnameList() hosts.add('1.2.3.4') assert_equals(hosts.__str__(), 'HostList (1)') hosts.add('2.3.4.5') hosts.add('3.4.5.6') hosts.add('4.5.6.7') assert_equals(hosts.__str__(), 'HostList (4)')
def test_deletion(self): hosts = HostnameList() hosts.add("test1") assert_equals(len(hosts), 1) hosts.add("test2") assert_equals(len(hosts), 2) del hosts[-1] assert_equals(len(hosts), 1)
def test_repr(self): hosts = HostnameList() hosts.add('1.2.3.4') assert_equals(hosts.__repr__(), '<HostList \'1.2.3.4\'>') hosts.add('2.3.4.5') hosts.add('3.4.5.6') hosts.add('4.5.6.7') assert_equals(hosts.__repr__(), '<HostList \'1.2.3.4, 2.3.4.5, 3.4.5.6\'>')
def test_str(self): hosts = HostnameList() hosts.add("1.2.3.4") assert_equals(hosts.__str__(), "HostList (1)") hosts.add("2.3.4.5") hosts.add("3.4.5.6") hosts.add("4.5.6.7") assert_equals(hosts.__str__(), "HostList (4)")
def test_repr(self): hosts = HostnameList() hosts.add("1.2.3.4") assert_equals(hosts.__repr__(), "<HostList '1.2.3.4'>") hosts.add("2.3.4.5") hosts.add("3.4.5.6") hosts.add("4.5.6.7") assert_equals(hosts.__repr__(), "<HostList '1.2.3.4, 2.3.4.5, 3.4.5.6'>")
def test_contains_host(self): host = HostnameList() host.add(Hostname("test", "1.2.3.4")) assert_true("test" in host) assert_true(Hostname("test") in host) assert_true(Hostname("test", "1.2.3.4") in host) assert_true(Hostname("test.example.com") in host) assert_true(Hostname("test.example.com", "1.2.3.4") in host) assert_false("test1" in host) assert_false(Hostname("test1") in host) assert_false(Hostname("test1", "2.3.4.5") in host) assert_false(Hostname("test1.example.com") in host) assert_false(Hostname("test1.example.com", "2.3.4.5") in host)
def test_contains_host(self): host = HostnameList() host.add(Hostname('test', '1.2.3.4')) assert_true('test' in host) assert_true(Hostname('test') in host) assert_true(Hostname('test', '1.2.3.4') in host) assert_true(Hostname('test.example.com') in host) assert_true(Hostname('test.example.com', '1.2.3.4') in host) assert_false('test1' in host) assert_false(Hostname('test1') in host) assert_false(Hostname('test1', '2.3.4.5') in host) assert_false(Hostname('test1.example.com') in host) assert_false(Hostname('test1.example.com', '2.3.4.5') in host)
def test_add_fail(self): hosts = HostnameList() hosts.add('test1', '1.1.1.1') assert_equals(len(hosts), 1) assert_raises(TypeError, hosts.add) assert_equals(len(hosts), 1) hosts.add(ip='1.1.1.1') assert_equals(len(hosts), 1) hosts.add('1.1.1.1') assert_equals(len(hosts), 1)
def test_add_fail(self): hosts = HostnameList() hosts.add("test1", "1.1.1.1") assert_equals(len(hosts), 1) assert_raises(TypeError, hosts.add) assert_equals(len(hosts), 1) hosts.add(ip="1.1.1.1") assert_equals(len(hosts), 1) hosts.add("1.1.1.1") assert_equals(len(hosts), 1)
def test_indexing(self): hosts = HostnameList() hosts.add('test1') assert_equals(hosts[0].name, 'test1') hosts.add('test2') assert_equals(hosts[1].name, 'test2') assert_equals(hosts[-1].name, 'test2')
def test_length(self): hosts = HostnameList() hosts.add('test1') hosts.add('test2') assert_equals(len(hosts), 2) hosts.add('test1') assert_equals(len(hosts), 2)
def test_itr(self): hosts = HostnameList() hosts.add('test1') hosts.add('test2') host = hosts.next() assert_equals(host.name, 'test1') host = hosts.next() assert_equals(host.name, 'test2') assert_raises(StopIteration, hosts.next) host = hosts.next() assert_equals(host.name, 'test1') host = hosts.next() assert_equals(host.name, 'test2') assert_raises(StopIteration, hosts.next)
def test_deletion(self): hosts = HostnameList() hosts.add('test1') assert_equals(len(hosts), 1) hosts.add('test2') assert_equals(len(hosts), 2) del hosts[-1] assert_equals(len(hosts), 1)
def test_itr(self): hosts = HostnameList() hosts.add("test1") hosts.add("test2") host = hosts.next() assert_equals(host.name, "test1") host = hosts.next() assert_equals(host.name, "test2") assert_raises(StopIteration, hosts.next) host = hosts.next() assert_equals(host.name, "test1") host = hosts.next() assert_equals(host.name, "test2") assert_raises(StopIteration, hosts.next)
def test_get(self): hosts = HostnameList() hosts.add("test") assert_equals(hosts.get("test"), Hostname("test")) assert_equals(hosts.get("test"), Hostname("test")) assert_equals(hosts.get("test"), Hostname("test")) assert_equals(hosts.get("test1"), None) hosts.add("test.example.com") assert_equals(hosts.get("test"), Hostname("test")) assert_equals(hosts.get("test.example.com"), Hostname("test")) assert_equals(hosts.get("test"), Hostname("test.example.com")) assert_equals(hosts.get("test.example.com"), Hostname("test.example.com"))
def test_add(self): hosts = HostnameList() hosts.add("test1") assert_in("test1", hosts) assert_not_in("test2", hosts)
def test_add(self): hosts = HostnameList() hosts.add('test1') assert_in('test1', hosts) assert_not_in('test2', hosts)
def test_get(self): hosts = HostnameList() hosts.add('test') assert_equals(hosts.get('test'), Hostname('test')) assert_equals(hosts.get('test'), Hostname('test')) assert_equals(hosts.get('test'), Hostname('test')) assert_equals(hosts.get('test1'), None) hosts.add('test.example.com') assert_equals(hosts.get('test'), Hostname('test')) assert_equals(hosts.get('test.example.com'), Hostname('test')) assert_equals(hosts.get('test'), Hostname('test.example.com')) assert_equals(hosts.get('test.example.com'), Hostname('test.example.com'))