def test_transaction_specification_for_avtalegiro_payment_request(
tn, ln, cn, text):
original = netsgiro.records.TransactionSpecification(
service_code=netsgiro.ServiceCode.AVTALEGIRO,
transaction_type=(
netsgiro.TransactionType.AVTALEGIRO_WITH_BANK_NOTIFICATION),
transaction_number=tn,
line_number=ln,
column_number=cn,
text=text,
)
ocr = original.to_ocr()
record = netsgiro.records.TransactionSpecification.from_string(ocr)
assert record.transaction_number == tn
assert record.line_number == ln
assert record.column_number == cn
assert len(record.text) == 40
assert record.text == original.text
python类text()的实例源码
def test_can_return_text_even_with_binary_content_type_configured(
create_event):
demo = app.Chalice('demo-app')
@demo.route('/index')
def index_view():
return app.Response(
status_code=200,
body='Plain text',
headers={'Content-Type': 'text/plain'})
event = create_event('/index', 'GET', {})
event['headers']['Accept'] = 'application/octet-stream'
response = demo(event, context=None)
assert response['statusCode'] == 200
assert response['body'] == 'Plain text'
assert response['headers']['Content-Type'] == 'text/plain'
def spark_application(app_id):
"""Mock of the Spark jobs REST resource."""
if 'last' in request.args:
return jsonify(redis.get(request.base_url))
d = st.fixed_dictionaries({
'jobId': st.integers(0),
'name': st.text(),
'submissionTime': st.text(),
'completionTime': st.text(),
'stageIds': st.lists(st.integers(0), average_size=3),
'status': st.sampled_from(['SUCCEEDED', 'RUNNING', 'FAILED']),
'numTasks': st.integers(0),
'numActiveTasks': st.integers(0),
'numCompletedTasks': st.integers(0),
'numSkippedTasks': st.integers(0),
'numFailedTasks': st.integers(0),
'numActiveStages': st.integers(0),
'numCompletedStages': st.integers(0),
'numSkippedStages': st.integers(0),
'numFailedStages': st.integers(0),
})
result = json.dumps(st.lists(d, average_size=3).example())
redis.set(request.base_url, result)
return jsonify(result)
def services(
draw,
ids=uuids(),
names=text(),
descriptions=text(),
registration_schemas=dictionaries(text(), text()),
result_schemas=dictionaries(text(), text()),
are_available=booleans(),
service_job_lists=job_lists(),
timeouts=timedeltas()
) -> ServiceInterface:
return Service(
draw(ids), draw(names), draw(descriptions),
draw(registration_schemas), draw(result_schemas),
draw(are_available), draw(service_job_lists),
draw(timeouts)
)
def dns_labels():
"""
Strategy for generating limited charset DNS labels.
"""
# This is too limited, but whatever
return (
s.text(
u'abcdefghijklmnopqrstuvwxyz0123456789-',
min_size=1, max_size=25)
.filter(
lambda s: not any([
s.startswith(u'-'),
s.endswith(u'-'),
s.isdigit(),
s[2:4] == u'--',
])))
def test_fsnative(text):
assert isinstance(fsnative(text), fsnative)
def test_text2fsn(text):
assert isinstance(text2fsn(text), fsnative)
def test_text_fsn_roudntrip(text):
if u"\x00" in text:
return
assert isinstance(fsn2text(text2fsn(text)), text_type)
def digits(min_size=10, max_size=None):
max_size = max_size or min_size
return st.text(string.digits, min_size=min_size, max_size=max_size)
def test_transaction_amount_item_3_for_ocr_giro_transactions(tn, text):
original = netsgiro.records.TransactionAmountItem3(
service_code=netsgiro.ServiceCode.OCR_GIRO,
transaction_type=(
netsgiro.TransactionType.PURCHASE_WITH_TEXT),
transaction_number=tn,
text=text,
)
ocr = original.to_ocr()
record = netsgiro.records.TransactionAmountItem3.from_string(ocr)
assert record.transaction_number == tn
assert record.text == original.text
def random_prefix(draw):
#limited to unicode letters, see
#https://en.wikipedia.org/wiki/Unicode_character_property#General_Category
categories = ['Ll', 'Lt', 'Lm', 'Lo']
characters = st.lists(st.characters(whitelist_categories=categories), min_size = 1)
prefix = st.text(alphabet = draw(characters), min_size = 1)
return draw(prefix)
def test_booleanvar_true(text):
assert BooleanVar()._to_python(text) is True
def test_booleanvar_false(text):
assert BooleanVar()._to_python(text) is False
def test_booleanvar_other(text):
assume(text not in (TRUE_VALUES + FALSE_VALUES))
with pytest.raises(ValueError):
BooleanVar()._to_python(text)
def test_stringvar_return_the_same_string(text):
assert StringVar()._to_python(text) == text
def enums_of_primitives(draw):
"""Generate enum classes with primitive values."""
if is_py2:
names = draw(st.sets(st.text(alphabet=string.ascii_letters,
min_size=1),
min_size=1))
else:
names = draw(st.sets(st.text(min_size=1), min_size=1))
n = len(names)
vals = draw(st.one_of(st.sets(st.one_of(
st.integers(),
st.floats(allow_nan=False),
st.text(min_size=1)),
min_size=n, max_size=n)))
return Enum('HypEnum', list(zip(names, vals)))
def str_attrs(draw, defaults=None):
"""
Generate a tuple of an attribute and a strategy that yields strs for that
attribute.
"""
default = NOTHING
if defaults is True or (defaults is None and draw(st.booleans())):
default = draw(st.text())
return ((attr.ib(default=default), st.text()))
def dict_attrs(draw, defaults=None):
"""
Generate a tuple of an attribute and a strategy that yields dictionaries
for that attribute. The dictionaries map strings to integers.
"""
default = NOTHING
val_strat = st.dictionaries(keys=st.text(), values=st.integers())
if defaults is True or (defaults is None and draw(st.booleans())):
default_val = draw(val_strat)
default = attr.Factory(lambda: default_val)
return ((attr.ib(default=default), val_strat))
def test_text_and_title(title, text):
assert(str(Abbreviation(title, text)) == "<abbr title=\"" + title + "\">" + text + "</abbr>")
def test_initialism():
assert(str(Abbreviation("Title", "text", True)) == "<abbr title=\"Title\" class=\"initialism\">text</abbr>")
def test_custom_class_ident_style_and_attrs():
assert(str(Abbreviation("Title", "text", True, cl='abclass', ident='123', style="font-size:0.9em;", attrs={"data-test": 'abc'}))
== "<abbr title=\"Title\" id=\"123\" class=\"initialism abclass\" style=\"font-size:0.9em;\" data-test=\"abc\">text</abbr>")
def test_hypothesis_text(s, each_text_maker):
# have to get a fresh text maker EACH time function is invoked, due to Hypothesis quirk explained here:
# http://hypothesis.works/articles/hypothesis-pytest-fixtures/
text_maker = each_text_maker.clone()
_input_tokenized = text_maker.input_text(s)
sentences = text_maker.make_sentences(300)
word_set_comparison = helpers.WordSetComparison(generated_tokens=sentences, input_tokenized=_input_tokenized)
assert word_set_comparison.output_is_valid_strict()
def _device_list(minimum):
"""
Get a device generating strategy.
:param int minimum: the minimum number of devices, must be at least 0
"""
return strategies.lists(
strategies.text(
alphabet=string.ascii_letters + "/",
min_size=1
),
min_size=minimum
)
def _device_list(minimum):
"""
Get a device generating strategy.
:param int minimum: the minimum number of devices, must be at least 0
"""
return strategies.lists(
strategies.text(
alphabet=string.ascii_letters + "/",
min_size=1
),
min_size=minimum
)
def jsonify(text):
"""Substitute for flask.jsonify which accepts an already encoded
JSON string and makes a response with 200 status and application/json
Content-Type header.
"""
return make_response(text, 200, {'Content-Type': 'application/json'})
def test_example(self) -> None:
"""
Test a successful example of creating an Authorization header.
"""
result = authorization_header(
access_key=b'my_access_key',
secret_key=b'my_secret_key',
method=GET,
content=b'{"something": "other"}',
content_type='text/example',
date='Sun, 22 Apr 2012 08:49:37 GMT.',
request_path='/example_path',
)
assert result == b'VWS my_access_key:CetfV6Yl/3mSz/Xl0c+O1YjXKYg='
def jobs(
draw,
services=service_generator(),
parameters=dictionaries(text(), text()),
) -> Job:
return Job.new(
draw(services),
draw(parameters)
)
def services(
draw,
names=text(),
descriptions=text(),
registration=dictionaries(text(), text()),
results=dictionaries(text(), text())
) -> Service:
return Service.new(
name=draw(names),
description=draw(descriptions),
registration_schema=draw(registration),
result_schema=draw(results)
)
def services(
draw,
service_id=uuids(), name=text(), description=text(),
is_available=booleans()
) -> IService:
return Service(
draw(service_id), draw(name), draw(description), draw(is_available)
)
def _valid_post_requests(
draw,
names: str=text(),
descriptions: str=text(),
job_registration_schemas: dict=dictionaries(text(), text()),
job_result_schemas: dict=dictionaries(text(), text())
) -> dict:
return {
'name': draw(names),
'description': draw(descriptions),
'job_registration_schema': draw(job_registration_schemas),
'job_result_schema': draw(job_result_schemas)
}