# Path: android_env/components/thread_function.py
# class ThreadFunction(metaclass=abc.ABCMeta):
#   class Signal(enum.IntEnum):
#     KILL = 1
#   def __init__(self, block_input: bool, block_output: bool, name: str):
#   def read(self, block: bool = True, timeout: Optional[float] = None):
#   def write(self, value, block: bool = True, timeout: Optional[float] = None):
#   def main(self):
#   def kill(self):
#   def _run(self):
#   def _read_value(self):
#   def _write_value(self, value):


from absl.testing import absltest
from android_env.components import thread_function
# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for android_env.components.thread_function."""



class ThreadFunctionTest(absltest.TestCase):

  def test_hello_world(self):

    class HelloFunction(thread_function.ThreadFunction):

      def main(self):
        v = self._read_value()
        if v:
          self._write_value('hello')
        else:
          self._write_value('world')

    hello_fn = HelloFunction(block_input=True, block_output=True, name='Hello')
    hello_fn.write(True, block=True)
    self.assertEqual(hello_fn.read(block=True), 'hello')
    hello_fn.write(False, block=True)
    self.assertEqual(hello_fn.read(block=True), 'world')
    hello_fn.kill()  # Not strictly necessary, but it's good hygiene.

  def test_class_with_state(self):
    """Derived class with internal state to change the thread output."""


# Path: android_env/components/thread_function.py
# class ThreadFunction(metaclass=abc.ABCMeta):
#   class Signal(enum.IntEnum):
#     KILL = 1
#   def __init__(self, block_input: bool, block_output: bool, name: str):
#   def read(self, block: bool = True, timeout: Optional[float] = None):
#   def write(self, value, block: bool = True, timeout: Optional[float] = None):
#   def main(self):
#   def kill(self):
#   def _run(self):
#   def _read_value(self):
#   def _write_value(self, value):


# Path: android_env/components/thread_function_test.py
from absl.testing import absltest
from android_env.components import thread_function

# See the License for the specific language governing permissions and
# limitations under the License.

"""Tests for android_env.components.thread_function."""



class ThreadFunctionTest(absltest.TestCase):

  def test_hello_world(self):

    class HelloFunction(thread_function.ThreadFunction):

      def main(self):
        v = self._read_value()
        if v:
          self._write_value('hello')
        else:
          self._write_value('world')

    hello_fn = HelloFunction(block_input=True, block_output=True, name='Hello')
    hello_fn.write(True, block=True)
    self.assertEqual(hello_fn.read(block=True), 'hello')
    hello_fn.write(False, block=True)
    self.assertEqual(hello_fn.read(block=True), 'world')
    hello_fn.kill()  # Not strictly necessary, but it's good hygiene.

  def test_class_with_state(self):
    """Derived class with internal state to change the thread output."""


    class HaveState(thread_function.ThreadFunction):