本文整理汇总了Python中tests.compat.u函数的典型用法代码示例。如果您正苦于以下问题:Python u函数的具体用法?Python u怎么用?Python u使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了u函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_click_u
def test_click_u(self):
app = webtest.TestApp(links_app)
resp = app.get('/utf8/')
self.assertIn(u("Тестовая страница"), resp)
self.assertIn('This is foo.', resp.click(u('Менделеев')))
self.assertIn('This is baz.', resp.click(anchor=u(".*title='Поэт'.*")))
开发者ID:lepilepi,项目名称:webtest,代码行数:7,代码来源:test_click.py
示例2: test_unicode_substring
def test_unicode_substring(self):
pattern = u('\u03A3\u0393')
text = u('\u03A0\u03A3\u0393\u0394')
self.expectedOutcomes(
self.search(pattern, text, max_subs=0),
[Match(1, 3, 0)]
)
开发者ID:taleinat,项目名称:fuzzysearch,代码行数:7,代码来源:test_substitutions_only.py
示例3: select_app_unicode
def select_app_unicode(environ, start_response):
req = Request(environ)
status = b"200 OK"
if req.method == "GET":
body = u(
"""
<html>
<head><title>form page</title></head>
<body>
<form method="POST" id="single_select_form">
<select id="single" name="single">
<option value="ЕКБ">Екатеринбург</option>
<option value="МСК" selected="selected">Москва</option>
<option value="СПБ">Санкт-Петербург</option>
<option value="САМ">Самара</option>
</select>
<input name="button" type="submit" value="single">
</form>
<form method="POST" id="multiple_select_form">
<select id="multiple" name="multiple" multiple="multiple">
<option value="8" selected="selected">Лондон</option>
<option value="9">Париж</option>
<option value="10">Пекин</option>
<option value="11" selected="selected">Бристоль</option>
</select>
<input name="button" type="submit" value="multiple">
</form>
</body>
</html>
"""
).encode("utf8")
else:
select_type = req.POST.get("button")
if select_type == "single":
selection = req.POST.get("single")
elif select_type == "multiple":
selection = ", ".join(req.POST.getall("multiple"))
body = (
u(
"""
<html>
<head><title>display page</title></head>
<body>
<p>You submitted the %(select_type)s </p>
<p>You selected %(selection)s</p>
</body>
</html>
"""
)
% dict(selection=selection, select_type=select_type)
).encode("utf8")
headers = [("Content-Type", "text/html; charset=utf-8"), ("Content-Length", str(len(body)))]
start_response(status, headers)
if not isinstance(body, binary_type):
raise AssertionError("Body is not %s" % binary_type)
return [body]
开发者ID:jollychang,项目名称:webtest,代码行数:56,代码来源:test_forms.py
示例4: links_app
def links_app(environ, start_response):
req = Request(environ)
status = "200 OK"
responses = {
'/': """
<html>
<head><title>page with links</title></head>
<body>
<a href="/foo/">Foo</a>
<a href='bar'>Bar</a>
<a href='baz/' id='id_baz'>Baz</a>
<a href='#' id='fake_baz'>Baz</a>
<a href='javascript:alert("123")' id='js_baz'>Baz</a>
<script>
var link = "<a href='/boo/'>Boo</a>";
</script>
<a href='/spam/'>Click me!</a>
<a href='/egg/'>Click me!</a>
</body>
</html>
""",
'/foo/': '<html><body>This is foo. <a href="bar">Bar</a> </body></html>',
'/foo/bar': '<html><body>This is foobar.</body></html>',
'/bar': '<html><body>This is bar.</body></html>',
'/baz/': '<html><body>This is baz.</body></html>',
'/spam/': '<html><body>This is spam.</body></html>',
'/egg/': '<html><body>Just eggs.</body></html>',
'/utf8/': u("""
<html>
<head><title>Тестовая страница</title></head>
<body>
<a href='/foo/'>Менделеев</a>
<a href='/baz/' title='Поэт'>Пушкин</a>
<img src='/egg/' title='Поэт'>
<script>
var link = "<a href='/boo/'>Злодейская ссылка</a>";
</script>
</body>
</html>
""").encode('utf8'),
}
utf8_paths = ['/utf8/']
body = responses[u(req.path_info)]
headers = [
('Content-Type', 'text/html'),
('Content-Length', str(len(body)))
]
if req.path_info in utf8_paths:
headers[0] = ('Content-Type', 'text/html; charset=utf-8')
start_response(status, headers)
return [to_bytes(body)]
开发者ID:lepilepi,项目名称:webtest,代码行数:55,代码来源:test_click.py
示例5: test_parse_attrs
def test_parse_attrs(self):
self.assertEqual(_parse_attrs("href='foo'"), {'href': 'foo'})
self.assertEqual(_parse_attrs('href="foo"'), {'href': 'foo'})
self.assertEqual(_parse_attrs('href=""'), {'href': ''})
self.assertEqual(_parse_attrs('href="foo" id="bar"'), {'href': 'foo', 'id': 'bar'})
self.assertEqual(_parse_attrs('href="foo" id="bar"'), {'href': 'foo', 'id': 'bar'})
self.assertEqual(_parse_attrs("href='foo' id=\"bar\" "), {'href': 'foo', 'id': 'bar'})
self.assertEqual(_parse_attrs("href='foo' id='bar' "), {'href': 'foo', 'id': 'bar'})
self.assertEqual(_parse_attrs("tag='foo\"'"), {'tag': 'foo"'})
self.assertEqual(
_parse_attrs('value="<>&"{"'),
{'value': u('<>&"{')})
self.assertEqual(_parse_attrs('value="∑"'), {'value': u('∑')})
self.assertEqual(_parse_attrs('value="€"'), {'value': u('€')})
开发者ID:ailling,项目名称:webtest,代码行数:14,代码来源:test_click.py
示例6: test_click_utf8
def test_click_utf8(self):
app = webtest.TestApp(links_app, use_unicode=False)
resp = app.get('/utf8/')
self.assertEqual(resp.charset, 'utf-8')
if not PY3:
# No need to deal with that in Py3
self.assertIn(u("Тестовая страница").encode('utf8'), resp)
self.assertIn(u("Тестовая страница"), resp)
target = u('Менделеев').encode('utf8')
self.assertIn('This is foo.', resp.click(target))
# should skip the img tag
anchor = u(".*title='Поэт'.*")
anchor_re = anchor.encode('utf8')
self.assertIn('This is baz.', resp.click(anchor=anchor_re))
开发者ID:lepilepi,项目名称:webtest,代码行数:15,代码来源:test_click.py
示例7: test_unicode_encodings
def test_unicode_encodings(self):
needle = u('PATTERN')
haystack = u('---PATERN---')
for encoding in ['ascii', 'latin-1', 'latin1', 'utf-8', 'utf-16']:
with self.subTest(encoding=encoding):
with tempfile.NamedTemporaryFile(mode='wb', delete=False) as f:
filename = f.name
f.write(haystack.encode(encoding))
self.addCleanup(os.remove, filename)
with io.open(filename, 'r', encoding=encoding) as f:
self.assertEqual(
find_near_matches_in_file(needle, f, max_l_dist=1),
[Match(3, 9, 1)],
)
开发者ID:taleinat,项目名称:fuzzysearch,代码行数:15,代码来源:test_find_near_matches_in_file.py
示例8: test_app_error
def test_app_error(self):
res = self.app.get('/')
res.charset = 'utf-8'
res.text = u('°C')
AppError('%s %s %s %s', res.status, '', res.request.url, res)
res.charset = None
AppError('%s %s %s %s', res.status, '', res.request.url, res)
开发者ID:ailling,项目名称:webtest,代码行数:7,代码来源:test_testing.py
示例9: input_unicode_app
def input_unicode_app(environ, start_response):
req = Request(environ)
status = "200 OK"
body =\
u("""
<html>
<head><title>form page</title></head>
<body>
<form method="POST" id="text_input_form">
<input name="foo" type="text" value="Хармс">
<input name="button" type="submit" value="Сохранить">
</form>
<form method="POST" id="radio_input_form">
<input name="foo" type="radio" value="Хармс">
<input name="foo" type="radio" value="Блок" checked>
<input name="button" type="submit" value="Сохранить">
</form>
<form method="POST" id="checkbox_input_form">
<input name="foo" type="checkbox" value="Хармс" checked>
<input name="button" type="submit" value="Ура">
</form>
</body>
</html>
""").encode('utf8')
headers = [
('Content-Type', 'text/html; charset=utf-8'),
('Content-Length', str(len(body)))]
start_response(status, headers)
return [body]
开发者ID:ailling,项目名称:webtest,代码行数:29,代码来源:test_input.py
示例10: application
def application(environ, start_response):
req = webob.Request(environ)
resp = webob.Response()
if req.method == 'GET':
filename = req.path_info.strip('/') or 'index.html'
if filename in ('302',):
redirect = req.params['redirect']
resp = exc.HTTPFound(location=redirect)
return resp(environ, start_response)
if filename.isdigit():
resp.status = filename
filename = 'index.html'
filename = os.path.join(files, 'html', filename)
if os.path.isfile(filename):
kw = dict(message=req.params.get('message', ''),
redirect=req.params.get('redirect', ''))
resp.unicode_body = u(open(filename).read()) % kw
_, ext = os.path.splitext(filename)
if ext == '.html':
resp.content_type = 'text/html'
elif ext == '.js':
resp.content_type = 'text/javascript'
elif ext == '.json':
resp.content_type = 'application/json'
else:
redirect = req.params.get('redirect', '')
if redirect:
resp = exc.HTTPFound(location=redirect)
else:
resp.body = req.body
return resp(environ, start_response)
开发者ID:fcavro,项目名称:webtest,代码行数:31,代码来源:test_selenium.py
示例11: test_print_stderr
def test_print_stderr(self):
res = self.app.get('/')
res.charset = 'utf-8'
res.text = u('°C')
print_stderr(str(res))
res.charset = None
print_stderr(str(res))
开发者ID:ailling,项目名称:webtest,代码行数:8,代码来源:test_testing.py
示例12: test_upload_invalid_content
def test_upload_invalid_content(self):
app = webtest.TestApp(SingleUploadFileApp())
res = app.get("/")
single_form = res.forms["file_upload_form"]
single_form.set("file-field", ("my_file.dat", 1))
try:
single_form.submit("button")
except ValueError:
e = sys.exc_info()[1]
self.assertEquals(six.text_type(e), u("File content must be %s not %s" % (binary_type, int)))
开发者ID:jollychang,项目名称:webtest,代码行数:10,代码来源:test_forms.py
示例13: test_exception_repr
def test_exception_repr(self):
res = self.app.get('/')
res.charset = 'utf-8'
res.text = u('°C')
if not PY3:
unicode(AssertionError(res))
str(AssertionError(res))
res.charset = None
if not PY3:
unicode(AssertionError(res))
str(AssertionError(res))
开发者ID:ailling,项目名称:webtest,代码行数:11,代码来源:test_testing.py
示例14: test_input_unicode
def test_input_unicode(self):
app = self.callFUT("form_unicode_inputs.html")
res = app.get("/form.html")
self.assertEqual(res.status_int, 200)
self.assertTrue(res.content_type.startswith("text/html"))
self.assertEqual(res.charset.lower(), "utf-8")
form = res.forms["text_input_form"]
self.assertEqual(form["foo"].value, u("Хармс"))
self.assertEqual(form.submit_fields(), [("foo", u("Хармс"))])
form = res.forms["radio_input_form"]
self.assertEqual(form["foo"].value, u("Блок"))
self.assertEqual(form.submit_fields(), [("foo", u("Блок"))])
form = res.forms["checkbox_input_form"]
self.assertEqual(form["foo"].value, u("Хармс"))
self.assertEqual(form.submit_fields(), [("foo", u("Хармс"))])
form = res.forms["password_input_form"]
self.assertEqual(form["foo"].value, u("Хармс"))
self.assertEqual(form.submit_fields(), [("foo", u("Хармс"))])
开发者ID:jollychang,项目名称:webtest,代码行数:22,代码来源:test_forms.py
示例15: test_input_unicode
def test_input_unicode(self):
app = webtest.TestApp(input_unicode_app)
res = app.get('/')
self.assertEqual(res.status_int, 200)
self.assertEqual(res.content_type, 'text/html')
self.assertEqual(res.charset, 'utf-8')
form = res.forms['text_input_form']
self.assertEqual(form['foo'].value, u('Хармс'))
self.assertEqual(form.submit_fields(), [('foo', u('Хармс'))])
form = res.forms['radio_input_form']
self.assertEqual(form['foo'].value, u('Блок'))
self.assertEqual(form.submit_fields(), [('foo', u('Блок'))])
form = res.forms['checkbox_input_form']
self.assertEqual(form['foo'].value, u('Хармс'))
self.assertEqual(form.submit_fields(), [('foo', u('Хармс'))])
form = res.forms['password_input_form']
self.assertEqual(form['foo'].value, u('Хармс'))
self.assertEqual(form.submit_fields(), [('foo', u('Хармс'))])
开发者ID:diarmuidbourke,项目名称:webtest,代码行数:22,代码来源:test_forms.py
示例16: test_unicode_select
def test_unicode_select(self):
app = webtest.TestApp(select_app_unicode)
res = app.get('/')
single_form = res.forms["single_select_form"]
self.assertEqual(single_form["single"].value, u("МСК"))
display = single_form.submit("button")
self.assertIn(u("<p>You selected МСК</p>"), display, display)
res = app.get('/')
single_form = res.forms["single_select_form"]
self.assertEqual(single_form["single"].value, u("МСК"))
single_form.set("single", u("СПБ"))
self.assertEqual(single_form["single"].value, u("СПБ"))
display = single_form.submit("button")
self.assertIn(u("<p>You selected СПБ</p>"), display, display)
开发者ID:lyndsysimon,项目名称:webtest,代码行数:16,代码来源:test_forms.py
示例17: test_button_submit
def test_button_submit(self):
form = self.callFUT(formid="multiple_buttons_form")
display = form.submit("action")
self.assertIn(u("action=deactivate"), display, display)
开发者ID:pombredanne,项目名称:webtest,代码行数:4,代码来源:test_forms.py
示例18: test_unicode_subsequence
def test_unicode_subsequence(self):
self.assertEqual(self.search(u('\u03A3\u0393'), u('\u03A0\u03A3\u0393\u0394')), [1])
开发者ID:taleinat,项目名称:fuzzysearch,代码行数:2,代码来源:test_search_exact.py
示例19: test_print_unicode
def test_print_unicode():
print_stderr(u('°C'))
开发者ID:ailling,项目名称:webtest,代码行数:2,代码来源:test_testing.py
示例20: test_button_submit_by_value
def test_button_submit_by_value(self):
form = self.callFUT(formid='multiple_buttons_form')
display = form.submit('action', value='activate')
self.assertIn(u("action=activate"), display, display)
开发者ID:SamuelMarks,项目名称:webtest,代码行数:4,代码来源:test_forms.py
注:本文中的tests.compat.u函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论