Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def html_return_the_html_string(context):
"Element().html() returns the html string"
dom = DOM(context.html)
p = dom.find("#the-only-paragraph").first()
assert that(p.html()).equals(
'<p id="the-only-paragraph">the only one in th whole damn thing!?</p>'
)
def attr_changes_a_attribute(context):
"attr retrieves attributes each attribute by name"
dom = DOM(context.html)
ul = dom.find("#objects").first()
ul.attr('id', 'list-of-stuff')
assert that(ul.attr('id')).equals('list-of-stuff')
assert that(ul.html()).looks_like(
'<ul id="list-of-stuff" class="list no-bullets">\n'
' <li id="ball" class="geometry">to kick</li>\n'</ul>
def select_by_class(context):
"selecting by class name"
dom = DOM(context.html)
div = dom.find(".nothiddendiv").first()
assert that(div).is_a(Element)
assert that(div.attribute['id']).equals("nothiddendiv")
assert that(div.attribute['style']).has("height:1px;")
assert that(div.attribute['style']).has("background:white;")
def test_single_scenario_single_scenario():
"Features should have at least the first scenario parsed with tags"
feature = Feature.from_string(FEATURE11)
first_scenario = feature.scenarios[0]
assert that(first_scenario.tags).deep_equals([
'many', 'other', 'basic', 'tags', 'here', ':)'])
def error_tolerance_for_non_well_formed_html(context):
"DOM(html) ignores a non-well-formed HTML"
parsed = DOM(context.html)
assert that(parsed).is_a(DOM)
head = parsed.find("head title").first()
assert that(head.text()).equals(u"Gabriel Falcão's page")
a, div, p = parsed.find("body *")
assert that(a.text()).equals("My Profile")
assert that(a.attr("href")).equals("http://github.com/gabrielfalcao")
assert that(div.text()).looks_like("")
assert that(div.attr("id")).equals("test")
assert that(p.text()).equals("Paragraph")
def text_modifies_the_text_within_element(context):
"Element().text('new text') modifies the text content"
dom = DOM(
'<div class="drinks">\n'
' <h1 id="header">I like piña colada!</h1>\n'
'</div>'
)
h1 = dom.find("div.drinks h1").first()
assert that(h1.text()).equals("I like piña colada!")
h1.text('Do you like vodka?')
assert that(h1.text()).equals("Do you like vodka?")
assert that(h1.html()).equals('<h1 id="header">Do you like vodka?</h1>')
assert that(dom.html()).equals(
'<div class="drinks">\n'
' <h1 id="header">Do you like vodka?</h1>\n'</div>
def first_returns_the_first(context):
"selecting all childs of some element"
dom = DOM(context.html)
elements = dom.find("#objects li")
p = elements.first()
assert that(p).is_a(Element)
assert that(p.tag).equals("li")
assert that(p.attribute['id']).equals("ball")
assert that(p.text()).equals("to kick")
def first_returns_the_first(context):
"selecting all childs of some element"
dom = DOM(context.html)
elements = dom.find("#objects li")
p = elements.first()
assert that(p).is_a(Element)
assert that(p.tag).equals("li")
assert that(p.attribute['id']).equals("ball")
assert that(p.text()).equals("to kick")
exists):
u"get_paths_for also takes paths, and check if exists"
find_module.side_effect = ImportError('no module named /some/path')
exists.side_effect = lambda x: x == '/path/to/file.py'
expected_paths = context.runner.get_paths_for(
['/path/to/file.py'],
appending=['more', 'members'],
)
assert that(expected_paths).equals(['/path/to/file.py'])
find_module.assert_called_once_with('/path/to/file.py')
assert that(load_module.call_count).equals(0)
def mock_get_paths_for(names, appending):
k = expected_kinds.pop(0)
assert that(names).is_a(list)
assert that(appending).is_a(list)
assert that(names).equals(['john', 'doe'])
assert that(appending).equals(['tests', k])
return [
'/apps/john/tests/%s' % k,
'/apps/doe/tests/%s' % k,
]