Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2012 The Chromium Authors. All rights reserved. | 1 # Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 import os | 4 import os |
| 5 import unittest | 5 import unittest |
| 6 import shutil | 6 import shutil |
| 7 import sys | |
| 7 import tempfile | 8 import tempfile |
| 8 | 9 |
| 9 from telemetry.core import util | 10 from telemetry.core import util |
| 10 | 11 |
| 11 class TestWait(unittest.TestCase): | 12 class TestWait(unittest.TestCase): |
| 12 @staticmethod | 13 @staticmethod |
| 13 def testNonTimeout(): | 14 def testNonTimeout(): |
| 14 def test(): | 15 def test(): |
| 15 return True | 16 return True |
| 16 util.WaitFor(test, 0.1) | 17 util.WaitFor(test, 0.1) |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 with open( | 56 with open( |
| 56 os.path.join(self.test_directory, 'test_%03d.json' % i), 'w') as _: | 57 os.path.join(self.test_directory, 'test_%03d.json' % i), 'w') as _: |
| 57 pass | 58 pass |
| 58 next_json_test_file_path = util.GetSequentialFileName( | 59 next_json_test_file_path = util.GetSequentialFileName( |
| 59 os.path.join(self.test_directory, 'test')) | 60 os.path.join(self.test_directory, 'test')) |
| 60 self.assertEquals(os.path.join(self.test_directory, 'test_003'), | 61 self.assertEquals(os.path.join(self.test_directory, 'test_003'), |
| 61 next_json_test_file_path) | 62 next_json_test_file_path) |
| 62 | 63 |
| 63 def tearDown(self): | 64 def tearDown(self): |
| 64 shutil.rmtree(self.test_directory) | 65 shutil.rmtree(self.test_directory) |
| 66 | |
| 67 class PySerialVersionTest(unittest.TestCase): | |
|
tonyg
2014/06/11 15:44:00
This is getting convoluted. Stepping back, what yo
| |
| 68 def testPySerialVersion(self): | |
| 69 third_party_pyserial_path = os.path.abspath(\ | |
| 70 os.path.join(util.GetTelemetryDir(), 'third_party', 'pyserial')) | |
| 71 | |
| 72 # Make an explicit call to sys.path.insert(0,...) to make sure the serial | |
| 73 # library is indeed from third_party/pyserial | |
| 74 sys.path.insert(0, third_party_pyserial_path) | |
| 75 import serial | |
| 76 third_party_pyserial_version = serial.VERSION | |
| 77 | |
| 78 # Remove all traces of third_party_pyserial_path from the sys.path | |
| 79 while sys.path.count(third_party_pyserial_path): | |
| 80 sys.path.remove(third_party_pyserial_path) | |
| 81 | |
| 82 try: | |
| 83 # Try to load serial from the system library if its available | |
| 84 reload(serial) | |
| 85 system_library_version = serial.VERSION | |
| 86 | |
| 87 # The version number may or may not match but we can safely ignore it | |
| 88 self.assertEqual(system_library_version, third_party_pyserial_version) | |
| 89 except AssertionError: | |
| 90 # Ignoring both cases | |
| 91 # 1. Serial not being part of any system library | |
| 92 # 2. Version number mismatch | |
| 93 pass | |
| 94 | |
| 95 util.AddDirToPythonPath(third_party_pyserial_path) | |
| 96 reload(serial) | |
| 97 self.assertEqual(serial.VERSION, third_party_pyserial_version) | |
| OLD | NEW |