本文整理汇总了Python中six.StringIO.name方法的典型用法代码示例。如果您正苦于以下问题:Python StringIO.name方法的具体用法?Python StringIO.name怎么用?Python StringIO.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.StringIO
的用法示例。
在下文中一共展示了StringIO.name方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_alternative
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import name [as 别名]
def test_alternative(self):
mockfile = StringIO("I'm a file! *cough, cough*")
mockfile.name = '/etc/mockfile.txt'
m = encode(OrderedDict([
('file', mockfile),
('full_name', 'Joe Average'),
]))
boundary = m.get_boundary()
self.assertEqual(str(m),
'--{boundary}\r\n'
'Content-Disposition: form-data; name="file"; '
'filename="mockfile.txt"\r\n'
'Content-Type: text/plain\r\n'
'\r\n'
"I'm a file! *cough, cough*\r\n"
'--{boundary}\r\n'
'Content-Disposition: form-data; name="full_name"\r\n'
'Content-Type: text/plain; charset=utf-8\r\n'
'\r\n'
'Joe Average\r\n'
'--{boundary}--\r\n'.format(
boundary=boundary
)
)
示例2: test_start_subshell
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import name [as 别名]
def test_start_subshell(self, call_mock, tempfile_mock):
memfile = StringIO()
memfile.name = 'FILENAME'
tempfile_mock.return_value = memfile
credentials = {'AWS_VALID_SECONDS': 600}
start_subshell(credentials, 'ACCOUNT', 'ROLE')
call_mock.assert_called_once_with(
["bash", "--rcfile", 'FILENAME'],
stdout=sys.stdout, stderr=sys.stderr, stdin=sys.stdin)
expected = dedent("""
# Pretend to be an interactive, non-login shell
for file in /etc/bash.bashrc ~/.bashrc; do
[ -f "$file" ] && . "$file"
done
function afp_minutes_left {
if ((SECONDS >= 600)) ; then
echo EXPIRED
else
echo $(((600-SECONDS)/60)) Min
fi
}
PS1="(AWS ACCOUNT/ROLE \$(afp_minutes_left)) $PS1"
export AWS_VALID_SECONDS='600'""")
memfile.seek(0)
received = memfile.read()
self.assertEqual(received, expected)
示例3: test_chunking
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import name [as 别名]
def test_chunking(self):
mockfile = StringIO("I'm a file! *cough, cough*")
mockfile.name = 'mockfile.txt'
ms = Multipart([
Field('full_name', fileobj=mockfile),
Field('full_name', 'Joe Average')
], chunksize=10)
self.assertTrue(reduce(lambda acc, x: acc and len(x) <= 10, ms, True))
示例4: test_load_fasta
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import name [as 别名]
def test_load_fasta(self):
client = kbase_data.MockDataClient()
client.authenticate()
s = StringIO("> metadata\nGATTACAGATTACAGATTACA\n")
s.name = "StringIO"
src = kbase_data.FastaSource(s)
oid = client.load(src)
objects = client.search({'oid': oid})
#print("Got back objects:")
#for o in objects:
# print('--')
# print(o)
self.assertEqual(len(objects), 1)
file_hash = objects[0].measurements.get('Bytes.FASTA', None)
self.assertNotEqual(file_hash, None)
示例5: test_start_subcmd
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import name [as 别名]
def test_start_subcmd(self, unlink_mock, call_mock, tempfile_mock):
memfile = StringIO()
memfile.name = 'FILENAME'
# Need to mock away the 'close', so we can read it out later
# despite 'close' being called inside the function.
memfile.close = Mock()
tempfile_mock.return_value = memfile
credentials = {'AWS_VALID_SECONDS': 600}
start_subcmd(credentials, 'ACCOUNT', 'ROLE')
call_mock.assert_called_once_with(
["cmd", "/K", 'FILENAME'])
expected = dedent("""
@echo off
set PROMPT=$C AWS ACCOUNT/ROLE $F
set AWS_VALID_SECONDS='600'""")
memfile.seek(0)
received = memfile.read()
self.assertEqual(received, expected)
示例6: test_alternative_explicit_filename
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import name [as 别名]
def test_alternative_explicit_filename(self):
mockfile = StringIO("I'm a file! *cough, cough*")
mockfile.name = '/etc/mockfile.txt'
m = encode({
'file': (mockfile, 'explicit-name.txt')
})
boundary = m.get_boundary()
self.assertEqual(str(m),
'--{boundary}\r\n'
'Content-Disposition: form-data; name="file"; '
'filename="explicit-name.txt"\r\n'
'Content-Type: text/plain\r\n'
'\r\n'
"I'm a file! *cough, cough*\r\n"
'--{boundary}--\r\n'.format(
boundary=boundary
)
)
示例7: test_dive_export
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import name [as 别名]
def test_dive_export(mocked_urlopen, mock_fetch_response):
mocked_urlopen.return_value = mock_fetch_response
fragmentsdb = 'data/fragments.sqlite'
uniprot_annot = StringIO(
'Entry\tGene names (primary )\tProtein families\tCross-reference (PDB)' + '\n' +
'P0CG48\tUBC\tUbiquitin family\t1C3T;2N2K' + '\n'
)
pdbtag = StringIO('2n2k' + '\n')
pdbtag.name = 'mytag'
propnames = StringIO()
props = StringIO()
dive.dive_export(fragmentsdb, uniprot_annot, [pdbtag], propnames, props)
assert '["pdb", "het", "fragment", "title", "smiles", "weight", "uniprot", "protein", "organism", "gene", "pdbtag", "family0", "family1", "family2", "family3", "family4"]' == propnames.getvalue()
props_lines = props.getvalue().split('\n')
result = list(filter(lambda d: d.startswith('2n2k_MTN_frag1'), props_lines))[0]
expected = '2n2k_MTN_frag1 pdb:2n2k het:MTN fragment:1 "title:Ensemble structure of the closed state of Lys63-linked diubiquitin in the absence of a ligand" smiles:CC1(C)C=C(C[S-])C(C)(C)[NH+]1O 170.17 uniprot:P0CG48 "protein:Polyubiquitin-C" "organism:Homo sapiens" "gene:UBC" pdbtag:mytag "family0:Ubiquitin family"'
assert result == expected
示例8: test_with_fileobj
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import name [as 别名]
def test_with_fileobj(self):
mockfile = StringIO("I'm a file! *cough, cough*")
mockfile.name = 'mockfile.txt'
m = Multipart([
Field('file', fileobj=mockfile)
], boundary='testing')
self.assertEqual(m.get_headers(), {
'Content-Length': '150',
'Content-Type': 'multipart/form-data; boundary=testing'
})
self.assertEqual(str(m),
'--testing\r\n'
'Content-Disposition: form-data; name="file"; '
'filename="mockfile.txt"\r\n'
'Content-Type: text/plain\r\n'
'\r\n'
"I'm a file! *cough, cough*\r\n"
'--testing--\r\n'
)
示例9: fetch
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import name [as 别名]
def fetch(self, url, inject_ids=True): # type: (Text, bool) -> Any
if url in self.idx:
return self.idx[url]
try:
text = self.fetch_text(url)
if isinstance(text, bytes):
textIO = StringIO(text.decode('utf-8'))
else:
textIO = StringIO(text)
textIO.name = url # type: ignore
result = yaml.round_trip_load(textIO)
add_lc_filename(result, url)
except yaml.parser.ParserError as e:
raise validate.ValidationException("Syntax error %s" % (e))
if (isinstance(result, CommentedMap) and inject_ids
and bool(self.identifiers)):
for identifier in self.identifiers:
if identifier not in result:
result[identifier] = url
self.idx[self.expand_url(result[identifier], url)] = result
else:
self.idx[url] = result
return result
示例10: clipboard_stream
# 需要导入模块: from six import StringIO [as 别名]
# 或者: from six.StringIO import name [as 别名]
def clipboard_stream(name=None):
stream = StringIO(get_clipboard_data())
stream.name = name or '<clipboard>'
return stream