# Path: pontoon/command.py
# class Command:
#     """
#     Base class for CLI commands.
# 
#     Parses docstrings and initalizes client.
#     """
# 
#     def run(self, override=None):
#         """Run the command specified by the docstring.
# 
#         :param override: Run a command other than the one specified.
#         """
# 
#         if override is None:
#             command = next(
#                 (k for k, v in self.args.items()
#                     if k in dir(self) and v), None)
#         else:
#             command = override
# 
#         try:
#             method = getattr(self, command)
#         except KeyError:
#             ui.message("No command '%s'" % command)
#             return 1
#         try:
#             return method()
#         except (KeyboardInterrupt, EOFError):
#             return 0
#         return 1
# 
# Path: pontoon/ui.py
# def ordered_dump(data, stream=None, Dumper=yaml.Dumper, **kwds):
#     def _dict_representer(dumper, data):
# def ticker():
# def ask_yesno(question):
# def ask(question):
# def valid_path(path):
# def full_path(path):
# def filename_from_path(path):
# def machine():
# def mask(text, masker='*'):
# def format_droplet_info(machine):
# def format_event(action):
# def format_item(item):
# def message(text):
# def yaml_message(data):
# def heading(text, boxwidth=60):
# def notify(text, boxwidth=60):
# def warning(text, boxwidth=60):
# def line(length=60, decor='-'):
# def box(text, decor='*', decor_x=None, decor_y=None,
#         boxwidth=60, borderwidth=2):
#     class OrderedDumper(Dumper):
# 
# Path: pontoon/configure.py
# def logger():
# def ssh_tools():
# def regenerate_public_key(private_key, public_key):
# def rsa_keygen(private_key):
# def combined():
# def register_key(credentials, name, public_key):
# def images(credentials):
# def sizes(credentials):
# def regions(credentials):
# def read_key(path):
# def create_config(data):
# def read_config():
# 
# Path: pontoon/mocking.py
# def _raise(ex=None):
#     """Wrapper for exceptions so they can be thrown from inside lambdas"""
#     exception = []
#     if ex:
#         exception.append(ex)
#     if len(exception):
#         raise exception.pop()
# 
# @contextlib.contextmanager
# def capture_stdout():
#     """Captures STDOUT and turns it into an object"""
#     old = sys.stdout
#     capturer = StringIO()
#     sys.stdout = capturer
#     data = Data()
#     yield data
#     sys.stdout = old
#     data.result = capturer.getvalue()
# 
# def event_response():
#     return {
#         'event_id': randrange(9999),
#         'status': 'OK',
#     }
# 
# def get_builtins():
#     """Python 2.x and 3.x have different names for accessing builtins"""
#     try:
#         __import__('builtins')
#         return 'builtins'
#     except ImportError:
#         return '__builtin__'


import sys
import os
import io
import pytest
from subprocess import CalledProcessError
from pytest import raises
from mock import MagicMock, patch
from docopt import docopt
from docopt import DocoptExit
from pontoon.command import Command
from pontoon import ui
from pontoon import configure
from pontoon.mocking import (_raise, capture_stdout, event_response,
                             get_builtins)

_Popen = MagicMock(name='Popen')


_open = MagicMock(name='open')


_getuid = MagicMock(name='getuid')
_getuid.return_value = 1

_fake_config = {
            'api_token': 'foobar',
            'auth_key': '~/.ssh/foo',
            'auth_key_name': 'foo'}

@patch('pontoon.ui.sleep', _sleep)
@patch('pontoon.ui.user_input', _input)
class TestUI:

    thisfile = os.path.realpath(__file__)

    def test_ticker(self):
        with capture_stdout() as capture:
            ui.ticker()
        assert capture.result == ""

    def test_ask_yesno(self):
        _input.return_value = "y"
        assert ui.ask_yesno("Foo?") is True
        _input.return_value = "n"

# Path: pontoon/command.py
# class Command:
#     """
#     Base class for CLI commands.
# 
#     Parses docstrings and initalizes client.
#     """
# 
#     def run(self, override=None):
#         """Run the command specified by the docstring.
# 
#         :param override: Run a command other than the one specified.
#         """
# 
#         if override is None:
#             command = next(
#                 (k for k, v in self.args.items()
#                     if k in dir(self) and v), None)
#         else:
#             command = override
# 
#         try:
#             method = getattr(self, command)
#         except KeyError:
#             ui.message("No command '%s'" % command)
#             return 1
#         try:
#             return method()
#         except (KeyboardInterrupt, EOFError):
#             return 0
#         return 1
# 
# Path: pontoon/ui.py
# def ordered_dump(data, stream=None, Dumper=yaml.Dumper, **kwds):
#     def _dict_representer(dumper, data):
# def ticker():
# def ask_yesno(question):
# def ask(question):
# def valid_path(path):
# def full_path(path):
# def filename_from_path(path):
# def machine():
# def mask(text, masker='*'):
# def format_droplet_info(machine):
# def format_event(action):
# def format_item(item):
# def message(text):
# def yaml_message(data):
# def heading(text, boxwidth=60):
# def notify(text, boxwidth=60):
# def warning(text, boxwidth=60):
# def line(length=60, decor='-'):
# def box(text, decor='*', decor_x=None, decor_y=None,
#         boxwidth=60, borderwidth=2):
#     class OrderedDumper(Dumper):
# 
# Path: pontoon/configure.py
# def logger():
# def ssh_tools():
# def regenerate_public_key(private_key, public_key):
# def rsa_keygen(private_key):
# def combined():
# def register_key(credentials, name, public_key):
# def images(credentials):
# def sizes(credentials):
# def regions(credentials):
# def read_key(path):
# def create_config(data):
# def read_config():
# 
# Path: pontoon/mocking.py
# def _raise(ex=None):
#     """Wrapper for exceptions so they can be thrown from inside lambdas"""
#     exception = []
#     if ex:
#         exception.append(ex)
#     if len(exception):
#         raise exception.pop()
# 
# @contextlib.contextmanager
# def capture_stdout():
#     """Captures STDOUT and turns it into an object"""
#     old = sys.stdout
#     capturer = StringIO()
#     sys.stdout = capturer
#     data = Data()
#     yield data
#     sys.stdout = old
#     data.result = capturer.getvalue()
# 
# def event_response():
#     return {
#         'event_id': randrange(9999),
#         'status': 'OK',
#     }
# 
# def get_builtins():
#     """Python 2.x and 3.x have different names for accessing builtins"""
#     try:
#         __import__('builtins')
#         return 'builtins'
#     except ImportError:
#         return '__builtin__'


# Path: test/test_models.py
import sys
import os
import io
import pytest
from subprocess import CalledProcessError
from pytest import raises
from mock import MagicMock, patch
from docopt import docopt
from docopt import DocoptExit
from pontoon.command import Command
from pontoon import ui
from pontoon import configure
from pontoon.mocking import (_raise, capture_stdout, event_response,
                             get_builtins)


_Popen = MagicMock(name='Popen')


_open = MagicMock(name='open')


_getuid = MagicMock(name='getuid')
_getuid.return_value = 1

_fake_config = {
            'api_token': 'foobar',
            'auth_key': '~/.ssh/foo',
            'auth_key_name': 'foo'}

@patch('pontoon.ui.sleep', _sleep)
@patch('pontoon.ui.user_input', _input)
class TestUI:

    thisfile = os.path.realpath(__file__)

    def test_ticker(self):
        with capture_stdout() as capture:
            ui.ticker()
        assert capture.result == ""

    def test_ask_yesno(self):
        _input.return_value = "y"
        assert ui.ask_yesno("Foo?") is True
        _input.return_value = "n"

        assert ui.ask_yesno("Bar?") is False