예제 #1
0
def test_outlets_collection():
    with pytest.raises(OutletsException):
        ol_collection = Outlets(
            [Outlet(1, 'MyServer#1', 'OFF'),
             Outlet(1, 'MyServer#1', 'ON')])

    ol_collection = Outlets([
        Outlet(1, 'MyServer#1', 'OFF'),
        Outlet(2, 'MyServer#2', 'ON'),
        Outlet(3, 'MyServer#3', 'OFF*'),
        Outlet(4, 'MyServer#4', 'ON*'),
        Outlet(5, 'MyServer#5', 'OFF'),
        Outlet(6, 'MyServer#6', 'ON'),
        Outlet(7, 'MyServer#7', 'OFF*'),
        Outlet(8, 'MyServer#8', 'ON*'),
    ])
    assert str(ol_collection) == """Outlet 1 MyServer#1      OFF
Outlet 2 MyServer#2      ON
Outlet 3 MyServer#3      OFF*
Outlet 4 MyServer#4      ON*
Outlet 5 MyServer#5      OFF
Outlet 6 MyServer#6      ON
Outlet 7 MyServer#7      OFF*
Outlet 8 MyServer#8      ON*"""

    ol = ol_collection[4]
    assert ol.id == 4
    assert ol.name == 'MyServer#4'
    assert str(ol.status) == 'ON*'

    assert len(ol_collection) == 8

    for i, ol in enumerate(ol_collection, 1):
        assert ol.id == i
예제 #2
0
파일: utility.py 프로젝트: Legodev/APC
 def status(self):
     self.sendnl('1')
     self.sendnl('2')
     self.sendnl('1')
     self.child.expect("-+ Outlet Control/Configuration -+")
     self.child.expect("<ESC>")
     s = self.child.before
     s = s.decode("utf-8")  # b'' -> string
     s = s.strip()
     rows = s.split("\n")
     lst_outlets = []
     for row in rows[:-1]:
         ol = Outlet.parse(row.strip())
         lst_outlets.append(ol)
     ol_collection = Outlets(lst_outlets)
     return ol_collection
예제 #3
0
파일: utility.py 프로젝트: zskdan/APC
 def status(self):
     self.sendnl('1')
     self.sendnl('9')
     self.sendnl('2')
     self.child.expect("Configuration of MasterSwitch")
     self.child.expect("<ESC>")
     s = self.child.before
     s = s.decode("utf-8")  # b'' -> string
     s = s.strip()
     rows = s.split("\n")
     lst_outlets = []
     for row in rows[:-1]:
         row = row.strip()[3:]
         ol = Outlet.parse(row)
         lst_outlets.append(ol)
     ol_collection = Outlets(lst_outlets)
     return ol_collection