# Path: pywayland/utils.py
# class AnonymousFile:
#     """Anonymous file object
# 
#     Provides access to anonymous file objects that can be used by Wayland
#     clients to render to surfaces.  Uses a method similar to Weston to open an
#     anonymous file, so XDG_RUNTIME_DIR must be set for this to work properly.
# 
#     This class provides a content manager, that is, it can be used with Python
#     ``with`` statements, where the value returned is the file descriptor.
#     """
# 
#     def __init__(self, size: int) -> None:
#         self.size = size
#         self.fd: int | None = None
# 
#     def __enter__(self) -> int:
#         self.open()
# 
#         assert self.fd is not None
#         return self.fd
# 
#     def __exit__(self, exc_type, exc_value, traceback) -> None:
#         self.close()
# 
#     def open(self) -> None:
#         """Open an anonymous file
# 
#         Opens the anonymous file and sets the ``fd`` property to the file
#         descriptor that has been opened.
#         """
#         if self.fd is not None:
#             raise IOError("File is already open")
#         self.fd = lib.os_create_anonymous_file(self.size)
#         if self.fd < 0:
#             raise IOError("Unable to create anonymous file")
# 
#     def close(self) -> None:
#         """Close the anonymous file
# 
#         Closes the file descriptor and sets the ``fd`` property to ``None``.
#         Does nothing if the file is not open.
#         """
#         if self.fd is None:
#             return
# 
#         os.close(self.fd)
#         self.fd = None


import pytest
from pywayland.utils import AnonymousFile
# Copyright 2021 Sean Vig
#
# Licensed 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.




def test_anonymous_file():
    with AnonymousFile(10) as fd:
        assert fd > 0


# Path: pywayland/utils.py
# class AnonymousFile:
#     """Anonymous file object
# 
#     Provides access to anonymous file objects that can be used by Wayland
#     clients to render to surfaces.  Uses a method similar to Weston to open an
#     anonymous file, so XDG_RUNTIME_DIR must be set for this to work properly.
# 
#     This class provides a content manager, that is, it can be used with Python
#     ``with`` statements, where the value returned is the file descriptor.
#     """
# 
#     def __init__(self, size: int) -> None:
#         self.size = size
#         self.fd: int | None = None
# 
#     def __enter__(self) -> int:
#         self.open()
# 
#         assert self.fd is not None
#         return self.fd
# 
#     def __exit__(self, exc_type, exc_value, traceback) -> None:
#         self.close()
# 
#     def open(self) -> None:
#         """Open an anonymous file
# 
#         Opens the anonymous file and sets the ``fd`` property to the file
#         descriptor that has been opened.
#         """
#         if self.fd is not None:
#             raise IOError("File is already open")
#         self.fd = lib.os_create_anonymous_file(self.size)
#         if self.fd < 0:
#             raise IOError("Unable to create anonymous file")
# 
#     def close(self) -> None:
#         """Close the anonymous file
# 
#         Closes the file descriptor and sets the ``fd`` property to ``None``.
#         Does nothing if the file is not open.
#         """
#         if self.fd is None:
#             return
# 
#         os.close(self.fd)
#         self.fd = None


# Path: test/test_utils.py
import pytest
from pywayland.utils import AnonymousFile

# Copyright 2021 Sean Vig
#
# Licensed 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.




def test_anonymous_file():
    with AnonymousFile(10) as fd:
        assert fd > 0


    f = AnonymousFile(10)