# Path: _stbt/keyboard.py
# def _keys_to_press(G, source, targets):
#     from networkx import shortest_path
# 
#     paths = sorted(
#         [shortest_path(G, source=source, target=t, weight="weight")
#          for t in targets],
#         key=len)
#     path = paths[0]
#     # shortest_path(G, "A", "V") -> ["A", "H", "O", "V"]
#     # shortest_path(G, "A", "A") -> ["A"]
#     if len(path) == 1:
#         return
#     for s, t in zip(path[:-1], path[1:]):
#         key = G[s][t]["key"]
#         possible_targets = set(tt for _, tt, kk in G.edges(s, data="key")
#                                if kk == key)
#         yield key, possible_targets
# 
#         # If there are multiple edges from this node with the same key, we
#         # don't know which one we will *actually* end up on. So don't do
#         # any further blind keypresses; let the caller re-calculate and call
#         # us again.
#         if len(possible_targets) > 1:
#             break
# 
# def _strip_shift_transitions(G):
#     from networkx import DiGraph
# 
#     G_ = DiGraph()
#     for node in G.nodes():
#         G_.add_node(node)
#     for u, v, data in G.edges(data=True):
#         if data["key"] == "KEY_OK" and u.text:
#             continue
#         G_.add_edge(u, v, **data)
#     return G_
# 
# Path: _stbt/transition.py
# class _TransitionResult():
#     def __init__(self, key, frame, status, press_time, animation_start_time,
#                  end_time):
#         self.key = key
#         self.frame = frame
#         self.status = status
#         self.press_time = press_time
#         self.animation_start_time = animation_start_time
#         self.end_time = end_time
# 
#     def __repr__(self):
#         return (
#             "_TransitionResult(key=%r, frame=<Frame>, status=%s, "
#             "press_time=%s, animation_start_time=%s, end_time=%s)" % (
#                 self.key,
#                 self.status,
#                 self.press_time,
#                 self.animation_start_time,
#                 self.end_time))
# 
#     def __str__(self):
#         # Also lists the properties -- it's useful to see them in the logs.
#         return (
#             "_TransitionResult(key=%r, frame=<Frame>, status=%s, "
#             "press_time=%s, animation_start_time=%s, end_time=%s, duration=%s, "
#             "animation_duration=%s)" % (
#                 self.key,
#                 self.status,
#                 self.press_time,
#                 self.animation_start_time,
#                 self.end_time,
#                 self.duration,
#                 self.animation_duration))
# 
#     def __bool__(self):
#         return self.status == TransitionStatus.COMPLETE
# 
#     @property
#     def duration(self):
#         if self.end_time is None or self.press_time is None:
#             return None
#         return self.end_time - self.press_time
# 
#     @property
#     def animation_duration(self):
#         if self.end_time is None or self.animation_start_time is None:
#             return None
#         return self.end_time - self.animation_start_time
# 
# class TransitionStatus(enum.Enum):
# 
#     #: The transition didn't start (nothing moved).
#     START_TIMEOUT = 0
# 
#     #: The transition didn't end (movement didn't stop).
#     STABLE_TIMEOUT = 1
# 
#     #: The transition started and then stopped.
#     COMPLETE = 2


import logging
import re
import networkx as nx
import numpy
import pytest
    import mock  # Python 2 backport
import stbt_core as stbt
    from unittest import mock
from _stbt.keyboard import _keys_to_press, _strip_shift_transitions
from _stbt.transition import _TransitionResult, TransitionStatus
                # x:   012345
                # x%2: 010101
                if self.x % 2 == 0:
                    self.x -= 2
                else:
                    self.x -= 1
            else:
                self.x -= 1
        elif keypress == "KEY_RIGHT":
            if self.x == 5 or (self.x == 4 and self.y in [0, 7]):
                assert False, "Unexpected %s on %r" % (keypress, selected)
            elif self.y in [0, 7]:
                # x:   012345
                # x%2: 010101
                if self.x % 2 == 0:
                    self.x += 2
                else:
                    self.x += 1
            else:
                self.x += 1
        else:
            assert False, "Unexpected %s on %r" % (keypress, selected)
        logging.debug("DUT.handle_press: Moved from %r (%s) to %r (%s)",
                      selected, mode, self.selection, self.mode)

    def handle_press_and_wait(self, key, **_kwargs):
        self.handle_press(key)
        return _TransitionResult(key, None, TransitionStatus.COMPLETE, 0, 0, 0)

    def handle_wait_for_transition_to_end(self, *_args, **_kwargs):

# Path: _stbt/keyboard.py
# def _keys_to_press(G, source, targets):
#     from networkx import shortest_path
# 
#     paths = sorted(
#         [shortest_path(G, source=source, target=t, weight="weight")
#          for t in targets],
#         key=len)
#     path = paths[0]
#     # shortest_path(G, "A", "V") -> ["A", "H", "O", "V"]
#     # shortest_path(G, "A", "A") -> ["A"]
#     if len(path) == 1:
#         return
#     for s, t in zip(path[:-1], path[1:]):
#         key = G[s][t]["key"]
#         possible_targets = set(tt for _, tt, kk in G.edges(s, data="key")
#                                if kk == key)
#         yield key, possible_targets
# 
#         # If there are multiple edges from this node with the same key, we
#         # don't know which one we will *actually* end up on. So don't do
#         # any further blind keypresses; let the caller re-calculate and call
#         # us again.
#         if len(possible_targets) > 1:
#             break
# 
# def _strip_shift_transitions(G):
#     from networkx import DiGraph
# 
#     G_ = DiGraph()
#     for node in G.nodes():
#         G_.add_node(node)
#     for u, v, data in G.edges(data=True):
#         if data["key"] == "KEY_OK" and u.text:
#             continue
#         G_.add_edge(u, v, **data)
#     return G_
# 
# Path: _stbt/transition.py
# class _TransitionResult():
#     def __init__(self, key, frame, status, press_time, animation_start_time,
#                  end_time):
#         self.key = key
#         self.frame = frame
#         self.status = status
#         self.press_time = press_time
#         self.animation_start_time = animation_start_time
#         self.end_time = end_time
# 
#     def __repr__(self):
#         return (
#             "_TransitionResult(key=%r, frame=<Frame>, status=%s, "
#             "press_time=%s, animation_start_time=%s, end_time=%s)" % (
#                 self.key,
#                 self.status,
#                 self.press_time,
#                 self.animation_start_time,
#                 self.end_time))
# 
#     def __str__(self):
#         # Also lists the properties -- it's useful to see them in the logs.
#         return (
#             "_TransitionResult(key=%r, frame=<Frame>, status=%s, "
#             "press_time=%s, animation_start_time=%s, end_time=%s, duration=%s, "
#             "animation_duration=%s)" % (
#                 self.key,
#                 self.status,
#                 self.press_time,
#                 self.animation_start_time,
#                 self.end_time,
#                 self.duration,
#                 self.animation_duration))
# 
#     def __bool__(self):
#         return self.status == TransitionStatus.COMPLETE
# 
#     @property
#     def duration(self):
#         if self.end_time is None or self.press_time is None:
#             return None
#         return self.end_time - self.press_time
# 
#     @property
#     def animation_duration(self):
#         if self.end_time is None or self.animation_start_time is None:
#             return None
#         return self.end_time - self.animation_start_time
# 
# class TransitionStatus(enum.Enum):
# 
#     #: The transition didn't start (nothing moved).
#     START_TIMEOUT = 0
# 
#     #: The transition didn't end (movement didn't stop).
#     STABLE_TIMEOUT = 1
# 
#     #: The transition started and then stopped.
#     COMPLETE = 2


# Path: tests/test_keyboard.py
import logging
import re
import networkx as nx
import numpy
import pytest
    import mock  # Python 2 backport
import stbt_core as stbt
    from unittest import mock
from _stbt.keyboard import _keys_to_press, _strip_shift_transitions
from _stbt.transition import _TransitionResult, TransitionStatus

                # x:   012345
                # x%2: 010101
                if self.x % 2 == 0:
                    self.x -= 2
                else:
                    self.x -= 1
            else:
                self.x -= 1
        elif keypress == "KEY_RIGHT":
            if self.x == 5 or (self.x == 4 and self.y in [0, 7]):
                assert False, "Unexpected %s on %r" % (keypress, selected)
            elif self.y in [0, 7]:
                # x:   012345
                # x%2: 010101
                if self.x % 2 == 0:
                    self.x += 2
                else:
                    self.x += 1
            else:
                self.x += 1
        else:
            assert False, "Unexpected %s on %r" % (keypress, selected)
        logging.debug("DUT.handle_press: Moved from %r (%s) to %r (%s)",
                      selected, mode, self.selection, self.mode)

    def handle_press_and_wait(self, key, **_kwargs):
        self.handle_press(key)
        return _TransitionResult(key, None, TransitionStatus.COMPLETE, 0, 0, 0)

    def handle_wait_for_transition_to_end(self, *_args, **_kwargs):

        return _TransitionResult(None, None, TransitionStatus.COMPLETE, 0, 0, 0)