flimflam-test: Fix last pylint errors

Mark a bunch of method parameters as unused to pass static checks.
Properly throw NotImplementedErrors for abstract methods, and redefine
the abstract method for the static checker.

I've disabled the checks for whether the unary '=' has spaces around it
so that these default parameters don't fail.  Apparently in this area,
pylint differs from PEP8.

TEST=No Pylint errors
BUG=chromium-os:38166

Change-Id: Ia6cfb95a223912b586689559928fc00eb319b1da
Reviewed-on: https://gerrit.chromium.org/gerrit/42348
Reviewed-by: Thieu Le <thieule@chromium.org>
Commit-Queue: Christopher Wiley <wiley@chromium.org>
Tested-by: Christopher Wiley <wiley@chromium.org>
diff --git a/test/fake-cromo b/test/fake-cromo
index fc648a1..1ab61ae 100644
--- a/test/fake-cromo
+++ b/test/fake-cromo
@@ -68,14 +68,14 @@
 
     @dbus.service.method('org.chromium.ModemManager.Carrier',
                          in_signature = '', out_signature = '')
-    def ProcessPayment(self, *args, **kwargs):
+    def ProcessPayment(self, *_args, **_kwargs):
         print "CarrierState: ProcessPayment"
         self.payment_made = True
         self.restricted = False
 
     @dbus.service.method('org.chromium.ModemManager.Carrier',
                          in_signature = '', out_signature = '')
-    def ConsumePlan(self, *args, **kwargs):
+    def ConsumePlan(self, *_args, **_kwargs):
         print "CarrierState: ConsumePlan"
         self.payment_made = False
         self.restricted = True
@@ -88,14 +88,14 @@
                        mdn='0000001234',
                        activation_state=Modem.NOT_ACTIVATED)
 
-    def Activate(self, s, *args, **kwargs):
+    def Activate(self, s, *_args, **_kwargs):
         print 'FactoryResetModem: Activate "%s"' % s
         self.StartActivation(Modem.PARTIALLY_ACTIVATED,
                              self.manager.MakePartiallyActivatedModem,
                              '0015551212')
 
     # Implement connect as a failure
-    def Connect(self, props, *args, **kwargs):
+    def Connect(self, _props, *_args, **_kwargs):
         print 'FactoryResetModem: Connect'
         time.sleep(self.manager.options.connect_delay_ms / 1000.0)
         self.state = flimflam_test.STATE_CONNECTING
@@ -105,6 +105,9 @@
                          flimflam_test.REASON_USER_REQUESTED))
         raise flimflam_test.ConnectError()
 
+    def ActivateImpl(self, _s, _args, _kwargs):
+        raise NotImplementedError('Unimplemented.  Must implement in subclass.')
+
 
 class PartiallyActivatedModem(Modem):
 
@@ -113,7 +116,7 @@
                        mdn='0015551212',
                        activation_state=Modem.PARTIALLY_ACTIVATED)
 
-    def Activate(self, s, *args, **kwargs):
+    def Activate(self, s, *_args, **_kwargs):
         print 'Partially_ActivatedModem: Activate "%s"' % s
         carrier = self.manager.carrier
         if self.manager.options.activatable and carrier.payment_made:
@@ -131,7 +134,10 @@
             restrictor.enter()
         else:
             restrictor.leave()
-        super(PartiallyActivatedModem, self).ConnectDone(old, new, why)
+        Modem.ConnectDone(self, old, new, why)
+
+    def ActivateImpl(self, _s, _args, _kwargs):
+        raise NotImplementedError('Unimplemented.  Must implement in subclass.')
 
 
 class ActivatedModem(Modem):
@@ -147,7 +153,7 @@
             restrictor.enter()
         else:
             restrictor.leave()
-        super(ActivatedModem, self).ConnectDone(old, new, why)
+        Modem.ConnectDone(self, old, new, why)
 
     def Connect(self, props, *args, **kwargs):
         print 'ActivatedModem: Connect'
@@ -155,6 +161,9 @@
             self.manager.options.connect_delay_ms)
         Modem.Connect(self, props, *args, **kwargs)
 
+    def ActivateImpl(self, _s, _args, _kwargs):
+        raise NotImplementedError('Unimplemented.  Must implement in subclass.')
+
 
 class BrokenActivatedModem(Modem):
     """ BrokenActivatedModem is a modem that although activated always
@@ -167,7 +176,7 @@
                        activation_state=Modem.ACTIVATED)
 
     # Implement connect by always failing
-    def Connect(self, props, *args, **kwargs):
+    def Connect(self, _props, *_args, **_kwargs):
         print 'BrokenActivatedModem: Connect'
         time.sleep(self.manager.options.connect_delay_ms / 1000.0)
         self.state = flimflam_test.STATE_CONNECTING
@@ -177,6 +186,9 @@
                          flimflam_test.REASON_USER_REQUESTED))
         raise flimflam_test.ConnectError()
 
+    def ActivateImpl(self, _s, _args, _kwargs):
+        raise NotImplementedError('Unimplemented.  Must implement in subclass.')
+
 
 class Manager(ModemManager):
     def __init__(self, bus, options):
diff --git a/test/flimflam_test.py b/test/flimflam_test.py
index ca6c87b..7e436bf 100644
--- a/test/flimflam_test.py
+++ b/test/flimflam_test.py
@@ -4,8 +4,6 @@
 
 import datetime
 import gobject
-import os
-import sys
 import time
 
 import dbus
@@ -61,13 +59,11 @@
 class OperationInitiated(DBusException):
     _dbus_error_name = 'org.chromium.ModemManager.Error.OperationInitiated'
     include_traceback = False
-    pass
 
 
 class ConnectError(DBusException):
     _dbus_error_name = 'org.chromium.ModemManager.Error.ConnectError'
     include_traceback = False
-    pass
 
 
 class SIM(object):
@@ -149,6 +145,11 @@
         self.device = device
         dbus.service.Object.__init__(self, manager.bus, self.path)
         self.manager.add(self)
+        self._default_signal_quality = UInt32(100)
+        self._band_class = UInt32(2)
+        self._band = 'F'
+        self._system_id = UInt32(2004)
+        self._modem_info = ('Initech', 'Modemtron 1.00', '0.42')
 
     def DiscardModem(self):
         """
@@ -162,7 +163,7 @@
         self.manager.remove(self)
 
     @dbus.service.method(OFDP, in_signature='s', out_signature='a{sv}')
-    def GetAll(self, iface, *args, **kwargs):
+    def GetAll(self, iface, *_args, **_kwargs):
         TimestampLog('Modem: GetAll %s' % iface)
         properties = {}
         if (iface == MM + '.Modem' or
@@ -184,7 +185,7 @@
         return self.GetAll(iface)[propname]
 
     @dbus.service.method(MM + '.Modem', in_signature='b', out_signature='')
-    def Enable(self, on, *args, **kwargs):
+    def Enable(self, on, *_args, **_kwargs):
         TimestampLog('Modem: Enable %s' % str(on))
         if on:
             self.state = STATE_ENABLED
@@ -205,7 +206,7 @@
 
     @dbus.service.method(MM + '.Modem.Simple', in_signature='',
                          out_signature='a{sv}')
-    def GetStatus(self, *args, **kwargs):
+    def GetStatus(self, *_args, **_kwargs):
         TimestampLog('Modem: GetStatus')
         a = { 'state': UInt32(self.state),
               'activation_state': self.activation_state,
@@ -233,7 +234,7 @@
 
     @dbus.service.method(MM + '.Modem.Simple', in_signature='a{sv}',
                          out_signature='')
-    def Connect(self, props, *args, **kwargs):
+    def Connect(self, _props, *_args, **kwargs):
         TimestampLog('Modem: Connect')
         if self.state != STATE_REGISTERED:
             raise ConnectError()
@@ -246,7 +247,7 @@
                                  REASON_USER_REQUESTED))
 
     @dbus.service.method(MM + '.Modem')
-    def Disconnect(self, *args, **kwargs):
+    def Disconnect(self, *_args, **_kwargs):
         TimestampLog('Modem: Disconnect')
         self.state = STATE_DISCONNECTING
         glib.timeout_add(500,
@@ -259,7 +260,7 @@
     def ActivationStateChanged(self, state, error, status_changes):
         pass
 
-    def ActivateDone(self, new_activation_state, new_modem_factory, new_mdn,
+    def ActivateDone(self, new_activation_state, new_modem_factory, _new_mdn,
                      discard_modem_delay_ms=DISCARD_MODEM_DELAY_MS,
                      reboot_delay_ms=REBOOT_DELAY_MS):
         TimestampLog('Modem: ActivateDone: _state = %d' % new_activation_state)
@@ -273,7 +274,13 @@
     @dbus.service.method(MM + '.Modem.Cdma', in_signature='s',
                          out_signature='')
     def Activate(self, s, *args, **kwargs):
-        raise 'Unimplemented.  Must implement in subclass.'
+        # It isn't entirely clear to me how inheritence works in combination
+        # with dbus method decorator magic, so lets just delegate to an impl
+        # stub that subclasses can override if they like.
+        self.ActivateImpl(s, args, kwargs)
+
+    def ActivateImpl(self, _s, _args, _kwargs):
+        raise NotImplementedError('Unimplemented.  Must implement in subclass.')
 
     def StartActivation(self, new_activation_state, factory, new_mdn):
         self.activation_state = self.ACTIVATING
@@ -301,7 +308,7 @@
 
     @dbus.service.method(MM + '.Modem.Cdma', in_signature='',
                          out_signature='uu')
-    def GetRegistrationState(self, *args, **kwargs):
+    def GetRegistrationState(self, *_args, **_kwargs):
         TimestampLog('Modem: GetRegistrationState')
         if self.state >= STATE_REGISTERED:
             cdma_1x_state = UInt32(2)
@@ -313,30 +320,27 @@
 
     @dbus.service.method(MM + '.Modem.Cdma', in_signature='',
                          out_signature='u')
-    def GetSignalQuality(self, *args, **kwargs):
+    def GetSignalQuality(self, *_args, **_kwargs):
         TimestampLog('Modem: GetSignalQuality')
-        return UInt32(100)
+        return self._default_signal_quality
 
     @dbus.service.method(MM + '.Modem.Cdma', in_signature='',
                          out_signature='(usu)')
-    def GetServingSystem(self, *args, **kwargs):
+    def GetServingSystem(self, *_args, **_kwargs):
         TimestampLog('Modem: GetServingSystem')
-        band_class = UInt32(2)
-        band = 'F'
-        system_id = UInt32(2004)
-        return (band_class, band, system_id)
+        return (self._band_class, self._band, self._system_id)
 
     @dbus.service.method(MM + '.Modem.Cdma', in_signature='',
                          out_signature='s')
-    def GetEsn(self, *args, **kwargs):
+    def GetEsn(self, *_args, **_kwargs):
         TimestampLog('Modem: GetEsn')
         return self.esn
 
     @dbus.service.method(MM + '.Modem', in_signature='',
                          out_signature='(sss)')
-    def GetInfo(self, *args, **kwargs):
+    def GetInfo(self, *_args, **_kwargs):
         TimestampLog('Modem: GetInfo')
-        return ('Initech', 'Modemtron 1.00', '0.42')
+        return self._modem_info
 
 
 class GSM_Modem(Modem):
@@ -349,6 +353,7 @@
         Modem.__init__(self, *args, **kwargs)
         self.gsm_sim = gsm_sim
         self.smses = smses
+        self._imei = '490154203237518'
 
     @dbus.service.method(OFDP, in_signature='s', out_signature='a{sv}')
     def GetAll(self, iface, *args, **kwargs):
@@ -364,20 +369,20 @@
                 'EnabledFacilityLocks' : UInt32(0)
             }
         else:
-            properties = super(GSM_Modem, self).GetAll(iface, args, kwargs)
+            properties = Modem.GetAll(self, iface, args, kwargs)
 
         return properties
 
 
     @dbus.service.method(MM + '.Modem.Gsm.Card', in_signature='',
                          out_signature='s')
-    def GetImei(self, *args, **kwargs):
+    def GetImei(self, *_args, **_kwargs):
         TimestampLog('Gsm: GetImei')
-        return '490154203237518'
+        return self._imei
 
     @dbus.service.method(MM + '.Modem.Gsm.Card', in_signature='',
                          out_signature='s')
-    def GetImsi(self, *args, **kwargs):
+    def GetImsi(self, *_args, **_kwargs):
         TimestampLog('Gsm: GetImsi')
         return self.gsm_sim.mcc + self.gsm_sim.mnc + self.gsm_sim.msin
 
@@ -401,13 +406,13 @@
 
     @dbus.service.method(MM + '.Modem.Gsm.Network', in_signature='',
                          out_signature='u')
-    def GetSignalQuality(self, *args, **kwargs):
+    def GetSignalQuality(self, *_args, **_kwargs):
         TimestampLog('Network: GetSignalQuality')
         return 100.0
 
     @dbus.service.method(MM + '.Modem.Gsm.Network', in_signature='',
                          out_signature='(uss)')
-    def GetRegistrationInfo(self, *args, **kwargs):
+    def GetRegistrationInfo(self, *_args, **_kwargs):
         TimestampLog('GSM: GetRegistrationInfo')
         registration_status = GSM_REG_STATUS_HOME
 
@@ -421,19 +426,19 @@
 
     @dbus.service.method(MM + '.Modem.Gsm.SMS', in_signature='',
                          out_signature='aa{sv}')
-    def List(self, *args, **kwargs):
+    def List(self, *_args, **_kwargs):
         TimestampLog('Gsm.SMS: List')
         return self.smses.values()
 
     @dbus.service.method(MM + '.Modem.Gsm.SMS', in_signature='u',
                          out_signature='')
-    def Delete(self, index, *args, **kwargs):
+    def Delete(self, index, *_args, **_kwargs):
         TimestampLog('Gsm.SMS: Delete %s' % index)
         del self.smses[index]
 
     @dbus.service.method(MM + '.Modem.Gsm.SMS', in_signature='u',
                          out_signature='a{sv}')
-    def Get(self, index, *args, **kwargs):
+    def Get(self, index, *_args, **_kwargs):
         TimestampLog('Gsm.SMS: Get %s' % index)
         return self.smses[index]
 
@@ -441,6 +446,8 @@
     def SmsReceived(self, index, complete):
         pass
 
+    def ActivateImpl(self, _s, _args, _kwargs):
+        raise NotImplementedError('Unimplemented.  Must implement in subclass.')
 
 class ModemManager(dbus.service.Object):
     def __init__(self, bus, path):
@@ -461,7 +468,7 @@
 
     @dbus.service.method('org.freedesktop.ModemManager',
                          in_signature='', out_signature='ao')
-    def EnumerateDevices(self, *args, **kwargs):
+    def EnumerateDevices(self, *_args, **_kwargs):
         devices = map(lambda d: d.path, self.devices)
         TimestampLog('EnumerateDevices: %s' % ', '.join(devices))
         return devices
@@ -475,13 +482,17 @@
         pass
 
 
-if __name__ == '__main__':
+def main():
     dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
     bus = dbus.SystemBus()
-    name = dbus.service.BusName(CMM, bus)
+    _ = dbus.service.BusName(CMM, bus)
     manager = ModemManager(bus, OCMM)
-    testmodem0 = Modem(manager, '/TestModem/0')
+    # The Modem constructor registers itself with the manager.
+    Modem(manager, '/TestModem/0')
 
     mainloop = gobject.MainLoop()
     TimestampLog("Running test modemmanager.")
     mainloop.run()
+
+if __name__ == '__main__':
+    main()