def test_scenario3(self): '''Scenario 3.''' h=Hosts(self.hostsfile) h['localhost'] = '10.0.0.3' h['10.0.0.3'] ='toto' del h['toto'] del h['broadcasthost'] # Add a name to an address, change the address of a hostname h['localhost'] = '127.0.0.1' h.append('localhost', 'localhost.yemen') del h['127.0.0.1'] h.write(self.emptyfile) correct = """## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 1.0.0.1 localhost localhost.yemen # very pertinent comment ::1 localhost fe80::1%lo0 localhost 1.0.0.2 mc02 """ self.assertEqual(file(self.emptyfile).read(), '')
def test_append(self): '''Append''' eq=self.assertEqual h=Hosts() h['mc']='10.0.0.1' h.append('10.0.0.1','localhost') eq(h['10.0.0.1'],'mc localhost') h.append('localhost', 'localhost.yemen') eq(h['10.0.0.1'],'mc localhost localhost.yemen') h.append('localhost', 'mc') eq(h['10.0.0.1'],'mc localhost localhost.yemen') self.assertRaises(KeyError, h.append, 'tata', '192.168.0.1')