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

Side by Side Diff: build/android/pylib/instrumentation/instrumentation_test_instance.py

Issue 2688913003: Add shared preference file modification option to instrumentation test runner (Closed)
Patch Set: Address more comments Created 3 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
« no previous file with comments | « no previous file | build/android/pylib/local/device/local_device_instrumentation_test_run.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 import collections 5 import collections
6 import copy 6 import copy
7 import json
7 import logging 8 import logging
8 import os 9 import os
9 import pickle 10 import pickle
10 import re 11 import re
11 12
12 from devil.android import apk_helper 13 from devil.android import apk_helper
13 from devil.android import md5sum 14 from devil.android import md5sum
14 from pylib import constants 15 from pylib import constants
15 from pylib.base import base_test_result 16 from pylib.base import base_test_result
16 from pylib.base import test_exception 17 from pylib.base import test_exception
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 494
494 self._coverage_directory = None 495 self._coverage_directory = None
495 self._initializeTestCoverageAttributes(args) 496 self._initializeTestCoverageAttributes(args)
496 497
497 self._store_tombstones = False 498 self._store_tombstones = False
498 self._initializeTombstonesAttributes(args) 499 self._initializeTombstonesAttributes(args)
499 500
500 self._should_save_logcat = None 501 self._should_save_logcat = None
501 self._initializeLogAttributes(args) 502 self._initializeLogAttributes(args)
502 503
504 self._edit_shared_prefs = []
505 self._initializeEditPrefsAttributes(args)
506
503 def _initializeApkAttributes(self, args, error_func): 507 def _initializeApkAttributes(self, args, error_func):
504 if args.apk_under_test: 508 if args.apk_under_test:
505 apk_under_test_path = args.apk_under_test 509 apk_under_test_path = args.apk_under_test
506 if not args.apk_under_test.endswith('.apk'): 510 if not args.apk_under_test.endswith('.apk'):
507 apk_under_test_path = os.path.join( 511 apk_under_test_path = os.path.join(
508 constants.GetOutDirectory(), constants.SDK_BUILD_APKS_DIR, 512 constants.GetOutDirectory(), constants.SDK_BUILD_APKS_DIR,
509 '%s.apk' % args.apk_under_test) 513 '%s.apk' % args.apk_under_test)
510 514
511 # TODO(jbudorick): Move the realpath up to the argument parser once 515 # TODO(jbudorick): Move the realpath up to the argument parser once
512 # APK-by-name is no longer supported. 516 # APK-by-name is no longer supported.
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 672
669 def _initializeTestCoverageAttributes(self, args): 673 def _initializeTestCoverageAttributes(self, args):
670 self._coverage_directory = args.coverage_dir 674 self._coverage_directory = args.coverage_dir
671 675
672 def _initializeTombstonesAttributes(self, args): 676 def _initializeTombstonesAttributes(self, args):
673 self._store_tombstones = args.store_tombstones 677 self._store_tombstones = args.store_tombstones
674 678
675 def _initializeLogAttributes(self, args): 679 def _initializeLogAttributes(self, args):
676 self._should_save_logcat = bool(args.json_results_file) 680 self._should_save_logcat = bool(args.json_results_file)
677 681
682 def _initializeEditPrefsAttributes(self, args):
683 if not hasattr(args, 'shared_prefs_file'):
684 return
685 if not isinstance(args.shared_prefs_file, str):
686 logging.warning("Given non-string for a filepath")
687 return
688
689 # json.load() loads strings as unicode, which causes issues when trying
690 # to edit string values in preference files, so convert to Python strings
691 def unicode_to_str(data):
692 if isinstance(data, dict):
693 return {unicode_to_str(key): unicode_to_str(value)
694 for key, value in data.iteritems()}
695 elif isinstance(data, list):
696 return [unicode_to_str(element) for element in data]
697 elif isinstance(data, unicode):
698 return data.encode('utf-8')
699 return data
700
701 with open(args.shared_prefs_file) as prefs_file:
702 self._edit_shared_prefs = unicode_to_str(json.load(prefs_file))
703
678 @property 704 @property
679 def additional_apks(self): 705 def additional_apks(self):
680 return self._additional_apks 706 return self._additional_apks
681 707
682 @property 708 @property
683 def apk_under_test(self): 709 def apk_under_test(self):
684 return self._apk_under_test 710 return self._apk_under_test
685 711
686 @property 712 @property
687 def apk_under_test_incremental_install_script(self): 713 def apk_under_test_incremental_install_script(self):
688 return self._apk_under_test_incremental_install_script 714 return self._apk_under_test_incremental_install_script
689 715
690 @property 716 @property
691 def coverage_directory(self): 717 def coverage_directory(self):
692 return self._coverage_directory 718 return self._coverage_directory
693 719
694 @property 720 @property
695 def driver_apk(self): 721 def driver_apk(self):
696 return self._driver_apk 722 return self._driver_apk
697 723
698 @property 724 @property
699 def driver_package(self): 725 def driver_package(self):
700 return self._driver_package 726 return self._driver_package
701 727
702 @property 728 @property
703 def driver_name(self): 729 def driver_name(self):
704 return self._driver_name 730 return self._driver_name
705 731
706 @property 732 @property
733 def edit_shared_prefs(self):
734 return self._edit_shared_prefs
735
736 @property
707 def flags(self): 737 def flags(self):
708 return self._flags 738 return self._flags
709 739
710 @property 740 @property
711 def should_save_logcat(self): 741 def should_save_logcat(self):
712 return self._should_save_logcat 742 return self._should_save_logcat
713 743
714 @property 744 @property
715 def package_info(self): 745 def package_info(self):
716 return self._package_info 746 return self._package_info
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 869
840 @staticmethod 870 @staticmethod
841 def GenerateTestResults( 871 def GenerateTestResults(
842 result_code, result_bundle, statuses, start_ms, duration_ms): 872 result_code, result_bundle, statuses, start_ms, duration_ms):
843 return GenerateTestResults(result_code, result_bundle, statuses, 873 return GenerateTestResults(result_code, result_bundle, statuses,
844 start_ms, duration_ms) 874 start_ms, duration_ms)
845 875
846 #override 876 #override
847 def TearDown(self): 877 def TearDown(self):
848 pass 878 pass
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/local/device/local_device_instrumentation_test_run.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698