Index: tools/telemetry/telemetry/core/util_unittest.py |
diff --git a/tools/telemetry/telemetry/core/util_unittest.py b/tools/telemetry/telemetry/core/util_unittest.py |
index 05df311add92e3cd88288185694dbfc19e946b2a..2c5c7736f42f660bdeb01d85cfb9c9e3fd4f9092 100644 |
--- a/tools/telemetry/telemetry/core/util_unittest.py |
+++ b/tools/telemetry/telemetry/core/util_unittest.py |
@@ -4,6 +4,7 @@ |
import os |
import unittest |
import shutil |
+import sys |
import tempfile |
from telemetry.core import util |
@@ -62,3 +63,35 @@ class TestGetSequentialFileName(unittest.TestCase): |
def tearDown(self): |
shutil.rmtree(self.test_directory) |
+ |
+class PySerialVersionTest(unittest.TestCase): |
tonyg
2014/06/11 15:44:00
This is getting convoluted. Stepping back, what yo
|
+ def testPySerialVersion(self): |
+ third_party_pyserial_path = os.path.abspath(\ |
+ os.path.join(util.GetTelemetryDir(), 'third_party', 'pyserial')) |
+ |
+ # Make an explicit call to sys.path.insert(0,...) to make sure the serial |
+ # library is indeed from third_party/pyserial |
+ sys.path.insert(0, third_party_pyserial_path) |
+ import serial |
+ third_party_pyserial_version = serial.VERSION |
+ |
+ # Remove all traces of third_party_pyserial_path from the sys.path |
+ while sys.path.count(third_party_pyserial_path): |
+ sys.path.remove(third_party_pyserial_path) |
+ |
+ try: |
+ # Try to load serial from the system library if its available |
+ reload(serial) |
+ system_library_version = serial.VERSION |
+ |
+ # The version number may or may not match but we can safely ignore it |
+ self.assertEqual(system_library_version, third_party_pyserial_version) |
+ except AssertionError: |
+ # Ignoring both cases |
+ # 1. Serial not being part of any system library |
+ # 2. Version number mismatch |
+ pass |
+ |
+ util.AddDirToPythonPath(third_party_pyserial_path) |
+ reload(serial) |
+ self.assertEqual(serial.VERSION, third_party_pyserial_version) |