本文整理汇总了Python中core.osutils.file.File.exists方法的典型用法代码示例。如果您正苦于以下问题:Python File.exists方法的具体用法?Python File.exists怎么用?Python File.exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.osutils.file.File
的用法示例。
在下文中一共展示了File.exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: platform_added
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import exists [as 别名]
def platform_added(app_name, platform=Platform.NONE, output=None):
"""
Assert platform is added.
:param app_name: Application name (folder where app is located).
:param platform: Platforms that should be available.
:param output: output of `tns platform add` command
"""
# Verify console output is correct
if output is not None:
if platform is Platform.ANDROID:
assert 'Platform android successfully added' in output
if platform is Platform.IOS and CURRENT_OS == OSType.OSX:
assert 'Platform ios successfully added' in output
else:
assert 'Applications for platform ios can not be built on this OS'
assert 'Project successfully created.' not in output
# This is to handle test for app with space.
# In this case we put app name inside ''.
app_name = app_name.replace('\'', '')
app_name = app_name.replace('\"', '')
# Verify file and folder content
if platform is Platform.NONE:
assert not File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_IOS))
assert not File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID))
if platform is Platform.ANDROID or platform is Platform.BOTH:
assert File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID))
if platform is Platform.IOS or platform is Platform.BOTH:
if CURRENT_OS == OSType.OSX:
assert File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_IOS))
else:
assert not File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_IOS))
示例2: created
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import exists [as 别名]
def created(app_name, output=None, full_check=True):
"""
Assert application is created properly.
:param app_name: App name
:param output: Output of `tns create command`
:param full_check: If true everything will be checked. If false only console output will be checked.
"""
# Assert console output is ok
if output is not None:
app = app_name.rsplit('/')[-1]
if USE_YARN != "True":
if Npm.version() < 5:
assert 'nativescript-theme-core' in output
assert 'Project {0} was successfully created'.format(app) in output, 'Failed to create {0}'.format(app)
if full_check:
# Assert files are ok
assert File.exists(app_name)
assert File.exists(app_name + '/node_modules/tns-core-modules/package.json')
assert File.exists(app_name + '/node_modules/tns-core-modules/LICENSE')
assert File.exists(app_name + '/node_modules/tns-core-modules/xml/xml.js')
assert File.exists(app_name + '/node_modules/nativescript-theme-core')
# Assert content of package.json
app_id = app_name.replace(' ', '').replace('_', '').replace('-', '').rsplit('/')[-1]
strings = ['org.nativescript.{0}'.format(app_id), 'tns-core-modules', 'nativescript-theme-core']
TnsAsserts.package_json_contains(app_name, string_list=strings)
示例3: test_205_build_android_app_bundle_env_snapshot
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import exists [as 别名]
def test_205_build_android_app_bundle_env_snapshot(self):
"""Build app with android app bundle option with --bundle and optimisations for snapshot.
Verify the output(app.aab) and use bundletool to deploy on device."""
# This test will not run on windows because env.snapshot option is not available on that OS
path_to_aab = os.path.join(self.app_name, "platforms", "android", "app", "build", "outputs", "bundle", "release", "app.aab")
#Configure app with snapshot optimisations
source = os.path.join('data', 'abdoid-app-bundle', 'app.gradle')
target = os.path.join(self.app_name, 'app', 'App_Resources', 'Android', 'app.gradle' )
File.copy(src=source, dest=target)
source = os.path.join('data', 'abdoid-app-bundle', 'webpack.config.js')
target = os.path.join(self.app_name, 'webpack.config.js' )
File.copy(src=source, dest=target)
#env.snapshot is applicable only in release build
output = Tns.build_android(attributes={"--path": self.app_name,
"--keyStorePath": ANDROID_KEYSTORE_PATH,
"--keyStorePassword": ANDROID_KEYSTORE_PASS,
"--keyStoreAlias": ANDROID_KEYSTORE_ALIAS,
"--keyStoreAliasPassword": ANDROID_KEYSTORE_ALIAS_PASS,
"--release": "",
"--aab": "",
"--env.uglify": "",
"--env.snapshot": "",
"--bundle": ""
}, assert_success=False)
assert "The build result is located at:" in output
assert path_to_aab in output
assert File.exists(path_to_aab)
#Verify app can be deployed on emulator via bundletool
# Use bundletool to create the .apks file
self.bundletool_build(self.bundletool_path, path_to_aab, self.path_to_apks)
assert File.exists(self.path_to_apks)
# Verify that the correct .so file is included in the package
File.unzip(self.path_to_apks, os.path.join(self.app_name, 'apks'))
File.unzip(os.path.join(self.app_name, 'apks', 'splits', 'base-x86.apk'), os.path.join(self.app_name,'base_apk'))
assert File.exists(os.path.join(self.app_name, 'base_apk', 'lib', 'x86', 'libNativeScript.so'))
# Deploy on device
self.bundletool_deploy(self.bundletool_path, self.path_to_apks, device_id=EMULATOR_ID)
# Start the app on device
Adb.start_app(EMULATOR_ID, "org.nativescript.TestApp")
# Verify app looks correct inside emulator
app_started = Device.wait_for_text(device_id=EMULATOR_ID, text='TAP')
assert app_started, 'App is not started on device'
示例4: platform_remove
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import exists [as 别名]
def platform_remove(platform=Platform.NONE, attributes={}, assert_success=True, log_trace=False, tns_path=None):
platform_string = Tns.__get_platform_string(platform)
output = Tns.run_tns_command("platform remove " + platform_string, attributes=attributes, log_trace=log_trace,
tns_path=tns_path)
app_name = Tns.__get_app_name_from_attributes(attributes)
if assert_success:
assert "Platform {0} successfully removed".format(platform_string) in output
assert "error" not in output
if platform is Platform.ANDROID:
assert not File.exists(app_name + TnsAsserts.PLATFORM_ANDROID)
if platform is Platform.IOS:
assert not File.exists(app_name + TnsAsserts.PLATFORM_IOS)
return output
示例5: test_301_prepare_android_platform_specific_files
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import exists [as 别名]
def test_301_prepare_android_platform_specific_files(self):
Tns.prepare_android(attributes={"--path": self.app_name})
# Add set of platform specific files
File.copy(self.app_name + "/app/app.js", self.app_name + "/app/app.ios.js")
File.copy(self.app_name + "/app/app.js", self.app_name + "/app/app.android.js")
File.copy(self.app_name + "/app/app.js", self.app_name + "/app/appios.js")
File.copy(self.app_name + "/app/app.js", self.app_name + "/app/appandroid.js")
File.copy(self.app_name + "/app/app.js", self.app_name + "/app/ios.js")
File.copy(self.app_name + "/app/app.js", self.app_name + "/app/android.js")
File.copy(self.app_name + "/app/app.css", self.app_name + "/app/app.ios.css")
File.copy(self.app_name + "/app/app.css", self.app_name + "/app/app.android.css")
File.copy(self.app_name + "/app/app.js", self.app_name + "/app/appNew.js")
File.copy(self.app_name + "/app/app.css", self.app_name + "/app/appNew.css")
File.remove(self.app_name + "/app/app.js")
File.remove(self.app_name + "/app/app.css")
Tns.prepare_android(attributes={"--path": self.app_name})
# Verify new files are in available in platforms folder
app_path = os.path.join(self.app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH)
assert File.exists(os.path.join(app_path, 'app.css'))
assert File.exists(os.path.join(app_path, 'app.js'))
assert File.exists(os.path.join(app_path, 'appandroid.js'))
assert File.exists(os.path.join(app_path, 'appios.js'))
assert File.exists(os.path.join(app_path, 'android.js'))
assert File.exists(os.path.join(app_path, 'ios.js'))
assert not File.exists(os.path.join(app_path, 'app.ios.css'))
assert not File.exists(os.path.join(app_path, 'app.android.css'))
示例6: get_screen_text
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import exists [as 别名]
def get_screen_text():
"""
Get text of current screen of host machine.
:return: All the text visible on screen as string
"""
base_path = os.path.join(OUTPUT_FOLDER, "images", "host")
if not File.exists(base_path):
Folder.create(base_path)
actual_image_path = os.path.join(base_path, "host_{0}.png".format(time.time()))
if File.exists(actual_image_path):
File.remove(actual_image_path)
Screen.save_screen(path=actual_image_path)
image = Image.open(actual_image_path)
text = pytesseract.image_to_string(image.convert('L'))
return text
示例7: create_app_ng
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import exists [as 别名]
def create_app_ng(app_name, attributes={}, log_trace=False, assert_success=True, update_modules=True,
template_version=None):
if template_version is not None:
template = "[email protected]" + template_version
attr = {"--template": template}
else:
if BRANCH is "master":
attr = {"--template": SUT_FOLDER + os.path.sep + "tns-template-hello-world-ng.tgz"}
else:
attr = {"--template": "tns-template-hello-world-ng"}
attributes.update(attr)
output = Tns.create_app(app_name=app_name, attributes=attributes, log_trace=log_trace,
assert_success=assert_success,
update_modules=update_modules)
if update_modules:
Tns.update_angular(path=app_name)
Tns.update_typescript(path=app_name)
if assert_success:
if USE_YARN != "True":
if Npm.version() < 5:
assert "nativescript-angular" in output
assert File.exists(os.path.join(app_name, 'node_modules', 'nativescript-theme-core'))
package_json = File.read(os.path.join(app_name, 'package.json'))
assert "tns-core-modules" in package_json
assert "nativescript-angular" in package_json
assert "nativescript-dev-typescript" in package_json
return output
示例8: get_screen
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import exists [as 别名]
def get_screen(device_id, file_path):
"""
Save screen of mobile device.
:param device_id: Device identifier (example: `emulator-5554`).
:param file_path: Path to image that will be saved.
"""
File.remove(file_path)
base_path, file_name = os.path.split(file_path)
Folder.create(base_path)
device_type = Device.__get_device_type(device_id)
if (device_type == DeviceType.EMULATOR) or (device_type == DeviceType.ANDROID):
Adb.get_screen(device_id=device_id, file_path=file_path)
if device_type == DeviceType.SIMULATOR:
Simulator.get_screen(device_id=device_id, file_path=file_path)
if device_type == DeviceType.IOS:
IDevice.get_screen(device_id=device_id, file_path=file_path)
image_saved = False
if File.exists(file_path):
size = os.path.getsize(file_path)
if size > 10:
image_saved = True
return image_saved
示例9: tearDown
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import exists [as 别名]
def tearDown(self):
# Logic executed only on test failure
test_name = self._testMethodName
artifacts_folder = os.path.join(OUTPUT_FOLDER, self.__class__.__name__ + "_" + test_name)
outcome = "PASSED"
if self.IsFailed(self._resultForDoCleanups) is True:
outcome = "FAILED"
# Ensure `artifacts_folder` exists and it is clean
if File.exists(artifacts_folder):
Folder.cleanup(artifacts_folder)
else:
Folder.create(artifacts_folder)
# Collect artifacts on test failure
self.__copy_images(artifacts_folder=artifacts_folder)
self.__copy_project_folder(artifacts_folder=artifacts_folder)
self.__save_host_screen(artifacts_folder=artifacts_folder, test_method_name=test_name)
print ""
print "Test Method: {0}".format(self._testMethodName)
print "End Time: {0}".format(time.strftime("%X"))
print "Outcome: {0}".format(outcome)
print "_________________________________TEST END_______________________________________"
print ""
示例10: test_300_prepare_ios_preserve_case
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import exists [as 别名]
def test_300_prepare_ios_preserve_case(self):
File.copy(self.app_name + "/node_modules/tns-core-modules/application/application-common.js",
self.app_name + "/node_modules/tns-core-modules/application/New-application-common.js")
File.copy(self.app_name + "/node_modules/tns-core-modules/application/application.android.js",
self.app_name + "/node_modules/tns-core-modules/application/New-application.android.js")
File.copy(self.app_name + "/node_modules/tns-core-modules/application/application.ios.js",
self.app_name + "/node_modules/tns-core-modules/application/New-application.ios.js")
output = Tns.prepare_ios(attributes={"--path": self.app_name})
TnsAsserts.prepared(self.app_name, platform=Platform.IOS, output=output, prepare=Prepare.FULL)
# Verify case is preserved
path = TnsAsserts._get_ios_modules_path(self.app_name)
assert File.exists(path + 'application/New-application-common.js')
assert File.exists(path + 'application/New-application.js')
assert not File.exists(path + 'application/New-application.ios.js')
示例11: create_app
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import exists [as 别名]
def create_app(app_name, attributes={}, log_trace=False, assert_success=True, update_modules=True,
force_clean=True, measureTime=False):
if force_clean:
if File.exists(app_name):
Folder.cleanup(app_name)
path = app_name
attributes_to_string = ""
for k, v in attributes.iteritems():
if "--path" in k:
path = v
attributes_to_string = "".join("{0} {1}".format(k, v))
attr = {}
if not any(s in attributes_to_string for s in ("--ng", "--template", "--tsc", "--vue")):
if BRANCH == "master":
attr = {"--template": SUT_FOLDER + os.path.sep + "tns-template-hello-world.tgz"}
else:
attr = {"--template": "tns-template-hello-world"}
attr.update(attributes)
if app_name is None:
output = Tns.run_tns_command("create ", attributes=attr, log_trace=log_trace, measureTime=measureTime)
else:
output = Tns.run_tns_command("create \"" + app_name + "\"", attributes=attr, log_trace=log_trace,
measureTime=measureTime)
if assert_success:
TnsAsserts.created(app_name=app_name, output=output)
if update_modules:
Tns.update_modules(path)
# Tns.ensure_app_resources(path)
return output
示例12: build_android
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import exists [as 别名]
def build_android(attributes={}, assert_success=True, tns_path=None, log_trace=False, measureTime=False):
output = Tns.run_tns_command("build android", attributes=attributes, tns_path=tns_path, log_trace=log_trace,
measureTime=measureTime)
if assert_success:
# Verify output of build command
assert "Project successfully built" in output, "Build failed!" + os.linesep + output
assert "FAILURE" not in output
assert "NOT FOUND" not in output # Test for https://github.com/NativeScript/android-runtime/issues/390
if log_trace:
assert "BUILD SUCCESSFUL" in output, "Build failed!" + os.linesep + output
else:
assert "BUILD SUCCESSFUL" not in output, "Native build out is displayed even without --log trace"
# Verify apk packages
app_name = Tns.__get_app_name_from_attributes(attributes=attributes)
Tns.__get_platform_string(platform=Platform.ANDROID)
android_version_string = str(TnsAsserts.get_platform_version(app_name=app_name, platform='android'))
android_major_version = int(android_version_string.split('-')[0].split('.')[0])
if android_major_version > 3:
apk_name = "app"
debug_app_path = os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APK_DEBUG_PATH, apk_name)
release_app_path = os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APK_RELEASE_PATH, apk_name)
else:
apk_name = Tns.__get_final_package_name(app_name, platform=Platform.ANDROID)
debug_app_path = os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APK_PATH, apk_name)
release_app_path = os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APK_PATH, apk_name)
if "--release" in attributes.keys():
apk_path = release_app_path + "-release.apk"
else:
apk_path = debug_app_path + "-debug.apk"
apk_path = apk_path.replace("\"", "") # Handle projects with space
assert File.exists(apk_path), "Apk file does not exist at " + apk_path
# Verify final package contains right modules (or verify bundle when it is used)
if "--bundle" not in attributes.keys():
assert "Webpack compilation complete" not in output
else:
assert "Webpack compilation complete" in output
assert File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH, "bundle.js"))
assert File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH, "package.json"))
assert File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH, "starter.js"))
assert File.exists(os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_APP_PATH, "vendor.js"))
assert not Folder.exists(os.path.join(app_name, TnsAsserts.PLATFORM_ANDROID_NPM_MODULES_PATH))
return output
示例13: get_screen
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import exists [as 别名]
def get_screen(device_id, file_path):
"""
Save screen of iOS Simulator.
:param device_id: Device identifier (Simualtor GUID)
:param file_path: Name of image that will be saved.
"""
run(command="xcrun simctl io {0} screenshot {1}".format(device_id, file_path), log_level=CommandLogLevel.SILENT)
assert File.exists(file_path), "Failed to get screenshot at " + file_path
示例14: test_200_build_android_inside_project_folder
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import exists [as 别名]
def test_200_build_android_inside_project_folder(self):
Folder.navigate_to(self.app_name)
output = Tns.build_android(tns_path=os.path.join("..", TNS_PATH), attributes={"--path": self.app_name},
assert_success=False, log_trace=True)
Folder.navigate_to(TEST_RUN_HOME, relative_from_current_folder=False)
assert successfully_prepared in output
assert build_successful in output
assert successfully_built in output
assert File.exists(os.path.join(self.app_name, TnsAsserts.PLATFORM_ANDROID_APK_DEBUG_PATH, self.debug_apk))
示例15: ensure_app_resources
# 需要导入模块: from core.osutils.file import File [as 别名]
# 或者: from core.osutils.file.File import exists [as 别名]
def ensure_app_resources(path):
app_resources_path = os.path.join(path, "app", "App_Resources")
if File.exists(app_resources_path):
pass
else:
print "AppResources not found. Will copy from default template..."
src = os.path.join(TEST_RUN_HOME, "sut", "template-hello-world", "app", "App_Resources")
dest = os.path.join(TEST_RUN_HOME, path, "app", "App_Resources")
Folder.copy(src, dest)