class FileDestination(DestinationDriver): def __init__(self, file_name, **options): self.driver_name = "file" self.path = Path(tc_parameters.WORKING_DIR, file_name) self.io = FileIO(self.path) super(FileDestination, self).__init__([self.path], options) def get_path(self): return self.path def read_log(self): return self.read_logs(1)[0] def read_logs(self, counter): return self.io.read_number_of_lines(counter) def read_until_logs(self, logs): return self.io.read_until_lines(logs)
class ExampleDestination(DestinationDriver): def __init__(self, filename, **options): self.driver_name = "example-destination" self.path = Path(tc_parameters.WORKING_DIR, filename) self.io = FileIO(self.path) super(ExampleDestination, self).__init__( None, dict({"filename": self.path.resolve()}, **options)) def get_path(self): return self.path def read_log(self): return self.read_logs(1)[0] def read_logs(self, counter): return self.io.read_number_of_lines(counter) def read_until_logs(self, logs): return self.io.read_until_lines(logs)
def test_file_io_multiple_write_read(temp_file, test_message): fileio = FileIO(temp_file) fileio.write(test_message) fileio.write(test_message) output = fileio.read_number_of_lines(2) assert [test_message, test_message] == output