Debian Codegraph @

test/unit/selenium/webdriver/remote/subtyping_tests.py

raw symbols SCIP
1 # Licensed to the Software Freedom Conservancy (SFC) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The SFC licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17
18
19 from selenium.webdriver.remote.webdriver import WebDriver
20 from selenium.webdriver.remote.webdriver import WebElement
21
22
23 def test_web_element_not_subclassed():
24 """A registered subtype of WebElement should work with isinstance checks."""
25
26 class MyWebElement:
27 def __init__(self, parent, id, _w3c=True):
28 self.parent = parent
29 self.id = id
30 self._w3c = _w3c
31
32 # Test that non registered class instance is not instance of Remote WebElement
33 my_web_element = MyWebElement("parent", "1")
34 assert not isinstance(my_web_element, WebElement)
35
36 # Register the class as a subtype of WebElement
37 WebElement.register(MyWebElement)
38 my_registered_web_element = MyWebElement("parent", "2")
39
40 assert isinstance(my_registered_web_element, WebElement)
41
42
43 def test_webdriver_not_subclassed():
44 """A registered subtype of WebDriver should work with isinstance checks."""
45
46 class MyWebDriver:
47 def __init__(self, *args, **kwargs):
48 super().__init__(*args, **kwargs)
49
50 # Test that non registered class instance is not instance of Remote WebDriver
51 my_driver = MyWebDriver()
52 assert not isinstance(my_driver, WebDriver)
53
54 # Register the class as a subtype of WebDriver
55 WebDriver.register(MyWebDriver)
56 my_registered_driver = MyWebDriver()
57
58 assert isinstance(my_registered_driver, MyWebDriver)