Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(600)

Side by Side Diff: tools/telemetry/telemetry/unittest_util/system_stub.py

Issue 838253005: Refactor serving_dirs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unittests. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 4
5 """Provides stubs for os, sys and subprocess for testing 5 """Provides stubs for os, sys and subprocess for testing
6 6
7 This test allows one to test code that itself uses os, sys, and subprocess. 7 This test allows one to test code that itself uses os, sys, and subprocess.
8 """ 8 """
9 9
10 import os 10 import os
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 result = CloudStorageModuleStub.GetHelper( 278 result = CloudStorageModuleStub.GetHelper(
279 self, self.PUBLIC_BUCKET, remote_path, local_path, True) 279 self, self.PUBLIC_BUCKET, remote_path, local_path, True)
280 if not result: 280 if not result:
281 result = CloudStorageModuleStub.GetHelper( 281 result = CloudStorageModuleStub.GetHelper(
282 self, self.PARTNER_BUCKET, remote_path, local_path, True) 282 self, self.PARTNER_BUCKET, remote_path, local_path, True)
283 if not result: 283 if not result:
284 result = CloudStorageModuleStub.GetHelper( 284 result = CloudStorageModuleStub.GetHelper(
285 self, self.INTERNAL_BUCKET, remote_path, local_path, True) 285 self, self.INTERNAL_BUCKET, remote_path, local_path, True)
286 return result 286 return result
287 287
288 def GetFilesInDirectoryIfChanged(self, directory, bucket):
289 if os.path.splitdrive(directory)[1] == '/':
290 raise ValueError('Trying to serve root directory from HTTP server.')
291 for dirpath, _, filenames in os.walk(directory):
292 for filename in filenames:
293 path, extension = os.path.splitext(
294 os.path.join(dirpath, filename))
295 if extension != '.sha1':
296 continue
297 self.GetIfChanged(path, bucket)
298
288 def CalculateHash(self, file_path): 299 def CalculateHash(self, file_path):
289 return self.local_file_hashes[file_path] 300 return self.local_file_hashes[file_path]
290 301
291 def ReadHash(self, hash_path): 302 def ReadHash(self, hash_path):
292 return self.local_hash_files[hash_path] 303 return self.local_hash_files[hash_path]
293 304
294 305
295 class LoggingStub(object): 306 class LoggingStub(object):
296 def __init__(self): 307 def __init__(self):
297 self.warnings = [] 308 self.warnings = []
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 return os.path.expanduser(path) 393 return os.path.expanduser(path)
383 394
384 @staticmethod 395 @staticmethod
385 def dirname(path): 396 def dirname(path):
386 return os.path.dirname(path) 397 return os.path.dirname(path)
387 398
388 @staticmethod 399 @staticmethod
389 def splitext(path): 400 def splitext(path):
390 return os.path.splitext(path) 401 return os.path.splitext(path)
391 402
403 @staticmethod
404 def splitdrive(path):
405 return os.path.splitdrive(path)
406
392 X_OK = os.X_OK 407 X_OK = os.X_OK
393 408
394 pathsep = os.pathsep 409 pathsep = os.pathsep
395 410
396 def __init__(self, sys_module=sys): 411 def __init__(self, sys_module=sys):
397 self.path = OsModuleStub.OsPathModuleStub(sys_module) 412 self.path = OsModuleStub.OsPathModuleStub(sys_module)
398 self.environ = OsModuleStub.OsEnvironModuleStub() 413 self.environ = OsModuleStub.OsEnvironModuleStub()
399 self.display = ':0' 414 self.display = ':0'
400 self.local_app_data = None 415 self.local_app_data = None
401 self.sys_path = None 416 self.sys_path = None
402 self.program_files = None 417 self.program_files = None
403 self.program_files_x86 = None 418 self.program_files_x86 = None
404 self.devnull = os.devnull 419 self.devnull = os.devnull
420 self._directory = {}
405 421
406 def access(self, path, _): 422 def access(self, path, _):
407 return path in self.path.files 423 return path in self.path.files
408 424
409 def getenv(self, name, value=None): 425 def getenv(self, name, value=None):
410 if name == 'DISPLAY': 426 if name == 'DISPLAY':
411 env = self.display 427 env = self.display
412 elif name == 'LOCALAPPDATA': 428 elif name == 'LOCALAPPDATA':
413 env = self.local_app_data 429 env = self.local_app_data
414 elif name == 'PATH': 430 elif name == 'PATH':
415 env = self.sys_path 431 env = self.sys_path
416 elif name == 'PROGRAMFILES': 432 elif name == 'PROGRAMFILES':
417 env = self.program_files 433 env = self.program_files
418 elif name == 'PROGRAMFILES(X86)': 434 elif name == 'PROGRAMFILES(X86)':
419 env = self.program_files_x86 435 env = self.program_files_x86
420 else: 436 else:
421 raise NotImplementedError('Unsupported getenv') 437 raise NotImplementedError('Unsupported getenv')
422 return env if env else value 438 return env if env else value
423 439
424 def chdir(self, path): 440 def chdir(self, path):
425 pass 441 pass
426 442
443 def walk(self, top):
444 for dir_name in self._directory:
445 yield top, dir_name, self._directory[dir_name]
446
427 447
428 class PerfControlModuleStub(object): 448 class PerfControlModuleStub(object):
429 class PerfControlStub(object): 449 class PerfControlStub(object):
430 def __init__(self, adb): 450 def __init__(self, adb):
431 pass 451 pass
432 452
433 def __init__(self): 453 def __init__(self):
434 self.PerfControl = PerfControlModuleStub.PerfControlStub 454 self.PerfControl = PerfControlModuleStub.PerfControlStub
435 455
436 456
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 class AdbInstallCertStub(object): 517 class AdbInstallCertStub(object):
498 class AndroidCertInstaller(object): 518 class AndroidCertInstaller(object):
499 def __init__(self, device_id, _cert_name, _cert_path): 519 def __init__(self, device_id, _cert_name, _cert_path):
500 if device_id == 'success': 520 if device_id == 'success':
501 pass 521 pass
502 elif device_id == 'failure': 522 elif device_id == 'failure':
503 raise Exception('Test exception.') 523 raise Exception('Test exception.')
504 524
505 def install_cert(self, overwrite_cert=False): 525 def install_cert(self, overwrite_cert=False):
506 pass 526 pass
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698