# Path: _stbt/power.py
# def uri_to_power_outlet(uri):
#     remotes = [
#         (r'none', _NoOutlet),
#         (r'file:(?P<filename>[^:]+)', _FileOutlet),
#         (r'aten:(?P<address>[^: ]+):(?P<outlet>[^: ]+)', _ATEN_PE6108G),
#         (r'rittal:(?P<address>[^: ]+):(?P<outlet_no>[^: ]+)'
#          ':(?P<community>[^: ]+)', _RittalSnmpPower),
#         (r'(?P<model>pdu|ipp|testfallback):(?P<hostname>[^: ]+)'
#          ':(?P<outlet>[^: ]+)', _ShellOutlet),
#         (r'aviosys-8800-pro(:(?P<filename>[^:]+))?', _new_aviosys_8800_pro),
#     ]
#     for regex, factory in remotes:
#         m = re.match(regex, uri, re.VERBOSE | re.IGNORECASE)
#         if m:
#             return factory(**m.groupdict())
#     raise ConfigurationError('Invalid power outlet URI: "%s"' % uri)


from contextlib import contextmanager
from pysnmp.proto.rfc1902 import Integer
    from unittest.mock import patch
    from mock import patch  # Python 2 backport
from _stbt.power import uri_to_power_outlet
import pytest


outlet = 1
oid = "1.3.6.1.4.1.21317.1.3.2.2.2.2.{0}.0".format(outlet + 1)


def test_aten_get_on():
    with mock_command_gen() as mock_command:
        mock_command.getCmd.return_value = mock_data(2)
        aten = uri_to_power_outlet('aten:mock.host.name:1')

        result = aten.get()

        assert result is True


def test_aten_get_off():
    with mock_command_gen() as mock_command:
        mock_command.getCmd.return_value = mock_data(1)
        aten = uri_to_power_outlet('aten:mock.host.name:1')

        result = aten.get()

        assert result is False


def test_aten_set_on():
    with mock_command_gen() as mock_command:
        mock_command.setCmd.return_value = mock_data(2)
        mock_command.getCmd.side_effect = [mock_data(n) for n in (1, 1, 1, 2)]

# Path: _stbt/power.py
# def uri_to_power_outlet(uri):
#     remotes = [
#         (r'none', _NoOutlet),
#         (r'file:(?P<filename>[^:]+)', _FileOutlet),
#         (r'aten:(?P<address>[^: ]+):(?P<outlet>[^: ]+)', _ATEN_PE6108G),
#         (r'rittal:(?P<address>[^: ]+):(?P<outlet_no>[^: ]+)'
#          ':(?P<community>[^: ]+)', _RittalSnmpPower),
#         (r'(?P<model>pdu|ipp|testfallback):(?P<hostname>[^: ]+)'
#          ':(?P<outlet>[^: ]+)', _ShellOutlet),
#         (r'aviosys-8800-pro(:(?P<filename>[^:]+))?', _new_aviosys_8800_pro),
#     ]
#     for regex, factory in remotes:
#         m = re.match(regex, uri, re.VERBOSE | re.IGNORECASE)
#         if m:
#             return factory(**m.groupdict())
#     raise ConfigurationError('Invalid power outlet URI: "%s"' % uri)


# Path: tests/test_power.py
from contextlib import contextmanager
from pysnmp.proto.rfc1902 import Integer
    from unittest.mock import patch
    from mock import patch  # Python 2 backport
from _stbt.power import uri_to_power_outlet
import pytest



outlet = 1
oid = "1.3.6.1.4.1.21317.1.3.2.2.2.2.{0}.0".format(outlet + 1)


def test_aten_get_on():
    with mock_command_gen() as mock_command:
        mock_command.getCmd.return_value = mock_data(2)
        aten = uri_to_power_outlet('aten:mock.host.name:1')

        result = aten.get()

        assert result is True


def test_aten_get_off():
    with mock_command_gen() as mock_command:
        mock_command.getCmd.return_value = mock_data(1)
        aten = uri_to_power_outlet('aten:mock.host.name:1')

        result = aten.get()

        assert result is False


def test_aten_set_on():
    with mock_command_gen() as mock_command:
        mock_command.setCmd.return_value = mock_data(2)
        mock_command.getCmd.side_effect = [mock_data(n) for n in (1, 1, 1, 2)]

        aten = uri_to_power_outlet('aten:mock.host.name:1')