How to use is_detached method in Playwright Python

Best Python code snippet using playwright-python

shade.py

Source:shade.py Github

copy

Full Screen

...89 """90 geometry = Face3D(tuple(Point3D(*v) for v in vertices))91 return cls(identifier, geometry, is_detached)92 @property93 def is_detached(self):94 """Get or set a boolean for whether this object is detached from other geometry.95 This will automatically be set to False if the shade is assigned to96 parent objects.97 """98 return self._is_detached99 @is_detached.setter100 def is_detached(self, value):101 try:102 self._is_detached = bool(value)103 if self._is_detached:104 assert not self.has_parent, 'Shade cannot be detached when it has ' \105 'a parent Room, Face, Aperture or Door.'106 except TypeError:107 raise TypeError(108 'Expected boolean for Shade.is_detached. Got {}.'.format(value))109 @property110 def parent(self):111 """Get the parent object if assigned. None if not assigned.112 The parent object can be either a Room, Face, Aperture or Door.113 """114 return self._parent...

Full Screen

Full Screen

test_component.py

Source:test_component.py Github

copy

Full Screen

1from __future__ import annotations2import json3import pytest4import yaml5from collections.abc import Iterable6from pathlib import Path as P7from git import Repo8from textwrap import dedent9from commodore.component import (10 Component,11 component_dir,12 component_parameters_key,13)14from commodore.gitrepo import RefError15from commodore.inventory import Inventory16def setup_directory(tmp_path: P):17 inv = Inventory(work_dir=tmp_path)18 inv.ensure_dirs()19 jsonnetfile = tmp_path / "jsonnetfile.json"20 with open(jsonnetfile, "w") as jf:21 json.dump({"version": 1, "dependencies": [], "legacyImports": True}, jf)22def _init_repo(tmp_path: P, cn: str, url: str):23 setup_directory(tmp_path)24 cr = Repo.init(component_dir(cn))25 cr.create_remote("origin", url)26REPO_URL = "https://github.com/projectsyn/component-argocd.git"27def _setup_component(28 tmp_path: P,29 version="master",30 repo_url=REPO_URL,31 name="argocd",32):33 return Component(34 name,35 repo_url=repo_url,36 directory=tmp_path / name,37 version=version,38 )39def test_component_checkout(tmp_path):40 c = _setup_component(tmp_path)41 c.checkout()42 assert c.version == "master"43 assert c.repo.repo.head.ref.name == "master"44 pull_remote = c.repo.remote45 push_remote = c.repo.repo.git.remote("get-url", "--push", "origin")46 assert pull_remote == REPO_URL47 assert push_remote.startswith("ssh://git@")48 assert push_remote == REPO_URL.replace("https://", "ssh://git@")49def test_component_checkout_branch(tmp_path):50 branch = "component-defs-in-applications"51 c = _setup_component(tmp_path, version=branch)52 c.checkout()53 assert c.version == branch54 repo = c.repo.repo55 assert repo.head.ref.name == branch56 for rb in repo.remote().refs:57 if rb.name.endswith(branch):58 remote_branch_commit = rb.commit59 break60 else:61 raise ValueError(f"No remote branch for {branch}")62 assert not repo.head.is_detached63 assert repo.head.ref.name == branch64 assert repo.head.commit == remote_branch_commit65def test_component_checkout_sha1version(tmp_path: P):66 commit = "696b4b4cb9a86ebc845daa314a0a98957f89e99b"67 c = _setup_component(tmp_path, version=commit)68 c.checkout()69 assert c.repo.repo.head.is_detached70 assert c.repo.repo.head.commit.hexsha == commit71def test_component_checkout_tag(tmp_path: P):72 c = _setup_component(73 tmp_path,74 version="v1.0.0",75 repo_url="https://github.com/projectsyn/component-backup-k8up.git",76 name="backup-k8up",77 )78 c.checkout()79 assert c.repo.repo.head.is_detached80 assert c.repo.repo.head.commit.hexsha == c.repo.repo.tags["v1.0.0"].commit.hexsha81def test_component_checkout_nonexisting_version(tmp_path: P):82 c = _setup_component(tmp_path, version="does-not-exist")83 with pytest.raises(RefError):84 c.checkout()85def test_component_checkout_existing_repo_update_version_branch(tmp_path: P):86 c = _setup_component(tmp_path, version="master")87 c.checkout()88 assert not c.repo.repo.head.is_detached89 assert c.repo.repo.head.ref.name == "master"90 # update version91 branch = "component-defs-in-applications"92 c.version = branch93 c.checkout()94 assert not c.repo.repo.head.is_detached95 assert c.repo.repo.head.ref.name == branch96def test_component_checkout_existing_repo_update_version_sha1version(tmp_path: P):97 c = _setup_component(tmp_path, version="master")98 c.checkout()99 assert not c.repo.repo.head.is_detached100 assert c.repo.repo.head.ref.name == "master"101 # update version102 commit = "696b4b4cb9a86ebc845daa314a0a98957f89e99b"103 c.version = commit104 c.checkout()105 assert c.repo.repo.head.is_detached106 assert c.repo.repo.head.commit.hexsha == commit107def test_component_checkout_existing_repo_update_latest_upstream(tmp_path: P):108 c = _setup_component(tmp_path, version="master")109 c.checkout()110 assert not c.repo.repo.head.is_detached111 assert c.repo.repo.head.ref.name == "master"112 master_commit = c.repo.repo.head.commit.hexsha113 c.repo.repo.git.reset("HEAD^", hard=True)114 assert not c.repo.repo.head.is_detached115 assert c.repo.repo.head.ref.name == "master"116 assert c.repo.repo.head.commit.hexsha != master_commit117 c.checkout()118 assert not c.repo.repo.head.is_detached119 assert c.repo.repo.head.ref.name == "master"120 assert not c.repo.repo.is_dirty()121@pytest.mark.parametrize(122 "mode",123 ["reinit", "update"],124)125def test_component_checkout_existing_repo_update_remote(tmp_path: P, mode: str):126 c = _setup_component(tmp_path, version="master")127 c.checkout()128 assert not c.repo.repo.head.is_detached129 assert c.repo.repo.head.ref.name == "master"130 # remember original url of remote origin131 orig_url = next(c.repo.repo.remote().urls)132 # create local upstream repo133 local = tmp_path / "upstream" / "argocd.git"134 Repo.init(local, bare=True)135 local_url = f"file://{local}"136 local_ver = "local-branch"137 # push repo to local upstream with a custom branch138 c.repo.repo.create_remote("local", local_url)139 c.repo.repo.create_head(local_ver)140 c.repo.repo.remote("local").push(local_ver)141 c.repo.repo.delete_remote("local")142 c.repo.repo.delete_head(local_ver)143 if mode == "reinit":144 # reinitialize component object on existing repo with different url/version info145 c = _setup_component(tmp_path, version=local_ver, repo_url=local_url)146 c.checkout()147 elif mode == "update":148 c.repo_url = local_url149 c.version = local_ver150 c.checkout()151 else:152 raise ValueError(f"Unknown mode {mode} for test")153 assert local_url in c.repo.repo.remote().urls154 assert orig_url not in c.repo.repo.remote().urls155 assert not c.repo.repo.head.is_detached156 assert c.repo.repo.head.ref.name == "local-branch"157def test_init_existing_component(tmp_path: P):158 cn = "test-component"159 orig_url = "git@github.com:projectsyn/commodore.git"160 setup_directory(tmp_path)161 cr = Repo.init(tmp_path)162 cr.create_remote("origin", orig_url)163 c = Component(cn, directory=tmp_path)164 for url in c.repo.repo.remote().urls:165 assert url == orig_url166def _setup_render_jsonnetfile_json(tmp_path: P) -> Component:167 Repo.init(tmp_path)168 c = Component("kube-monitoring", directory=tmp_path)169 jsonnetfile = tmp_path / "jsonnetfile.jsonnet"170 with open(jsonnetfile, "w") as jf:171 jf.write(172 dedent(173 """174 {175 version: 1,176 dependencies: [177 {178 source: {179 git: {180 remote: "https://github.com/coreos/kube-prometheus",181 subdir: "jsonnet/kube-prometheus",182 },183 },184 version: std.extVar("kube_prometheus_version"),185 },186 ],187 legacyImports: true,188 }"""189 )190 )191 c.repo.repo.index.add("*")192 c.repo.repo.index.commit("Initial commit")193 return c194def _render_jsonnetfile_json_error_string(c: Component):195 return (196 f" > [WARN] Component {c.name} repo contains both jsonnetfile.json and jsonnetfile.jsonnet, "197 + "continuing with jsonnetfile.jsonnet"198 )199def test_render_jsonnetfile_json(tmp_path: P, capsys):200 c = _setup_render_jsonnetfile_json(tmp_path)201 c.render_jsonnetfile_json(202 {"jsonnetfile_parameters": {"kube_prometheus_version": "1.18"}}203 )204 stdout, _ = capsys.readouterr()205 assert (tmp_path / "jsonnetfile.json").is_file()206 assert _render_jsonnetfile_json_error_string(c) not in stdout207 with open(tmp_path / "jsonnetfile.json") as jf:208 jsonnetfile_contents = json.load(jf)209 assert isinstance(jsonnetfile_contents, dict)210 # check expected keys are there using set comparison211 assert {"version", "dependencies", "legacyImports"} <= set(212 jsonnetfile_contents.keys()213 )214 assert jsonnetfile_contents["version"] == 1215 assert jsonnetfile_contents["legacyImports"]216 assert jsonnetfile_contents["dependencies"][0]["version"] == "1.18"217def test_render_jsonnetfile_json_warning(tmp_path: P, capsys):218 c = _setup_render_jsonnetfile_json(tmp_path)219 with open(tmp_path / "jsonnetfile.json", "w") as jf:220 jf.write("{}")221 c.repo.repo.index.add("*")222 c.repo.repo.index.commit("Add jsonnetfile.json")223 c.render_jsonnetfile_json(224 {"jsonnetfile_parameters": {"kube_prometheus_version": "1.18"}}225 )226 stdout, _ = capsys.readouterr()227 assert _render_jsonnetfile_json_error_string(c) in stdout228@pytest.mark.parametrize(229 "name,key",230 [231 ("simple", "simple"),232 ("simple-name", "simple_name"),233 ("some-other-name", "some_other_name"),234 ],235)236def test_component_parameters_key(name: str, key: str):237 assert component_parameters_key(name) == key238def _setup_libfiles(c: Component, libfiles: Iterable[str]):239 lib_dir = c.target_directory / "lib"240 if len(libfiles) > 0:241 lib_dir.mkdir(parents=True, exist_ok=True)242 for libf in libfiles:243 with open(lib_dir / libf, "w") as f:244 yaml.safe_dump({"libf": libf}, f)245@pytest.mark.parametrize(246 "libfiles",247 [248 [],249 ["foo.libsonnet"],250 ["foo.libsonnet", "bar.libsonnet"],251 ],252)253def test_component_lib_files(tmp_path: P, libfiles: Iterable[str]):254 c = _setup_component(tmp_path, name="tc1")255 _setup_libfiles(c, libfiles)256 assert sorted(c.lib_files) == sorted(tmp_path / "tc1" / "lib" / f for f in libfiles)257@pytest.mark.parametrize(258 "libfiles",259 [260 [],261 ["foo.libsonnet"],262 ["foo.libsonnet", "bar.libsonnet"],263 ],264)265def test_component_get_library(tmp_path: P, libfiles: Iterable[str]):266 c = _setup_component(tmp_path, name="tc1")267 _setup_libfiles(c, libfiles)268 if len(libfiles) == 0:269 assert c.get_library("foo.libsonnet") is None270 for f in libfiles:...

Full Screen

Full Screen

services.py

Source:services.py Github

copy

Full Screen

1from odoo import exceptions, http2from odoo.http import Controller, request3try:4 from odoo.addons.horanet_go.tools import git_source5 from odoo.addons.horanet_go import version6 from odoo.addons.horanet_web.tools import route7except ImportError:8 from horanet_go.tools import git_source9 from horanet_go import version10 from horanet_web.tools import route11class SourceVersion(Controller):12 @http.route(['/web/version'], type='http', auth="user", methods=['GET'], website=True)13 def page_module_version(self):14 if not request.env.user.has_group('base.group_system'):15 raise exceptions.AccessDenied()16 qcontext = {}17 horanet_go_module = request.env['ir.module.module'].search([('name', '=', 'horanet_go')])18 repo = git_source.get_module_git_repository(horanet_go_module)19 if repo:20 active_branch = repo.active_branch21 remote_branch = [b for b in repo.branches if b.path == repo.active_branch.path]22 remote_tag = [b for b in repo.tags if b.path == repo.active_branch.path]23 remote_branch = remote_branch[0] if remote_branch else None24 remote_tag = remote_tag[0] if remote_tag else None25 is_detached = False26 if remote_branch:27 is_detached = remote_branch.commit == active_branch.commit28 elif remote_tag:29 is_detached = remote_tag.commit == active_branch.commit30 qcontext.update({31 'version': version.__version__,32 'repo': {33 'active_branch': active_branch.name,34 'remote_branch': remote_branch and remote_branch.name or '',35 'remote_tag': remote_tag and remote_tag.name or '',36 'is_detached': is_detached,37 'status': repo.git.status(),38 'log': repo.git.log(max_count=100),39 }40 })41 return request.render('horanet_go.display_module_version', qcontext=qcontext)42 @route.jsonRoute(['/web/version/horanet'], auth='user', csrf=True)43 def horanet_version(self, **data):44 """45 Webservice JSON de récupération d'information sur le dépôt git d'horanet_go.46 :param data:47 :return: Dictionary with various informations about git repository48 """49 if not request.env.user.has_group('base.group_system'):50 raise exceptions.AccessDenied()51 horanet_go_module = request.env['ir.module.module'].search([('name', '=', 'horanet_go')])52 horanet_version = 'null'53 repo = git_source.get_module_git_repository(horanet_go_module)54 if repo:55 active_branch = repo.active_branch56 remote_branch = [b for b in repo.branches if b.path == repo.active_branch.path]57 remote_tag = [b for b in repo.tags if b.path == repo.active_branch.path]58 remote_branch = remote_branch[0] if remote_branch else None59 remote_tag = remote_tag[0] if remote_tag else None60 git_status = repo.git.status()61 git_log = repo.git.log(max_count=4)62 is_detached = False63 if remote_branch:64 is_detached = remote_branch.commit == active_branch.commit65 return {66 'version': str(horanet_version),67 'branch': repo.active_branch.name,68 'commit': repo.active_branch.commit.summary,69 'remote_tag': remote_tag,70 'git_status': git_status,71 'git_log': git_log,72 'is_detached': is_detached,73 }74 elif horanet_go_module:75 horanet_version = horanet_go_module.installed_version76 else:77 horanet_version = 'Impossible code to reach (using route on an uninstalled module ?!)'...

Full Screen

Full Screen

check_git_checkout_not_detached.py

Source:check_git_checkout_not_detached.py Github

copy

Full Screen

1#!/usr/bin/env python2# vim:ts=4:sts=4:sw=4:et3#4# Author: Hari Sekhon5# Date: 2016-07-25 14:57:36 +0100 (Mon, 25 Jul 2016)6#7# https://github.com/harisekhon/nagios-plugins8#9# License: see accompanying Hari Sekhon LICENSE file10#11# If you're using my code you're welcome to connect with me on LinkedIn12# and optionally send me feedback to help steer this or other code I publish13#14# https://www.linkedin.com/in/harisekhon15#16"""17Nagios Plugin to check a Git checkout working directory isn't in 'detached' state18Requires the 'git' command in the $PATH, otherwise you can set the path to the git19executable using the environment variable GIT_PYTHON_GIT_EXECUTABLE20"""21from __future__ import absolute_import22from __future__ import division23from __future__ import print_function24from __future__ import unicode_literals25import os26import sys27import traceback28import git29srcdir = os.path.abspath(os.path.dirname(__file__))30libdir = os.path.join(srcdir, 'pylib')31sys.path.append(libdir)32try:33 # pylint: disable=wrong-import-position34 from harisekhon.utils import CriticalError, validate_directory35 from harisekhon import NagiosPlugin36except ImportError as _:37 print(traceback.format_exc(), end='')38 sys.exit(4)39__author__ = 'Hari Sekhon'40__version__ = '0.1.1'41class CheckGitCheckoutDetached(NagiosPlugin):42 def __init__(self):43 # Python 2.x44 super(CheckGitCheckoutDetached, self).__init__()45 # Python 3.x46 # super().__init__()47 self.msg = 'CheckGitCheckoutDetached msg not defined'48 self.ok()49 def add_options(self):50 self.add_opt('-d', '--directory', action='store', help='Path to git checkout directory')51 def run(self):52 self.no_args()53 directory = self.get_opt('directory')54 validate_directory(directory)55 directory = os.path.abspath(directory)56 try:57 repo = git.Repo(directory)58 except git.InvalidGitRepositoryError:59 raise CriticalError("directory '{}' does not contain a valid Git repository!".format(directory))60 is_detached = repo.head.is_detached61 self.msg = "git checkout detached = '{}' for directory '{}'".format(is_detached, directory)62 if is_detached:63 self.critical()64if __name__ == '__main__':...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful