[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/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