本文整理汇总了Python中core.osutils.file.File.write方法的典型用法代码示例。如果您正苦于以下问题:Python File.write方法的具体用法?Python File.write怎么用?Python File.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.osutils.file.File
的用法示例。
在下文中一共展示了File.write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wait_for_log
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import write [as 别名]
def wait_for_log(log_file, string_list, not_existing_string_list=None, timeout=45, check_interval=3,
clean_log=True):
"""
Wait until log file contains list of string.
:param log_file: Path to log file.
:param string_list: List of strings.
:param not_existing_string_list: List of string that should not be in logs.
:param timeout: Timeout.
:param check_interval: Check interval.
:param clean_log: Specify if content of log file should be delete after check.
"""
t_end = time.time() + timeout
all_items_found = False
not_found_list = []
log = ""
while time.time() < t_end:
not_found_list = []
log = File.read(log_file)
log = str(log.decode('utf8').encode('utf8')).strip()
for item in string_list:
if item in log:
print "'{0}' found.".format(item)
else:
not_found_list.append(item)
if not_found_list == []:
all_items_found = True
print "Log contains: {0}".format(string_list)
break
else:
print "'{0}' NOT found. Wait...".format(not_found_list)
time.sleep(check_interval)
if 'BUILD FAILED' in log:
print 'BUILD FAILED. No need to wait more time!'
break
if 'Unable to sync files' in log:
print 'Sync process failed. No need to wait more time!'
break
if '????????????????????????????' in log:
print 'Log seems to be corrupted. No need to wait more time!'
break
if 'errors were thrown' in log:
print 'Multiple errors were thrown. No need to wait more time!'
break
if clean_log and (CURRENT_OS is not OSType.WINDOWS) and all_items_found:
File.write(file_path=log_file, text="")
if all_items_found:
if not_existing_string_list is None:
pass
else:
for item in not_existing_string_list:
assert item not in log, "{0} found! It should not be in logs.\nLog:\n{1}".format(item, log)
else:
print "##### OUTPUT BEGIN #####\n"
print log
print "##### OUTPUT END #####\n"
print ""
assert False, "Output does not contain {0}".format(not_found_list)
示例2: setUpClass
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import write [as 别名]
def setUpClass(cls):
BaseClass.setUpClass(cls.__name__)
Folder.cleanup(cls.app_no_platform)
File.remove(cls.debug_apk)
File.remove(cls.release_apk)
Folder.cleanup('temp')
Tns.create_app(cls.app_name)
Tns.platform_add_android(attributes={"--path": cls.app_name, "--frameworkPath": ANDROID_PACKAGE})
# Add release and debug configs
debug = os.path.join(cls.app_name, 'app', 'config.debug.json')
release = os.path.join(cls.app_name, 'app', 'config.release.json')
File.write(file_path=debug, text='{"config":"debug"}')
File.write(file_path=release, text='{"config":"release"}')
示例3: screen_match
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import write [as 别名]
def screen_match(device_name, device_id, expected_image, tolerance=0.1, timeout=30):
"""
Verify screen match expected image.
:param device_name: Name of device (name of Android avd image, or name or iOS Simulator).
:param device_id: Device identifier (example: `emulator-5554`).
:param expected_image: Name of expected image.
:param tolerance: Tolerance in percents.
:param timeout: Timeout in seconds.
"""
device_type = Device.__get_device_type(device_id)
if device_type == DeviceType.IOS:
type = run(command="ideviceinfo | grep ProductType", log_level=CommandLogLevel.SILENT)
type = type.replace(',', '')
type = type.replace('ProductType:', '').strip(' ')
device_name = type
print "Verify {0} looks correct...".format(expected_image)
expected_image_original_path = os.path.join("data", "images", device_name, "{0}.png".format(expected_image))
actual_image_path = os.path.join(OUTPUT_FOLDER, "images", device_name, "{0}_actual.png".format(expected_image))
diff_image_path = os.path.join(OUTPUT_FOLDER, "images", device_name, "{0}_diff.png".format(expected_image))
expected_image_path = os.path.join(OUTPUT_FOLDER, "images", device_name,
"{0}_expected.png".format(expected_image))
if File.exists(expected_image_original_path):
t_end = time.time() + timeout
diff = 100.0
are_equal = False
comparison_result = None
while time.time() < t_end:
time.sleep(1)
if Device.get_screen(device_id=device_id, file_path=actual_image_path):
comparison_result = ImageUtils.image_match(actual_image_path=actual_image_path,
expected_image_path=expected_image_original_path,
tolerance=tolerance)
are_equal = comparison_result[0]
diff = comparison_result[1]
if are_equal:
print "{0} looks OK.".format(expected_image)
break # Exist if images look OK.
else:
time.sleep(2)
print "{0} does not match. Diff is {1} %. Wait...".format(expected_image, diff)
else:
print "Failed to get image from {0}".format(device_id)
# Report results after timeout is over
if not are_equal:
# Save expected and diff images (actual is already there)
diff_image_final_path = os.path.join("out", diff_image_path)
print "Diff image will be saved at " + diff_image_final_path
File.copy(src=expected_image_original_path, dest=expected_image_path)
comparison_result[2].save(diff_image_final_path)
# Get logs (from android devices).
if device_type == DeviceType.EMULATOR or device_type == DeviceType.ANDROID:
log_path = diff_image_final_path.replace('_diff.png', '.log')
print "Console logs will be saved at " + log_path
log = Adb.get_logcat(device_id=device_id)
if len(log) < 10000:
print log
File.write(file_path=log_path, text=log)
assert are_equal, "Current image on {0} does not match expected image {1}. Diff is {2}%". \
format(device_name, expected_image, diff)
else:
# If expected image is not found actual will be saved as expected.
print "Expected image not found. Actual image will be saved as expected: " + expected_image_original_path
time.sleep(timeout)
Device.get_screen(device_id, expected_image_original_path)
assert False, "Expected image not found!"