Search is not available for this dataset
text stringlengths 75 104k |
|---|
def update(self, obj, **kwargs):
"Update the tree item when the object name changes"
# search for the old name:
child = self.tree.FindItem(self.root, kwargs['name'])
if DEBUG: print "update child", child, kwargs
if child:
self.tree.ScrollTo(child)
self.tre... |
def show_context_menu(self, item, mouse_pos=None):
"Open a popup menu with options regarding the selected object"
if item:
d = self.tree.GetItemData(item)
if d:
obj = d.GetData()
if obj:
# highligh and store the selected object:... |
def set_parent(self, new_parent, init=False):
"Re-parent a child control with the new wx_obj parent (owner)"
##SubComponent.set_parent(self, new_parent, init)
self.wx_obj.SetOwner(new_parent.wx_obj.GetEventHandler()) |
def to_representation(self, value):
"""
Perform the actual serialization.
Args:
value: the image to transform
Returns:
a url pointing at a scaled and cached image
"""
if not value:
return None
image = get_thumbnail(value, self... |
def add_selector(name):
"""
Builds and registers a :class:`Selector` object with the given name and configuration.
Args:
name (str): The name of the selector.
Yields:
SelectorFactory: The factory that will build the :class:`Selector`.
"""
factory = SelectorFactory(name)
yi... |
def expression_filters(self):
""" Dict[str, ExpressionFilter]: Returns the expression filters for this selector. """
return {
name: filter for name, filter in iter(self.filters.items())
if isinstance(filter, ExpressionFilter)} |
def node_filters(self):
""" Dict[str, NodeFilter]: Returns the node filters for this selector. """
return {
name: filter for name, filter in iter(self.filters.items())
if isinstance(filter, NodeFilter)} |
def expression_filter(self, name, **kwargs):
"""
Returns a decorator function for adding an expression filter.
Args:
name (str): The name of the filter.
**kwargs: Variable keyword arguments for the filter.
Returns:
Callable[[Callable[[AbstractExpress... |
def node_filter(self, name, **kwargs):
"""
Returns a decorator function for adding a node filter.
Args:
name (str): The name of the filter.
**kwargs: Variable keyword arguments for the filter.
Returns:
Callable[[Callable[[Element, Any], bool]]]: A de... |
def filter_set(self, name):
"""
Adds filters from a particular global :class:`FilterSet`.
Args:
name (str): The name of the set whose filters should be added.
"""
filter_set = filter_sets[name]
for name, filter in iter(filter_set.filters.items()):
... |
def build_selector(self):
""" Selector: Returns a new :class:`Selector` instance with the current configuration. """
kwargs = {
'label': self.label,
'descriptions': self.descriptions,
'filters': self.filters}
if self.format == "xpath":
kwargs['xpa... |
def resolves_for(self, node):
"""
Resolves this query relative to the given node.
Args:
node (node.Base): The node to be evaluated.
Returns:
int: The number of matches found.
"""
self.node = node
self.actual_styles = node.style(*self.exp... |
def failure_message(self):
""" str: A message describing the query failure. """
return (
"Expected node to have styles {expected}. "
"Actual styles were {actual}").format(
expected=desc(self.expected_styles),
actual=desc(self.actual_styles)) |
def assert_current_path(self, path, **kwargs):
"""
Asserts that the page has the given path. By default this will compare against the
path+query portion of the full URL.
Args:
path (str | RegexObject): The string or regex that the current "path" should match.
**k... |
def assert_no_current_path(self, path, **kwargs):
"""
Asserts that the page doesn't have the given path.
Args:
path (str | RegexObject): The string or regex that the current "path" should match.
**kwargs: Arbitrary keyword arguments for :class:`CurrentPathQuery`.
... |
def has_current_path(self, path, **kwargs):
"""
Checks if the page has the given path.
Args:
path (str | RegexObject): The string or regex that the current "path" should match.
**kwargs: Arbitrary keyword arguments for :class:`CurrentPathQuery`.
Returns:
... |
def has_no_current_path(self, path, **kwargs):
"""
Checks if the page doesn't have the given path.
Args:
path (str | RegexObject): The string or regex that the current "path" should match.
**kwargs: Arbitrary keyword arguments for :class:`CurrentPathQuery`.
Retu... |
def text(self):
"""
Retrieve the text of the element. If :data:`capybara.ignore_hidden_elements` is ``True``,
which it is by default, then this will return only text which is visible. The exact
semantics of this may differ between drivers, but generally any text within elements with
... |
def select_option(self):
""" Select this node if it is an option element inside a select tag. """
if self.disabled:
warn("Attempt to select disabled option: {}".format(self.value or self.text))
self.base.select_option() |
def apply_filter(self, expr, value):
"""
Returns the given expression filtered by the given value.
Args:
expr (xpath.expression.AbstractExpression): The expression to filter.
value (object): The desired value with which the expression should be filtered.
Returns... |
def get_browser(browser_name, capabilities=None, **options):
"""
Returns an instance of the given browser with the given capabilities.
Args:
browser_name (str): The name of the desired browser.
capabilities (Dict[str, str | bool], optional): The desired capabilities of the browser.
... |
def kwargs(self):
""" Dict[str, Any]: The keyword arguments with which this query was initialized. """
kwargs = {}
kwargs.update(self.options)
kwargs.update(self.filter_options)
return kwargs |
def description(self):
""" str: A long description of this query. """
description = self.label
if self.locator:
description += " {}".format(desc(self.locator))
if self.options["text"] is not None:
description += " with text {}".format(desc(self.options["text"]))... |
def visible(self):
""" str: The desired element visibility. """
if self.options["visible"] is not None:
if self.options["visible"] is True:
return "visible"
elif self.options["visible"] is False:
return "all"
else:
retur... |
def xpath(self, exact=None):
"""
Returns the XPath query for this selector.
Args:
exact (bool, optional): Whether to exactly match text.
Returns:
str: The XPath query for this selector.
"""
exact = exact if exact is not None else self.exact
... |
def resolve_for(self, node, exact=None):
"""
Resolves this query relative to the given node.
Args:
node (node.Base): The node relative to which this query should be resolved.
exact (bool, optional): Whether to exactly match text.
Returns:
list[Elemen... |
def matches_filters(self, node):
"""
Returns whether the given node matches all filters.
Args:
node (Element): The node to evaluate.
Returns:
bool: Whether the given node matches.
"""
visible = self.visible
if self.options["text"]:
... |
def current_scope(self):
""" node.Base: The current node relative to which all interaction will be scoped. """
scope = self._scopes[-1]
if scope in [None, "frame"]:
scope = self.document
return scope |
def current_path(self):
""" str: Path of the current page, without any domain information. """
if not self.current_url:
return
path = urlparse(self.current_url).path
return path if path else None |
def current_host(self):
""" str: Host of the current page. """
if not self.current_url:
return
result = urlparse(self.current_url)
scheme, netloc = result.scheme, result.netloc
host = netloc.split(":")[0] if netloc else None
return "{0}://{1}".format(scheme,... |
def visit(self, visit_uri):
"""
Navigate to the given URL. The URL can either be a relative URL or an absolute URL. The
behavior of either depends on the driver. ::
session.visit("/foo")
session.visit("http://google.com")
For drivers which can run against an ext... |
def scope(self, *args, **kwargs):
"""
Executes the wrapped code within the context of a node. ``scope`` takes the same options
as :meth:`find`. For the duration of the context, any command to Capybara will be handled
as though it were scoped to the given element. ::
with sco... |
def frame(self, locator=None, *args, **kwargs):
"""
Execute the wrapped code within the given iframe using the given frame or frame name/id.
May not be supported by all drivers.
Args:
locator (str | Element, optional): The name/id of the frame or the frame's element.
... |
def switch_to_frame(self, frame):
"""
Switch to the given frame.
If you use this method you are responsible for making sure you switch back to the parent
frame when done in the frame changed to. :meth:`frame` is preferred over this method and
should be used when possible. May no... |
def switch_to_window(self, window, wait=None):
"""
If ``window`` is a lambda, it switches to the first window for which ``window`` returns a
value other than False or None. If a window that matches can't be found, the window will be
switched back and :exc:`WindowError` will be raised.
... |
def window(self, window):
"""
This method does the following:
1. Switches to the given window (it can be located by window instance/lambda/string).
2. Executes the given block (within window located at previous step).
3. Switches back (this step will be invoked even if exception... |
def window_opened_by(self, trigger_func, wait=None):
"""
Get the window that has been opened by the passed lambda. It will wait for it to be opened
(in the same way as other Capybara methods wait). It's better to use this method than
``windows[-1]`` `as order of windows isn't defined in ... |
def execute_script(self, script, *args):
"""
Execute the given script, not returning a result. This is useful for scripts that return
complex objects, such as jQuery statements. ``execute_script`` should be used over
:meth:`evaluate_script` whenever possible.
Args:
s... |
def evaluate_script(self, script, *args):
"""
Evaluate the given JavaScript and return the result. Be careful when using this with
scripts that return complex objects, such as jQuery statements. :meth:`execute_script`
might be a better alternative.
Args:
script (str)... |
def accept_alert(self, text=None, wait=None):
"""
Execute the wrapped code, accepting an alert.
Args:
text (str | RegexObject, optional): Text to match against the text in the modal.
wait (int | float, optional): Maximum time to wait for the modal to appear after
... |
def accept_confirm(self, text=None, wait=None):
"""
Execute the wrapped code, accepting a confirm.
Args:
text (str | RegexObject, optional): Text to match against the text in the modal.
wait (int | float, optional): Maximum time to wait for the modal to appear after
... |
def dismiss_confirm(self, text=None, wait=None):
"""
Execute the wrapped code, dismissing a confirm.
Args:
text (str | RegexObject, optional): Text to match against the text in the modal.
wait (int | float, optional): Maximum time to wait for the modal to appear after
... |
def accept_prompt(self, text=None, response=None, wait=None):
"""
Execute the wrapped code, accepting a prompt, optionally responding to the prompt.
Args:
text (str | RegexObject, optional): Text to match against the text in the modal.
response (str, optional): Response ... |
def dismiss_prompt(self, text=None, wait=None):
"""
Execute the wrapped code, dismissing a prompt.
Args:
text (str | RegexObject, optional): Text to match against the text in the modal.
wait (int | float, optional): Maximum time to wait for the modal to appear after
... |
def save_page(self, path=None):
"""
Save a snapshot of the page.
If invoked without arguments, it will save a file to :data:`capybara.save_path` and the
file will be given a randomly generated filename. If invoked with a relative path, the path
will be relative to :data:`capybar... |
def save_screenshot(self, path=None, **kwargs):
"""
Save a screenshot of the page.
If invoked without arguments, it will save a file to :data:`capybara.save_path` and the
file will be given a randomly generated filename. If invoked with a relative path, the path
will be relative... |
def reset(self):
"""
Reset the session (i.e., remove cookies and navigate to a blank page).
This method does not:
* accept modal dialogs if they are present (the Selenium driver does, but others may not),
* clear the browser cache/HTML 5 local storage/IndexedDB/Web SQL database/... |
def raise_server_error(self):
""" Raise errors encountered by the server. """
if self.server and self.server.error:
try:
if capybara.raise_server_errors:
raise self.server.error
finally:
self.server.reset_error() |
def matches(self, node, value):
"""
Returns whether the given node matches the filter rule with the given value.
Args:
node (Element): The node to filter.
value (object): The desired value with which the node should be evaluated.
Returns:
bool: Wheth... |
def get_version():
""" str: The package version. """
global_vars = {}
# Compile and execute the individual file to prevent
# the package from being automatically loaded.
source = read(os.path.join("capybara", "version.py"))
code = compile(source, "version.py", "exec")
exec(code, global_var... |
def resolves_for(self, node):
"""
Resolves this query relative to the given node.
Args:
node (node.Document): The node to be evaluated.
Returns:
bool: Whether the given node matches this query.
"""
self.actual_title = normalize_text(node.title)
... |
def frame_title(self):
""" str: The title for the current frame. """
elements = self._find_xpath("/html/head/title")
titles = [element.all_text for element in elements]
return titles[0] if len(titles) else "" |
def value(self):
""" str: The value of the form element. """
if self.tag_name == "textarea":
return inner_content(self.native)
elif self.tag_name == "select":
if self["multiple"] == "multiple":
selected_options = self._find_xpath(".//option[@selected='sel... |
def add_filter_set(name):
"""
Builds and registers a global :class:`FilterSet`.
Args:
name (str): The name of the set.
Yields:
FilterSetFactory: A configurable factory for building a :class:`FilterSet`.
"""
factory = FilterSetFactory(name)
yield factory
filter_sets[nam... |
def current_session():
"""
Returns the :class:`Session` for the current driver and app, instantiating one if needed.
Returns:
Session: The :class:`Session` for the current driver and app.
"""
driver = current_driver or default_driver
session_key = "{driver}:{session}:{app}".format(
... |
def has_all_of_selectors(self, selector, *locators, **kwargs):
"""
Checks if allof the provided selectors are present on the given page or descendants of the
current node. If options are provided, the assertion will check that each locator is present
with those options as well (other tha... |
def has_none_of_selectors(self, selector, *locators, **kwargs):
"""
Checks if none of the provided selectors are present on the given page or descendants of the
current node. If options are provided, the assertion will check that each locator is present
with those options as well (other ... |
def assert_selector(self, *args, **kwargs):
"""
Asserts that a given selector is on the page or a descendant of the current node. ::
page.assert_selector("p#foo")
By default it will check if the expression occurs at least once, but a different number can
be specified. ::
... |
def assert_style(self, styles, **kwargs):
"""
Asserts that an element has the specified CSS styles. ::
element.assert_style({"color": "rgb(0,0,255)", "font-size": re.compile(r"px")})
Args:
styles (Dict[str, str | RegexObject]): The expected styles.
Returns:
... |
def assert_all_of_selectors(self, selector, *locators, **kwargs):
"""
Asserts that all of the provided selectors are present on the given page or descendants of
the current node. If options are provided, the assertion will check that each locator is
present with those options as well (ot... |
def assert_none_of_selectors(self, selector, *locators, **kwargs):
"""
Asserts that none of the provided selectors are present on the given page or descendants of
the current node. If options are provided, the assertion will check that each locator is
present with those options as well (... |
def assert_no_selector(self, *args, **kwargs):
"""
Asserts that a given selector is not on the page or a descendant of the current node. Usage
is identical to :meth:`assert_selector`.
Query options such as ``count``, ``minimum``, and ``between`` are considered to be an
integral ... |
def assert_matches_selector(self, *args, **kwargs):
"""
Asserts that the current node matches a given selector. ::
node.assert_matches_selector("p#foo")
node.assert_matches_selector("xpath", "//p[@id='foo']")
It also accepts all options that :meth:`find_all` accepts, su... |
def has_checked_field(self, locator, **kwargs):
"""
Checks if the page or current node has a radio button or checkbox with the given label,
value, or id, that is currently checked.
Args:
locator (str): The label, name, or id of a checked field.
**kwargs: Arbitrar... |
def has_no_checked_field(self, locator, **kwargs):
"""
Checks if the page or current node has no radio button or checkbox with the given label,
value, or id that is currently checked.
Args:
locator (str): The label, name, or id of a checked field.
**kwargs: Arbit... |
def has_unchecked_field(self, locator, **kwargs):
"""
Checks if the page or current node has a radio button or checkbox with the given label,
value, or id, that is currently unchecked.
Args:
locator (str): The label, name, or id of an unchecked field.
**kwargs: A... |
def has_no_unchecked_field(self, locator, **kwargs):
"""
Checks if the page or current node has no radio button or checkbox with the given label,
value, or id, that is currently unchecked.
Args:
locator (str): The label, name, or id of an unchecked field.
**kwarg... |
def assert_text(self, *args, **kwargs):
"""
Asserts that the page or current node has the given text content, ignoring any HTML tags.
Args:
*args: Variable length argument list for :class:`TextQuery`.
**kwargs: Arbitrary keyword arguments for :class:`TextQuery`.
... |
def assert_no_text(self, *args, **kwargs):
"""
Asserts that the page or current node doesn't have the given text content, ignoring any
HTML tags.
Args:
*args: Variable length argument list for :class:`TextQuery`.
**kwargs: Arbitrary keyword arguments for :class:`... |
def assert_title(self, title, **kwargs):
"""
Asserts that the page has the given title.
Args:
title (str | RegexObject): The string or regex that the title should match.
**kwargs: Arbitrary keyword arguments for :class:`TitleQuery`.
Returns:
True
... |
def assert_no_title(self, title, **kwargs):
"""
Asserts that the page doesn't have the given title.
Args:
title (str | RegexObject): The string that the title should include.
**kwargs: Arbitrary keyword arguments for :class:`TitleQuery`.
Returns:
Tru... |
def has_title(self, title, **kwargs):
"""
Checks if the page has the given title.
Args:
title (str | RegexObject): The string or regex that the title should match.
**kwargs: Arbitrary keyword arguments for :class:`TitleQuery`.
Returns:
bool: Whether ... |
def has_no_title(self, title, **kwargs):
"""
Checks if the page doesn't have the given title.
Args:
title (str | RegexObject): The string that the title should include.
**kwargs: Arbitrary keyword arguments for :class:`TitleQuery`.
Returns:
bool: Whe... |
def find_all(self, *args, **kwargs):
"""
Find all elements on the page matching the given selector and options.
Both XPath and CSS expressions are supported, but Capybara does not try to automatically
distinguish between them. The following statements are equivalent::
page.... |
def find_first(self, *args, **kwargs):
"""
Find the first element on the page matching the given selector and options, or None if no
element matches.
By default, no waiting behavior occurs. However, if ``capybara.wait_on_first_by_default``
is set to true, it will trigger Capybar... |
def resolve_for(self, node):
"""
Resolves this query relative to the given node.
Args:
node (node.Base): The node to be evaluated.
Returns:
int: The number of matches found.
"""
self.node = node
self.actual_text = normalize_text(
... |
def inner_content(node):
"""
Returns the inner content of a given XML node, including tags.
Args:
node (lxml.etree.Element): The node whose inner content is desired.
Returns:
str: The inner content of the node.
"""
from lxml import etree
# Include text content at the star... |
def inner_text(node):
"""
Returns the inner text of a given XML node, excluding tags.
Args:
node: (lxml.etree.Element): The node whose inner text is desired.
Returns:
str: The inner text of the node.
"""
from lxml import etree
# Include text content at the start of the no... |
def normalize_url(url):
"""
Returns the given URL with all query keys properly escaped.
Args:
url (str): The URL to normalize.
Returns:
str: The normalized URL.
"""
uri = urlparse(url)
query = uri.query or ""
pairs = parse_qsl(query)
decoded_pairs = [(unquote(key)... |
def setter_decorator(fset):
"""
Define a write-only property that, in addition to the given setter function, also
provides a setter decorator defined as the property's getter function.
This allows one to set the property either through traditional assignment, as a
method argument, or through decora... |
def _valid_value(self, value):
""" bool: Whether the given value is valid. """
if not self.valid_values:
return True
valid_values = (self.valid_values if isinstance(self.valid_values, list)
else list(self.valid_values))
return value in valid_values |
def attach_file(self, locator_or_path, path=None, **kwargs):
"""
Find a file field on the page and attach a file given its path. The file field can be found
via its name, id, or label text. ::
page.attach_file(locator, "/path/to/file.png")
Args:
locator_or_path ... |
def check(self, locator=None, allow_label_click=None, **kwargs):
"""
Find a check box and mark it as checked. The check box can be found via name, id, or label
text. ::
page.check("German")
Args:
locator (str, optional): Which check box to check.
all... |
def choose(self, locator=None, allow_label_click=None, **kwargs):
"""
Find a radio button and mark it as checked. The radio button can be found via name, id, or
label text. ::
page.choose("Male")
Args:
locator (str, optional): Which radio button to choose.
... |
def fill_in(self, locator=None, current_value=None, value=None, fill_options=None, **kwargs):
"""
Locate a text field or text area and fill it in with the given text. The field can be found
via its name, id, or label text. ::
page.fill_in("Name", value="Bob")
Args:
... |
def select(self, value=None, field=None, **kwargs):
"""
If the ``field`` argument is present, ``select`` finds a select box on the page and selects
a particular option from it. Otherwise it finds an option inside the current scope and
selects it. If the select box is a multiple select, `... |
def uncheck(self, locator=None, allow_label_click=None, **kwargs):
"""
Find a check box and uncheck it. The check box can be found via name, id, or label text. ::
page.uncheck("German")
Args:
locator (str, optional): Which check box to uncheck.
allow_label_c... |
def unselect(self, value=None, field=None, **kwargs):
"""
Find a select box on the page and unselect a particular option from it. If the select box is
a multiple select, ``unselect`` can be called multiple times to unselect more than one
option. The select box can be found via its name, ... |
def _check_with_label(self, selector, checked, locator=None, allow_label_click=None, visible=None, wait=None,
**kwargs):
"""
Args:
selector (str): The selector for the type of element that should be checked/unchecked.
checked (bool): Whether the element ... |
def synchronize(func):
""" Decorator for :meth:`synchronize`. """
@wraps(func)
def outer(self, *args, **kwargs):
@self.synchronize
def inner(self, *args, **kwargs):
return func(self, *args, **kwargs)
return inner(self, *args, **kwargs)
return outer |
def synchronize(self, func=None, wait=None, errors=()):
"""
This method is Capybara's primary defense against asynchronicity problems. It works by
attempting to run a given decorated function until it succeeds. The exact behavior of this
method depends on a number of factors. Basically t... |
def _should_catch_error(self, error, errors=()):
"""
Returns whether to catch the given error.
Args:
error (Exception): The error to consider.
errors (Tuple[Type[Exception], ...], optional): The exception types that should be
caught. Defaults to :class:`E... |
def compare_count(self):
"""
Returns how the result count compares to the query options.
The return value is negative if too few results were found, zero if enough were found, and
positive if too many were found.
Returns:
int: -1, 0, or 1.
"""
if se... |
def failure_message(self):
""" str: A message describing the query failure. """
message = failure_message(self.query.description, self.query.options)
if len(self) > 0:
message += ", found {count} {matches}: {results}".format(
count=len(self),
matches... |
def _cache_at_least(self, size):
"""
Attempts to fill the result cache with at least the given number of results.
Returns:
bool: Whether the cache contains at least the given size.
"""
try:
while len(self._result_cache) < size:
self._resu... |
def desc(value):
""" str: A normalized representation for a user-provided value. """
def normalize_strings(value):
if isinstance(value, list):
value = [normalize_strings(e) for e in value]
if isinstance(value, dict):
value = {normalize_strings(k): normalize_strings(v) f... |
def expects_none(options):
"""
Returns whether the given query options expect a possible count of zero.
Args:
options (Dict[str, int | Iterable[int]]): A dictionary of query options.
Returns:
bool: Whether a possible count of zero is expected.
"""
if any(options.get(key) is no... |
def failure_message(description, options):
"""
Returns a expectation failure message for the given query description.
Args:
description (str): A description of the failed query.
options (Dict[str, Any]): The query options.
Returns:
str: A message describing the failure.
"""... |
def matches_count(count, options):
"""
Returns whether the given count matches the given query options.
If no quantity options are specified, any count is considered acceptable.
Args:
count (int): The count to be validated.
options (Dict[str, int | Iterable[int]]): A dictionary of quer... |
def normalize_text(value):
"""
Normalizes the given value to a string of text with extra whitespace removed.
Byte sequences are decoded. ``None`` is converted to an empty string. Everything else
is simply cast to a string.
Args:
value (Any): The data to normalize.
Returns:
str... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.