def make_paths(tmp_dir, paths_end): complete_paths = [] for path_end in paths_end: complete_path = os.path.join(tmp_dir, path_end) makedirs(complete_path) complete_paths.append(complete_path) return complete_paths
def build_preferences(self, params): """Build the XML files to setup Trepn and the data points""" current_dir = op.dirname(op.realpath(__file__)) # lxml is not the most secure parser, it is up to the user for valid configurations # https://docs.python.org/2/library/xml.html#xml-vulnerabilities self.pref_dir = op.join(self.paths['OUTPUT_DIR'], 'trepn.pref/') util.makedirs(self.pref_dir) preferences_file = et.parse(op.join(current_dir, 'preferences.xml')) preferences_file = self.override_preferences(params, preferences_file) preferences_file.write(op.join(self.pref_dir, 'com.quicinc.trepn_preferences.xml'), encoding='utf-8', xml_declaration=True, standalone=True) datapoints_file = et.parse(op.join(current_dir, 'data_points.xml')) dp_root = datapoints_file.getroot() data_points_dict = util.load_json( op.join(current_dir, 'data_points.json')) for dp in params['data_points']: dp = str(data_points_dict[dp]) self.data_points.append(dp) dp_root.append(et.Element('int', {'name': dp, 'value': dp})) datapoints_file.write(op.join( self.pref_dir, 'com.quicinc.preferences.saved_data_points.xml'), encoding='utf-8', xml_declaration=True, standalone=True)
def setup_paths(config_file, log_dir): paths.CONFIG_DIR = op.dirname(config_file) paths.ORIGINAL_CONFIG_DIR = config_file makedirs(log_dir) paths.OUTPUT_DIR = log_dir paths.BASE_OUTPUT_DIR = log_dir sys.path.append(op.join(paths.ROOT_DIR, 'AndroidRunner'))
def test_makedirs_fail(self, tmpdir): os.chmod(str(tmpdir), 0o444) dir_path = op.join(str(tmpdir), 'test2') assert op.isdir(dir_path) is False with pytest.raises(OSError) as except_result: util.makedirs(dir_path) assert "Permission denied" in str(except_result.value) assert op.isdir(dir_path) is False
def set_dirs(self, device, profiler_name): self.dirs['subject'] = os.path.join(self.output_root, 'data', device.name, 'test_dir_1', 'test_dir_2', profiler_name) self.dirs['aggregated'] = os.path.join( paths.OUTPUT_DIR, '{}_aggregated.csv'.format(profiler_name)) self.dirs['data_folder'] = os.path.join(paths.OUTPUT_DIR, 'data') makedirs(self.dirs['subject'])
def test_makedirs_fail_already_exist(self, tmpdir): dir_path = op.join(str(tmpdir), 'test1') assert op.isdir(dir_path) is False util.makedirs(dir_path) util.makedirs(dir_path) assert op.isdir(dir_path) is True files_in_path = [f for f in os.listdir(str(tmpdir)) if os.path.isdir(os.path.join(str(tmpdir), f))] assert len(files_in_path) == 1
def test_list_dir_non_empty(self, tmpdir, android_test_plugin_handler): tmpdir = os.path.join(str(tmpdir), 'test') makedirs(tmpdir) os.makedirs(os.path.join(tmpdir, '1')) os.makedirs(os.path.join(tmpdir, '2')) sub_dirs = android_test_plugin_handler.list_subdir(tmpdir) assert len(sub_dirs) == 2 assert '1' in sub_dirs assert '2' in sub_dirs
def test_setup_paths(self, tmpdir): temp_config_dir = op.join(str(tmpdir), 'config') makedirs(temp_config_dir) temp_config_file = op.join(temp_config_dir, 'config.json') open(temp_config_file, "w+") temp_log_dir = op.join(str(tmpdir), 'log') main.setup_paths(temp_config_file, temp_log_dir) assert paths.CONFIG_DIR == op.dirname(temp_config_file) assert op.isdir(temp_log_dir) assert paths.OUTPUT_DIR == temp_log_dir assert paths.BASE_OUTPUT_DIR == temp_log_dir assert op.join(paths.ROOT_DIR, 'AndroidRunner') in sys.path
def build_preferences(self, params): """Build the XML files to setup Trepn and the data points""" current_dir = op.dirname(op.realpath(__file__)) # lxml is not the most secure parser, it is up to the user for valid configurations # https://docs.python.org/2/library/xml.html#xml-vulnerabilities self.pref_dir = op.join(self.paths['OUTPUT_DIR'], 'trepn.pref/') util.makedirs(self.pref_dir) preferences_file = et.parse(op.join(current_dir, 'preferences.xml')) if 'preferences' in params: for i in preferences_file.getroot().iter(): if 'sample_interval' in params['preferences'] and \ i.get('name') == 'com.quicinc.preferences.general.profiling_interval': i.set('value', str(params['preferences']['sample_interval'])) if 'battery_power_source_selection' in params['preferences'] and \ i.get('name') == 'com.quicinc.preferences.battery_power_source_selection': i.text = params['preferences'][ 'battery_power_source_selection'] preferences_file.write(op.join(self.pref_dir, 'com.quicinc.trepn_preferences.xml'), encoding='utf-8', xml_declaration=True, standalone=True) datapoints_file = et.parse(op.join(current_dir, 'data_points.xml')) dp_root = datapoints_file.getroot() data_points_dict = util.load_json( op.join(current_dir, 'data_points.json')) for dp in params['data_points']: dp = str(data_points_dict[dp]) self.data_points.append(dp) dp_root.append(et.Element('int', {'name': dp, 'value': dp})) datapoints_file.write(op.join( self.pref_dir, 'com.quicinc.preferences.saved_data_points.xml'), encoding='utf-8', xml_declaration=True, standalone=True)
def test_makedirs_succes(self, tmpdir): dir_path = op.join(str(tmpdir), 'test1') assert op.isdir(dir_path) is False util.makedirs(dir_path) assert op.isdir(dir_path) is True
def test_list_dir_empty(self, tmpdir, android_test_plugin_handler): tmpdir = os.path.join(str(tmpdir), 'test') makedirs(tmpdir) assert android_test_plugin_handler.list_subdir(tmpdir) == []