def test_SetupLogging(): testLogFile = '/tmp/test.log' assert os.path.exists(testLogFile) is False assert Utils.SetupLogging(testLogFile) is True logging.error('test_setupLogging error test') assert os.path.exists(testLogFile) is True os.unlink(testLogFile)
return d @staticmethod def InspectIPPacket(pktlen, data, timestamp): if not data: return decoded = LibVirtWakeOnLan.DecodeIPPacket(data[14:]) macaddress = LibVirtWakeOnLan.GetMACAddress(decoded['data']) if not macaddress: return return LibVirtWakeOnLan.StartServerByMACAddress(macaddress) if __name__ == '__main__': from lvwolutils import Utils Utils.SetupLogging() # line below is replaced on commit LVWOLVersion = "20140814 231218" Utils.ShowVersion(LVWOLVersion) if len(sys.argv) < 2: print('usage: libvirtwol <interface>') sys.exit(0) interface = sys.argv[1] p = pcap.pcapObject() net, mask = pcap.lookupnet(interface) p.open_live(interface, 1600, 0, 100) p.setfilter('udp and port 7 or port 9', 0, 0)
def test_showVersion(): assert Utils.ShowVersion("12345") is False sys.argv = ['testfile', 'version'] with pytest.raises(SystemExit): Utils.ShowVersion("12345")
def test_SetupLoggingFails(): testLogFile = '/tmp/dirthatdoesntexist/test.log' assert os.path.exists(testLogFile) is False assert Utils.SetupLogging(testLogFile) is False assert os.path.exists(testLogFile) is False