[autotest] suppress ImportError on gviz_api and matplotlib

Suppressing these ImportErrors allows unit tests to run inside the
chroot without needing to install gviz_api and matplotlib in the chroot
(both of which do not have a readily-installable portage ebuild).

BUG=chromium:221254
TEST=autotest_lib.frontend.afe.resources_test passes inside the chroot,
after removing all build external packages from autotest repo (using
`git clean -fxd` -- use with caution)

Change-Id: I65aaedb82f5ebed4b7c23f28f2ccc2dd0e574e8d
Reviewed-on: https://gerrit.chromium.org/gerrit/59619
Tested-by: Aviv Keshet <akeshet@chromium.org>
Reviewed-by: Alex Miller <milleral@chromium.org>
Commit-Queue: Aviv Keshet <akeshet@chromium.org>
diff --git a/frontend/croschart/labtest/models.py b/frontend/croschart/labtest/models.py
index 1baea21..e0d8aae 100644
--- a/frontend/croschart/labtest/models.py
+++ b/frontend/croschart/labtest/models.py
@@ -1,6 +1,7 @@
 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
+# pylint: disable-msg=C0111
 
 """Django chart models for labtest report.
 
@@ -20,8 +21,11 @@
 from autotest_lib.frontend.croschart.charterrors import ChartDBError
 from autotest_lib.frontend.croschart.charterrors import ChartInputError
 
-import gviz_api
-
+try:
+    import gviz_api
+except ImportError:
+    # Do nothing, in case this is part of a unit test.
+    pass
 
 ###############################################################################
 # Queries: These are designed as stateless functions with static relationships.
diff --git a/frontend/croschart/perfchart/models.py b/frontend/croschart/perfchart/models.py
index 0f2910a..af570bf 100644
--- a/frontend/croschart/perfchart/models.py
+++ b/frontend/croschart/perfchart/models.py
@@ -1,6 +1,7 @@
 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
+# pylint: disable-msg=C0111
 
 """Django chart models for performance key-build charts.
 
@@ -18,8 +19,11 @@
 from autotest_lib.frontend.croschart.charterrors import ChartDBError
 from autotest_lib.frontend.croschart.charterrors import ChartInputError
 
-import gviz_api
-
+try:
+    import gviz_api
+except ImportError:
+    # Do nothing, in case this is part of a unit test.
+    pass
 
 # Can only get date order from the db.
 DEFAULT_ORDER = 'ORDER BY test_started_time'
diff --git a/frontend/croschart/releasereport/models.py b/frontend/croschart/releasereport/models.py
index 9b91358..50a3325 100644
--- a/frontend/croschart/releasereport/models.py
+++ b/frontend/croschart/releasereport/models.py
@@ -1,6 +1,7 @@
 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
+# pylint: disable-msg=C0111
 
 """Django chart models for a report listing all known automated tests.
 
@@ -23,8 +24,11 @@
 from autotest_lib.frontend.croschart.charterrors import ChartDBError
 from autotest_lib.frontend.croschart.charterrors import ChartInputError
 
-import gviz_api
-
+try:
+    import gviz_api
+except ImportError:
+    # Do nothing, in case this is part of a unit test.
+    pass
 
 NO_DIFF = 'n/a'
 
diff --git a/frontend/croschart/testreport/models.py b/frontend/croschart/testreport/models.py
index 8997f66..050e2b0 100644
--- a/frontend/croschart/testreport/models.py
+++ b/frontend/croschart/testreport/models.py
@@ -1,6 +1,7 @@
 # Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
+# pylint: disable-msg=C0111
 
 """Django chart models for a report listing all known automated tests.
 
@@ -17,8 +18,11 @@
 from autotest_lib.frontend.croschart.charterrors import ChartDBError
 from autotest_lib.frontend.croschart.charterrors import ChartInputError
 
-import gviz_api
-
+try:
+    import gviz_api
+except ImportError:
+    # Do nothing, in case this is part of a unit test.
+    pass
 
 ###############################################################################
 # Queries: These are designed as stateless functions with static relationships.
diff --git a/frontend/tko/graphing_utils.py b/frontend/tko/graphing_utils.py
index 17a6ceb..cd5c70e 100644
--- a/frontend/tko/graphing_utils.py
+++ b/frontend/tko/graphing_utils.py
@@ -1,4 +1,6 @@
-import base64, os, tempfile, operator, pickle, datetime, django.db
+# pylint: disable-msg=C0111
+
+import base64, os, tempfile, pickle, datetime, django.db
 import os.path, getpass
 from math import sqrt
 
@@ -15,11 +17,16 @@
     os.mkdir(temp_dir)
 os.environ['MPLCONFIGDIR'] = temp_dir
 
-import matplotlib
-matplotlib.use('Agg')
+try:
+    import matplotlib
+    matplotlib.use('Agg')
+    import matplotlib.figure, matplotlib.backends.backend_agg
+    import StringIO, colorsys, PIL.Image, PIL.ImageChops
+except ImportError:
+    # Do nothing, in case this is part of a unit test, so the unit test
+    # can proceed.
+    pass
 
-import matplotlib.figure, matplotlib.backends.backend_agg
-import StringIO, colorsys, PIL.Image, PIL.ImageChops
 from autotest_lib.frontend.afe import readonly_connection
 from autotest_lib.frontend.afe.model_logic import ValidationError
 from json import encoder