audio: fix up pylint errors for cmd_utils.py and affected tests

This was split out of a CL that has functionality changes.

TEST=audio_Aplay
BUG=chromium:371230

Change-Id: Id48861e4d06d19901b2bd62b8a2546e67fe106e9
Reviewed-on: https://chromium-review.googlesource.com/537221
Commit-Ready: Adam Goode <agoode@chromium.org>
Tested-by: Adam Goode <agoode@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/client/cros/audio/alsa_utils.py b/client/cros/audio/alsa_utils.py
index d4fd7f3..f1ed61c 100644
--- a/client/cros/audio/alsa_utils.py
+++ b/client/cros/audio/alsa_utils.py
@@ -3,6 +3,7 @@
 # found in the LICENSE file.
 
 import re
+import subprocess
 
 from autotest_lib.client.cros.audio import cmd_utils
 
@@ -72,7 +73,7 @@
     '''
 
     cmd = [AMIXER_PATH, '-c', str(card_id), 'controls']
-    p = cmd_utils.popen(cmd, stdout=cmd_utils.PIPE)
+    p = cmd_utils.popen(cmd, stdout=subprocess.PIPE)
     output, _ = p.communicate()
     if p.wait() != 0:
         raise RuntimeError('amixer command failed')
@@ -105,7 +106,7 @@
     '''
 
     cmd = [AMIXER_PATH, '-c', str(card_id), 'scontrols']
-    p = cmd_utils.popen(cmd, stdout=cmd_utils.PIPE)
+    p = cmd_utils.popen(cmd, stdout=subprocess.PIPE)
     output, _ = p.communicate()
     if p.wait() != 0:
         raise RuntimeError('amixer command failed')
@@ -154,7 +155,7 @@
     '''
     card_name_re = re.compile(r'card %d: .*?\[(.*?)\]' % card_idx)
     cmd = [ARECORD_PATH, '-l']
-    p = cmd_utils.popen(cmd, stdout=cmd_utils.PIPE)
+    p = cmd_utils.popen(cmd, stdout=subprocess.PIPE)
     output, _ = p.communicate()
     if p.wait() != 0:
         raise RuntimeError('arecord -l command failed')
@@ -195,7 +196,7 @@
 
     # Get first device id of this card.
     cmd = [ARECORD_PATH, '-l']
-    p = cmd_utils.popen(cmd, stdout=cmd_utils.PIPE)
+    p = cmd_utils.popen(cmd, stdout=subprocess.PIPE)
     output, _ = p.communicate()
     if p.wait() != 0:
         raise RuntimeError('arecord -l command failed')
@@ -211,7 +212,7 @@
 
 
 def _get_sysdefault(cmd):
-    p = cmd_utils.popen(cmd, stdout=cmd_utils.PIPE)
+    p = cmd_utils.popen(cmd, stdout=subprocess.PIPE)
     output, _ = p.communicate()
     if p.wait() != 0:
         raise RuntimeError('%s failed' % cmd)
@@ -315,7 +316,7 @@
     '''
 
     cmd = [AMIXER_PATH, '-c', str(card_id)] + cmd
-    p = cmd_utils.popen(cmd, stdout=cmd_utils.PIPE)
+    p = cmd_utils.popen(cmd, stdout=subprocess.PIPE)
     output, _ = p.communicate()
     if p.wait() != 0:
         raise RuntimeError('amixer command failed')
diff --git a/client/cros/audio/audio_helper.py b/client/cros/audio/audio_helper.py
index 81ef0b7..3a0a5d3 100644
--- a/client/cros/audio/audio_helper.py
+++ b/client/cros/audio/audio_helper.py
@@ -8,6 +8,7 @@
 import numpy
 import os
 import re
+import subprocess
 import tempfile
 import threading
 import time
@@ -496,10 +497,10 @@
             sox_utils.extract_channel_cmd(
                     input_audio, '-', channel_index,
                     channels=channels, bits=bits, rate=rate),
-            stdout=cmd_utils.PIPE)
+            stdout=subprocess.PIPE)
     p2 = cmd_utils.popen(
             sox_utils.stat_cmd('-', channels=1, bits=bits, rate=rate),
-            stdin=p1.stdout, stderr=cmd_utils.PIPE)
+            stdin=p1.stdout, stderr=subprocess.PIPE)
     stat_output = p2.stderr.read()
     cmd_utils.wait_and_check_returncode(p1, p2)
     return sox_utils.parse_stat_output(stat_output)
@@ -537,7 +538,7 @@
                 sox_utils.noise_profile_cmd(
                         noise_file, '-', channels=channels, bits=bits,
                         rate=rate),
-                stdout=cmd_utils.PIPE)
+                stdout=subprocess.PIPE)
         p2 = cmd_utils.popen(
                 sox_utils.noise_reduce_cmd(
                         input_audio, reduced_file.name, '-',
@@ -590,7 +591,7 @@
     @returns: a string containing diagnostic results.
 
     """
-    return cmd_utils.execute([_AUDIO_DIAGNOSTICS_PATH], stdout=cmd_utils.PIPE)
+    return cmd_utils.execute([_AUDIO_DIAGNOSTICS_PATH], stdout=subprocess.PIPE)
 
 
 def get_max_cross_correlation(signal_a, signal_b):
diff --git a/client/cros/audio/cmd_utils.py b/client/cros/audio/cmd_utils.py
index ee43e2d..7390efc 100644
--- a/client/cros/audio/cmd_utils.py
+++ b/client/cros/audio/cmd_utils.py
@@ -12,7 +12,6 @@
 import subprocess
 import threading
 
-from subprocess import PIPE
 from autotest_lib.client.common_lib.utils import TEE_TO_LOGS
 
 _popen_lock = threading.Lock()
@@ -28,6 +27,7 @@
         self._logger = logger
 
     def fileno(self):
+        """Returns the fileno of the logger pipe."""
         return self._logger._pipe[1]
 
     def __del__(self):
@@ -42,6 +42,7 @@
         self._prefix = prefix
 
     def close(self):
+        """Closes the logger."""
         if self._pipe[1] != _PIPE_CLOSED:
             os.close(self._pipe[1])
             self._pipe[1] = _PIPE_CLOSED
@@ -53,7 +54,7 @@
         # Python's list is thread safe
         self._loggers = []
 
-        # Change tuple  to list so that we can change the value when
+        # Change tuple to list so that we can change the value when
         # closing the pipe.
         self._pipe = list(os.pipe())
         self._thread = threading.Thread(target=self._service_run)
@@ -91,6 +92,11 @@
 
 
     def create_logger(self, level=logging.DEBUG, prefix=''):
+        """Creates a new logger.
+
+        @param level: the desired logging level
+        @param prefix: the prefix to add to each log entry
+        """
         logger = _PipeLogger(level=level, prefix=prefix)
         self._loggers.append(logger)
         os.write(self._pipe[1], '\0')
@@ -98,6 +104,7 @@
 
 
     def shutdown(self):
+        """Shuts down the logger."""
         if self._pipe[1] != _PIPE_CLOSED:
             os.close(self._pipe[1])
             self._pipe[1] = _PIPE_CLOSED
@@ -105,6 +112,11 @@
 
 
 def create_logger(level=logging.DEBUG, prefix=''):
+    """Creates a new logger.
+
+    @param level: the desired logging level
+    @param prefix: the prefix to add to each log entry
+    """
     global _logging_service
     if _logging_service is None:
         _logging_service = _LoggingService()
@@ -113,10 +125,10 @@
 
 
 def kill_or_log_returncode(*popens):
-    '''Kills all the processes of the given Popens or logs the return code.
+    """Kills all the processes of the given Popens or logs the return code.
 
-    @param poopens: The Popens to be killed.
-    '''
+    @param popens: The Popens to be killed.
+    """
     for p in popens:
         if p.poll() is None:
             try:
@@ -129,12 +141,12 @@
 
 
 def wait_and_check_returncode(*popens):
-    '''Wait for all the Popens and check the return code is 0.
+    """Wait for all the Popens and check the return code is 0.
 
     If the return code is not 0, it raises an RuntimeError.
 
     @param popens: The Popens to be checked.
-    '''
+    """
     error_message = None
     for p in popens:
         if p.wait() != 0:
@@ -146,15 +158,16 @@
 
 
 def execute(args, stdin=None, stdout=TEE_TO_LOGS, stderr=TEE_TO_LOGS):
-    '''Executes a child command and wait for it.
+    """Executes a child command and wait for it.
 
     Returns the output from standard output if 'stdout' is subprocess.PIPE.
     Raises RuntimeException if the return code of the child command is not 0.
 
     @param args: the command to be executed
     @param stdin: the executed program's standard input
-    @param stdout: the executed program's stdandrd output
-    '''
+    @param stdout: the executed program's standard output
+    @param stderr: the executed program's standard error
+    """
     ps = popen(args, stdin=stdin, stdout=stdout, stderr=stderr)
     out = ps.communicate()[0] if stdout == subprocess.PIPE else None
     wait_and_check_returncode(ps)
@@ -162,9 +175,15 @@
 
 
 def popen(args, stdin=None, stdout=TEE_TO_LOGS, stderr=TEE_TO_LOGS, env=None):
-    '''Returns a Popen object just as subprocess.Popen does but with the
+    """Returns a Popen object just as subprocess.Popen does but with the
     executed command stored in Popen.command.
-    '''
+
+    @param args: the command to be executed
+    @param stdin: the executed program's standard input
+    @param stdout: the executed program's standard output
+    @param stderr: the executed program's standard error
+    @param env: the executed program's environment
+    """
     command_id = _command_serial_number.next()
     prefix = '[%04d] ' % command_id
 
@@ -179,7 +198,7 @@
     # The lock is required for http://crbug.com/323843.
     with _popen_lock:
         ps = subprocess.Popen(args, stdin=stdin, stdout=stdout, stderr=stderr,
-            env=env)
+                              env=env)
     logging.info('%spid is %d', prefix, ps.pid)
     ps.command_id = command_id
     ps.command = command
diff --git a/client/cros/audio/sox_utils.py b/client/cros/audio/sox_utils.py
index fb0b572..b70230a 100644
--- a/client/cros/audio/sox_utils.py
+++ b/client/cros/audio/sox_utils.py
@@ -4,6 +4,7 @@
 
 import logging
 import re
+import subprocess
 
 from autotest_lib.client.cros.audio import cmd_utils
 
@@ -71,9 +72,9 @@
     return args
 
 
-def noise_profile(*arg, **karg):
+def noise_profile(*args, **kwargs):
     """A helper function to execute the noise_profile_cmd."""
-    return cmd_utils.execute(noise_profile_cmd(*arg, **karg))
+    return cmd_utils.execute(noise_profile_cmd(*args, **kwargs))
 
 
 def noise_profile_cmd(input, output, channels=1, bits=16, rate=48000):
@@ -91,9 +92,9 @@
     return args
 
 
-def noise_reduce(*args, **kargs):
+def noise_reduce(*args, **kwargs):
     """A helper function to execute the noise_reduce_cmd."""
-    return cmd_utils.execute(noise_reduce_cmd(*args, **kargs))
+    return cmd_utils.execute(noise_reduce_cmd(*args, **kwargs))
 
 
 def noise_reduce_cmd(
@@ -101,7 +102,7 @@
     """Reduce noise in the input audio by the given noise profile.
 
     @param input: The input audio file.
-    @param ouput: The output file in which the noise reduced audio is stored.
+    @param output: The output file in which the noise reduced audio is stored.
     @param noise_profile: The noise profile.
     @param channels: The number of channels.
     @param bits: The number of bits of each sample.
@@ -161,7 +162,7 @@
     It returns the statistical information (in text) read from the standard
     error.
     """
-    p = cmd_utils.popen(stat_cmd(*args, **kargs), stderr=cmd_utils.PIPE)
+    p = cmd_utils.popen(stat_cmd(*args, **kargs), stderr=subprocess.PIPE)
 
     #The output is read from the stderr instead of stdout
     stat_output = p.stderr.read()
diff --git a/client/site_tests/audio_CRASFormatConversion/audio_CRASFormatConversion.py b/client/site_tests/audio_CRASFormatConversion/audio_CRASFormatConversion.py
index cc62f91..3ce45c3 100755
--- a/client/site_tests/audio_CRASFormatConversion/audio_CRASFormatConversion.py
+++ b/client/site_tests/audio_CRASFormatConversion/audio_CRASFormatConversion.py
@@ -4,8 +4,8 @@
 
 import logging
 import os
+import subprocess
 import tempfile
-import time
 
 from autotest_lib.client.bin import utils
 from autotest_lib.client.common_lib import error
@@ -19,19 +19,21 @@
 _TEST_TONE_TWO = 523
 
 class audio_CRASFormatConversion(audio_helper.cras_rms_test):
+    """Checks that sample rate conversion works in CRAS."""
+
     version = 1
 
 
-    def play_sine_tone(self, frequence, rate):
+    def play_sine_tone(self, frequency, rate):
         """Plays a sine tone by cras and returns the processes.
-        Args:
-            frequence: the frequence of the sine wave.
-            rate: the sampling rate.
+
+        @param frequency: the frequency of the sine wave.
+        @param rate: the sampling rate.
         """
         p1 = cmd_utils.popen(
             sox_utils.generate_sine_tone_cmd(
-                    filename='-', rate=rate, frequencies=frequence, gain=-6),
-            stdout=cmd_utils.PIPE)
+                    filename='-', rate=rate, frequencies=frequency, gain=-6),
+            stdout=subprocess.PIPE)
         p2 = cmd_utils.popen(
             cras_utils.playback_cmd(playback_file='-', rate=rate),
             stdin=p1.stdout)
@@ -39,6 +41,15 @@
 
 
     def wait_for_active_stream_count(self, expected_count):
+        """Waits until the number of active streams matches the requested
+        number or until a timeout occurs.
+
+        @param expected_count: the exact number of streams required to
+                               be active for execution to continue.
+
+        @raise TestError: if a timeout occurs.
+        """
+
         utils.poll_for_condition(
                 lambda: cras_utils.get_active_stream_count() == expected_count,
                 exception=error.TestError(