samredai commented on a change in pull request #3691: URL: https://github.com/apache/iceberg/pull/3691#discussion_r789264740
########## File path: python/tests/io/test_base.py ########## @@ -0,0 +1,116 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import io + +from iceberg.io.base import FileIO, InputFile, OutputFile + + +class FooInputFile(InputFile): + def __len__(self): + return io.BytesIO(b"foo").getbuffer().nbytes + + def exists(self): + return True + + def __enter__(self): + super().__enter__() + return io.BytesIO(b"foo") + + def __exit__(self, exc_type, exc_value, exc_traceback): + super().__exit__(exc_type, exc_value, exc_traceback) + return + + +class FooOutputFile(OutputFile): + def __call__(self, overwrite: bool = False, **kwargs): + super().__call__(overwrite=True) + return self + + def __len__(self): + return len(self._file_obj) + + def exists(self): + return True + + def to_input_file(self): + return FooInputFile(location=self.location) + + def __enter__(self): + self._mock_storage = io.BytesIO() + return self._mock_storage + + def __exit__(self, exc_type, exc_value, exc_traceback): + super().__exit__(exc_type, exc_value, exc_traceback) + return + + +class FooFileIO(FileIO): Review comment: I've updated the tests to use a `LocalFileIO`, `LocalInputFile`, and `LocalOutputFile` implementation. I've also made the tests more generic by configuring them to take a list of implementation classes. I'm using `tempfile` which is part of the python standard library to create temporary directories/files to test the local file-io. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
