# Path: android_env/components/app_screen_checker.py
# class DumpsysNode():
# class AppScreenChecker():
#   class Outcome(enum.IntEnum):
#   def __init__(self, data: Optional[str] = None):
#   def data(self) -> str:
#   def children(self) -> List['DumpsysNode']:
#   def find_child(self,
#                  predicate: Callable[['DumpsysNode'], bool],
#                  max_levels: int = 0) -> Optional['DumpsysNode']:
#   def __repr__(self):
#   def print_tree(self, indent: int = 2):
# def build_tree_from_dumpsys_output(dumpsys_output: str) -> DumpsysNode:
# def matches_path(dumpsys_activity_output: str,
#                  expected_view_hierarchy_path: Sequence[Pattern[str]],
#                  max_levels: int = 0) -> bool:
#     def regex_predicate(node, expr=regex):
#   def __init__(self,
#                adb_controller: adb_control.AdbController,
#                expected_app_screen: task_pb2.AppScreen):
#   def matches_current_app_screen(self) -> enum.IntEnum:
#     SUCCESS = 0
#     EMPTY_EXPECTED_ACTIVITY = 1
#     FAILED_ACTIVITY_EXTRACTION = 2
#     UNEXPECTED_ACTIVITY = 3
#     UNEXPECTED_VIEW_HIERARCHY = 4


import re
from typing import Sequence
from absl.testing import absltest
from android_env.components import app_screen_checker
TASK
  ACTIVITY
    Some node we don't care
      Blah

    View Hierarchy
      Hirohito
        Akihito
          Naruhito
            Aiko
          Fumihito
            Mako
            Kako
            Hisahito
        Masahito
"""
    expected_path = ['^Hirohito$', 'Akihito$', 'Fumihito$', 'Kako$']
    expected_view_hierarchy_path = [
        re.compile(regex) for regex in expected_path
    ]
    self.assertTrue(
        app_screen_checker.matches_path(
            dumpsys_output, expected_view_hierarchy_path, max_levels=2))

    # Also check that the following path does not match anything in the tree.
    expected_path = ['^Hirohito$', 'Akihito$', 'Fumihito$', 'Kenji$']
    expected_view_hierarchy_path = [
        re.compile(regex) for regex in expected_path
    ]
    self.assertFalse(

# Path: android_env/components/app_screen_checker.py
# class DumpsysNode():
# class AppScreenChecker():
#   class Outcome(enum.IntEnum):
#   def __init__(self, data: Optional[str] = None):
#   def data(self) -> str:
#   def children(self) -> List['DumpsysNode']:
#   def find_child(self,
#                  predicate: Callable[['DumpsysNode'], bool],
#                  max_levels: int = 0) -> Optional['DumpsysNode']:
#   def __repr__(self):
#   def print_tree(self, indent: int = 2):
# def build_tree_from_dumpsys_output(dumpsys_output: str) -> DumpsysNode:
# def matches_path(dumpsys_activity_output: str,
#                  expected_view_hierarchy_path: Sequence[Pattern[str]],
#                  max_levels: int = 0) -> bool:
#     def regex_predicate(node, expr=regex):
#   def __init__(self,
#                adb_controller: adb_control.AdbController,
#                expected_app_screen: task_pb2.AppScreen):
#   def matches_current_app_screen(self) -> enum.IntEnum:
#     SUCCESS = 0
#     EMPTY_EXPECTED_ACTIVITY = 1
#     FAILED_ACTIVITY_EXTRACTION = 2
#     UNEXPECTED_ACTIVITY = 3
#     UNEXPECTED_VIEW_HIERARCHY = 4


# Path: android_env/components/app_screen_checker_test.py
import re
from typing import Sequence
from absl.testing import absltest
from android_env.components import app_screen_checker

TASK
  ACTIVITY
    Some node we don't care
      Blah

    View Hierarchy
      Hirohito
        Akihito
          Naruhito
            Aiko
          Fumihito
            Mako
            Kako
            Hisahito
        Masahito
"""
    expected_path = ['^Hirohito$', 'Akihito$', 'Fumihito$', 'Kako$']
    expected_view_hierarchy_path = [
        re.compile(regex) for regex in expected_path
    ]
    self.assertTrue(
        app_screen_checker.matches_path(
            dumpsys_output, expected_view_hierarchy_path, max_levels=2))

    # Also check that the following path does not match anything in the tree.
    expected_path = ['^Hirohito$', 'Akihito$', 'Fumihito$', 'Kenji$']
    expected_view_hierarchy_path = [
        re.compile(regex) for regex in expected_path
    ]
    self.assertFalse(

        app_screen_checker.matches_path(dumpsys_output,