本文整理汇总了Python中test.test_support.findfile方法的典型用法代码示例。如果您正苦于以下问题:Python test_support.findfile方法的具体用法?Python test_support.findfile怎么用?Python test_support.findfile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test.test_support
的用法示例。
在下文中一共展示了test_support.findfile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_read_returns_file_list_with_bytestring_path
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import findfile [as 别名]
def test_read_returns_file_list_with_bytestring_path(self):
if self.delimiters[0] != '=':
self.skipTest('incompatible format')
file1_bytestring = support.findfile("cfgparser.1").encode()
# check when passing an existing bytestring path
cf = self.newconfig()
parsed_files = cf.read(file1_bytestring)
self.assertEqual(parsed_files, [file1_bytestring])
# check when passing an non-existing bytestring path
cf = self.newconfig()
parsed_files = cf.read(b'nonexistent-file')
self.assertEqual(parsed_files, [])
# check when passing both an existing and non-existing bytestring path
cf = self.newconfig()
parsed_files = cf.read([file1_bytestring, b'nonexistent-file'])
self.assertEqual(parsed_files, [file1_bytestring])
# shared by subclasses
示例2: test_reading
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import findfile [as 别名]
def test_reading(self):
smbconf = support.findfile("cfgparser.2")
# check when we pass a mix of readable and non-readable files:
cf = self.newconfig()
parsed_files = cf.read([smbconf, "nonexistent-file"], encoding='utf-8')
self.assertEqual(parsed_files, [smbconf])
sections = [
'global',
'homes',
'printers',
'print$',
'pdf-generator',
'tmp',
'Agustin',
]
self.assertEqual(cf.sections(), sections)
self.assertEqual(cf.get("global", "workgroup"), "MDKGROUP")
self.assertEqual(cf.getint("global", "max log size"), 50)
self.assertEqual(cf.get("global", "hosts allow"), "127.")
self.assertEqual(cf.get("tmp", "echo command"), "cat %s; rm %s")
示例3: test_read_returns_file_list
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import findfile [as 别名]
def test_read_returns_file_list(self):
file1 = test_support.findfile("cfgparser.1")
# check when we pass a mix of readable and non-readable files:
cf = self.newconfig()
parsed_files = cf.read([file1, "nonexistent-file"])
self.assertEqual(parsed_files, [file1])
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
# check when we pass only a filename:
cf = self.newconfig()
parsed_files = cf.read(file1)
self.assertEqual(parsed_files, [file1])
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
# check when we pass only missing files:
cf = self.newconfig()
parsed_files = cf.read(["nonexistent-file"])
self.assertEqual(parsed_files, [])
# check when we pass no files:
cf = self.newconfig()
parsed_files = cf.read([])
self.assertEqual(parsed_files, [])
# shared by subclasses
示例4: test_random_files
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import findfile [as 别名]
def test_random_files(self):
# Test roundtrip on random python modules.
# pass the '-ucpu' option to process the full directory.
import glob, random
fn = test_support.findfile("tokenize_tests" + os.extsep + "txt")
tempdir = os.path.dirname(fn) or os.curdir
testfiles = glob.glob(os.path.join(tempdir, "test*.py"))
if not test_support.is_resource_enabled("cpu"):
testfiles = random.sample(testfiles, 10)
for testfile in testfiles:
try:
with open(testfile, 'rb') as f:
self.check_roundtrip(f)
except:
print "Roundtrip failed for file %s" % testfile
raise
示例5: test_play_sound_file
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import findfile [as 别名]
def test_play_sound_file(self):
path = findfile("audiotest.au")
fp = open(path, 'r')
size, enc, rate, nchannels, extra = sunaudio.gethdr(fp)
data = fp.read()
fp.close()
if enc != SND_FORMAT_MULAW_8:
self.fail("Expect .au file with 8-bit mu-law samples")
# convert the data to 16-bit signed
data = audioop.ulaw2lin(data, 2)
# set the data format
if sys.byteorder == 'little':
fmt = linuxaudiodev.AFMT_S16_LE
else:
fmt = linuxaudiodev.AFMT_S16_BE
# set parameters based on .au file headers
self.dev.setparameters(rate, 16, nchannels, fmt)
self.dev.write(data)
self.dev.flush()
示例6: check_create_from_data
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import findfile [as 别名]
def check_create_from_data(self, ext):
testfile = support.findfile('python.' + ext, subdir='imghdrdata')
with open(testfile, 'rb') as f:
data = f.read()
image = tkinter.PhotoImage('::img::test', master=self.root,
data=data)
self.assertEqual(str(image), '::img::test')
self.assertEqual(image.type(), 'photo')
self.assertEqual(image.width(), 16)
self.assertEqual(image.height(), 16)
self.assertEqual(image['data'], data if self.wantobjects
else data.decode('latin1'))
self.assertEqual(image['file'], '')
self.assertIn('::img::test', self.root.image_names())
del image
self.assertNotIn('::img::test', self.root.image_names())
示例7: test_parse_errors
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import findfile [as 别名]
def test_parse_errors(self):
cf = self.newconfig()
self.parse_error(
cf,
configparser.ParsingError,
"[Foo]\n" "{0}val-without-opt-name\n".format(self.delimiters[0]),
)
self.parse_error(
cf,
configparser.ParsingError,
"[Foo]\n" "{0}val-without-opt-name\n".format(self.delimiters[1]),
)
e = self.parse_error(
cf, configparser.MissingSectionHeaderError, "No Section!\n"
)
self.assertEqual(e.args, ('<???>', 1, "No Section!\n"))
if not self.allow_no_value:
e = self.parse_error(
cf, configparser.ParsingError, "[Foo]\n wrong-indent\n"
)
self.assertEqual(e.args, ('<???>',))
# read_file on a real file
tricky = support.findfile("cfgparser.3")
if self.delimiters[0] == '=':
error = configparser.ParsingError
expected = (tricky,)
else:
error = configparser.MissingSectionHeaderError
expected = (
tricky,
1,
' # INI with as many tricky parts as possible\n',
)
with open(tricky, encoding='utf-8') as f:
e = self.parse_error(cf, error, f)
self.assertEqual(e.args, expected)
示例8: test_read_returns_file_list
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import findfile [as 别名]
def test_read_returns_file_list(self):
if self.delimiters[0] != '=':
self.skipTest('incompatible format')
file1 = support.findfile("cfgparser.1")
# check when we pass a mix of readable and non-readable files:
cf = self.newconfig()
parsed_files = cf.read([file1, "nonexistent-file"])
self.assertEqual(parsed_files, [file1])
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
# check when we pass only a filename:
cf = self.newconfig()
parsed_files = cf.read(file1)
self.assertEqual(parsed_files, [file1])
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
# check when we pass only a Path object:
cf = self.newconfig()
parsed_files = cf.read(pathlib.Path(file1))
self.assertEqual(parsed_files, [file1])
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
# check when we passed both a filename and a Path object:
cf = self.newconfig()
parsed_files = cf.read([pathlib.Path(file1), file1])
self.assertEqual(parsed_files, [file1, file1])
self.assertEqual(cf.get("Foo Bar", "foo"), "newbar")
# check when we pass only missing files:
cf = self.newconfig()
parsed_files = cf.read(["nonexistent-file"])
self.assertEqual(parsed_files, [])
# check when we pass no files:
cf = self.newconfig()
parsed_files = cf.read([])
self.assertEqual(parsed_files, [])
示例9: test_cfgparser_dot_3
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import findfile [as 别名]
def test_cfgparser_dot_3(self):
tricky = support.findfile("cfgparser.3")
cf = self.newconfig()
self.assertEqual(len(cf.read(tricky, encoding='utf-8')), 1)
self.assertEqual(
cf.sections(),
[
'strange',
'corruption',
'yeah, sections can be ' 'indented as well',
'another one!',
'no values here',
'tricky interpolation',
'more interpolation',
],
)
self.assertEqual(
cf.getint(self.default_section, 'go', vars={'interpolate': '-1'}), -1
)
with self.assertRaises(ValueError):
# no interpolation will happen
cf.getint(self.default_section, 'go', raw=True, vars={'interpolate': '-1'})
self.assertEqual(len(cf.get('strange', 'other').split('\n')), 4)
self.assertEqual(len(cf.get('corruption', 'value').split('\n')), 10)
longname = 'yeah, sections can be indented as well'
self.assertFalse(cf.getboolean(longname, 'are they subsections'))
self.assertEqual(cf.get(longname, 'lets use some Unicode'), '片仮名')
self.assertEqual(len(cf.items('another one!')), 5) # 4 in section and
# `go` from DEFAULT
with self.assertRaises(configparser.InterpolationMissingOptionError):
cf.items('no values here')
self.assertEqual(cf.get('tricky interpolation', 'lets'), 'do this')
self.assertEqual(
cf.get('tricky interpolation', 'lets'), cf.get('tricky interpolation', 'go')
)
self.assertEqual(cf.get('more interpolation', 'lets'), 'go shopping')
示例10: __init__
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import findfile [as 别名]
def __init__(self):
file_path = support.findfile("cfgparser.1")
with open(file_path) as f:
self.lines = f.readlines()
self.lines.reverse()
示例11: test_file
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import findfile [as 别名]
def test_file(self):
file_paths = [support.findfile("cfgparser.1")]
try:
file_paths.append(file_paths[0].encode('utf8'))
except UnicodeEncodeError:
pass # unfortunately we can't test bytes on this path
for file_path in file_paths:
parser = configparser.ConfigParser()
with open(file_path) as f:
parser.read_file(f)
self.assertIn("Foo Bar", parser)
self.assertIn("foo", parser["Foo Bar"])
self.assertEqual(parser["Foo Bar"]["foo"], "newbar")
示例12: _msgobj
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import findfile [as 别名]
def _msgobj(self, filename):
fp = openfile(findfile(filename))
try:
msg = email.message_from_file(fp)
finally:
fp.close()
return msg
# Test various aspects of the Message class's API
示例13: test_message_rfc822_only
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import findfile [as 别名]
def test_message_rfc822_only(self):
# Issue 7970: message/rfc822 not in multipart parsed by
# HeaderParser caused an exception when flattened.
fp = openfile(findfile('msg_46.txt'))
msgdata = fp.read()
parser = email.Parser.HeaderParser()
msg = parser.parsestr(msgdata)
out = StringIO()
gen = email.Generator.Generator(out, True, 0)
gen.flatten(msg, False)
self.assertEqual(out.getvalue(), msgdata)
示例14: setUp
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import findfile [as 别名]
def setUp(self):
# Make sure we pick up the audiotest.au that lives in email/test/data.
# In Python, there's an audiotest.au living in Lib/test but that isn't
# included in some binary distros that don't include the test
# package. The trailing empty string on the .join() is significant
# since findfile() will do a dirname().
datadir = os.path.join(os.path.dirname(landmark), 'data', '')
fp = open(findfile('audiotest.au', datadir), 'rb')
try:
self._audiodata = fp.read()
finally:
fp.close()
self._au = MIMEAudio(self._audiodata)
示例15: _msg_and_obj
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import findfile [as 别名]
def _msg_and_obj(self, filename):
fp = openfile(findfile(filename))
try:
original = fp.read()
msg = email.message_from_string(original)
finally:
fp.close()
return original, msg