diff --git a/src/tests/test_overall.py b/src/tests/test_overall.py --- a/src/tests/test_overall.py +++ b/src/tests/test_overall.py @@ -13,31 +13,31 @@ from . import RedirectedOutput config.logger.removeHandler(config.handler) -handler=FileHandler("/tmp/morevna.log") +handler = FileHandler("/tmp/morevna.log") handler.setFormatter(config.formatter) config.logger.addHandler(handler) -config.batchSize.hash=8 -config.batchSize.data=8 +config.batchSize.hash = 8 +config.batchSize.data = 8 -dataDir=os.path.join(config.directory,"src/tests/data") -filename=os.path.join(dataDir,"test.img") +dataDir = os.path.join(config.directory, "src/tests/data") +filename = os.path.join(dataDir, "test.img") -def compareFiles(f1,f2): - with open(f1,mode="rb") as f: - h2=hashlib.sha256(f.read()).hexdigest() - with open(f2,mode="rb") as f: - h=hashlib.sha256(f.read()).hexdigest() - return (h,h2) +def compareFiles(f1, f2): + with open(f1, mode="rb") as f: + h2 = hashlib.sha256(f.read()).hexdigest() + with open(f2, mode="rb") as f: + h = hashlib.sha256(f.read()).hexdigest() + return (h, h2) -class TestMorevna(RedirectedOutput,TestCase): - _stdout=None +class TestMorevna(RedirectedOutput, TestCase): + _stdout = None def setUp(self): - src=os.path.join(dataDir,"test1.img") - shutil.copyfile(src,filename) + src = os.path.join(dataDir, "test1.img") + shutil.copyfile(src, filename) @classmethod def tearDownClass(cls): @@ -45,68 +45,68 @@ class TestMorevna(RedirectedOutput,TestC os.remove(filename) def test_build(self): - treeFile=os.path.join(dataDir,"test.bin") - refFile=os.path.join(dataDir,"test1.bin") + treeFile = os.path.join(dataDir, "test.bin") + refFile = os.path.join(dataDir, "test1.bin") - tree=HashTree.fromFile(os.path.join(dataDir,"test1.img")) + tree = HashTree.fromFile(os.path.join(dataDir, "test1.img")) tree.save(treeFile) - self.assertEqual(*compareFiles(refFile,treeFile)) + self.assertEqual(*compareFiles(refFile, treeFile)) os.remove(treeFile) def test_push(self): - config.port+=1 - ms=Miniserver(filename) - p=multiprocessing.Process(target=ms.serve) + config.port += 1 + ms = Miniserver(filename) + p = multiprocessing.Process(target=ms.serve) p.start() - for clientFile in ("test2.img","test3.img","test4.img"): - clientFile=os.path.join(dataDir,clientFile) - c=Client(clientFile) - with ClientConnection("127.0.0.1",config.port) as con: + for clientFile in ("test2.img", "test3.img", "test4.img"): + clientFile = os.path.join(dataDir, clientFile) + c = Client(clientFile) + with ClientConnection("127.0.0.1", config.port) as con: c.setConnection(con) c.init("push") - blocksToTransfer=c.negotiate() + blocksToTransfer = c.negotiate() c.sendData(blocksToTransfer) - self.assertEqual(*compareFiles(clientFile,filename)) + self.assertEqual(*compareFiles(clientFile, filename)) p.terminate() p.join() def test_pull(self): - config.port+=1 - serverFile=os.path.join(dataDir,"test3.img") - ms=Miniserver(serverFile) - p=multiprocessing.Process(target=ms.serve) + config.port += 1 + serverFile = os.path.join(dataDir, "test3.img") + ms = Miniserver(serverFile) + p = multiprocessing.Process(target=ms.serve) p.start() - c=Client(filename) - with ClientConnection("127.0.0.1",config.port) as con: + c = Client(filename) + with ClientConnection("127.0.0.1", config.port) as con: c.setConnection(con) c.init("pull") - blocksToTransfer=c.negotiate() + blocksToTransfer = c.negotiate() c.pullData(blocksToTransfer) - self.assertEqual(*compareFiles(serverFile,filename)) + self.assertEqual(*compareFiles(serverFile, filename)) p.terminate() p.join() def test_deny(self): - config.port+=1 - ms=Miniserver(filename) - p=multiprocessing.Process(target=ms.serve) + config.port += 1 + ms = Miniserver(filename) + p = multiprocessing.Process(target=ms.serve) p.start() - c1=Client(os.path.join(dataDir,"test2.img")) - with ClientConnection("127.0.0.1",config.port) as con1: + c1 = Client(os.path.join(dataDir, "test2.img")) + with ClientConnection("127.0.0.1", config.port) as con1: c1.setConnection(con1) c1.init("push") - c2=Client(os.path.join(dataDir,"test3.img")) - with ClientConnection("127.0.0.1",config.port) as con2: + c2 = Client(os.path.join(dataDir, "test3.img")) + with ClientConnection("127.0.0.1", config.port) as con2: c2.setConnection(con2) with self.assertRaises(DeniedConnection): c2.init("push")