def testDirectCopy(self): def writeTestData(filename): with open(filename, 'w') as f: from time import sleep for i in range(1,10): print i sleep(0.1) f.write("%d\n" % i) # Create reader = StreamingFile(writeTestData) expect(reader.thread.is_alive()).to_be_truthy() expect(exists(reader.name)).to_be_truthy() contents = reader.read(10) expect(contents).to_equal("\n".join(map(str,range(1,6)))+"\n") contents = reader.read(1024) expect(contents).to_equal("\n".join(map(str,range(6,10)))+"\n") contents = reader.read(1024) expect(contents).to_equal('') expect(exists(reader.name)).to_be_truthy() reader.close() expect(exists(reader.name)).to_be_falsy()
def testDirectCopy(self): def writeTestData(filename): with open(filename, 'w') as f: from time import sleep for i in range(1,10): print i sleep(0.1) f.write("%d\n" % i) # Test the asynchronous flavor reader = StreamingFile(writeTestData, asynchronous_file_creation=True) expect(reader.thread.is_alive()).to_be_truthy() expect(exists(reader.name)).to_be_truthy() contents = reader.read(10) expect(contents).to_equal("\n".join(map(str,range(1,6)))+"\n") contents = reader.read(1024) expect(contents).to_equal("\n".join(map(str,range(6,10)))+"\n") contents = reader.read(1024) expect(contents).to_equal('') expect(exists(reader.name)).to_be_truthy() reader.close() expect(exists(reader.name)).to_be_falsy() # Test the synchronous flavor reader = StreamingFile(writeTestData, asynchronous_file_creation=False) expect(hasattr(reader, 'thread')).to_be_falsy() expect(exists(reader.name)).to_be_truthy() contents = reader.read(10) expect(contents).to_equal("\n".join(map(str,range(1,6)))+"\n") contents = reader.read(1024) expect(contents).to_equal("\n".join(map(str,range(6,10)))+"\n") contents = reader.read(1024) expect(contents).to_equal('') expect(exists(reader.name)).to_be_truthy() reader.close() expect(exists(reader.name)).to_be_falsy()