本文整理汇总了Python中test.support.findfile方法的典型用法代码示例。如果您正苦于以下问题:Python support.findfile方法的具体用法?Python support.findfile怎么用?Python support.findfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类test.support
的用法示例。
在下文中一共展示了support.findfile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_read_returns_file_list_with_bytestring_path
# 需要导入模块: from test import support [as 别名]
# 或者: from 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 support [as 别名]
# 或者: from 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_data
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import findfile [as 别名]
def test_data(self):
for filename, expected in (
('sndhdr.8svx', ('8svx', 0, 1, 0, 8)),
('sndhdr.aifc', ('aifc', 44100, 2, 5, 16)),
('sndhdr.aiff', ('aiff', 44100, 2, 5, 16)),
('sndhdr.au', ('au', 44100, 2, 5.0, 16)),
('sndhdr.hcom', ('hcom', 22050.0, 1, -1, 8)),
('sndhdr.sndt', ('sndt', 44100, 1, 5, 8)),
('sndhdr.voc', ('voc', 0, 1, -1, 8)),
('sndhdr.wav', ('wav', 44100, 2, 5, 16)),
):
filename = findfile(filename, subdir="sndhdrdata")
what = sndhdr.what(filename)
self.assertNotEqual(what, None, filename)
self.assertSequenceEqual(what, expected)
self.assertEqual(what.filetype, expected[0])
self.assertEqual(what.framerate, expected[1])
self.assertEqual(what.nchannels, expected[2])
self.assertEqual(what.nframes, expected[3])
self.assertEqual(what.sampwidth, expected[4])
示例4: test_test_command_invalid_file
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import findfile [as 别名]
def test_test_command_invalid_file(self):
zipname = support.findfile('zipdir.zip')
rc, out, err = self.tarfilecmd_failure('-t', zipname)
self.assertIn(b' is not a tar archive.', err)
self.assertEqual(out, b'')
self.assertEqual(rc, 1)
for tar_name in testtarnames:
with self.subTest(tar_name=tar_name):
with open(tar_name, 'rb') as f:
data = f.read()
try:
with open(tmpname, 'wb') as f:
f.write(data[:511])
rc, out, err = self.tarfilecmd_failure('-t', tmpname)
self.assertEqual(out, b'')
self.assertEqual(rc, 1)
finally:
support.unlink(tmpname)
示例5: test_read_returns_file_list
# 需要导入模块: from test import support [as 别名]
# 或者: from 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 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
示例6: test_pipe_cloexec
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import findfile [as 别名]
def test_pipe_cloexec(self):
sleeper = support.findfile("input_reader.py", subdir="subprocessdata")
fd_status = support.findfile("fd_status.py", subdir="subprocessdata")
p1 = subprocess.Popen([sys.executable, sleeper],
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=False)
self.addCleanup(p1.communicate, b'')
p2 = subprocess.Popen([sys.executable, fd_status],
stdout=subprocess.PIPE, close_fds=False)
output, error = p2.communicate()
result_fds = set(map(int, output.split(b',')))
unwanted_fds = set([p1.stdin.fileno(), p1.stdout.fileno(),
p1.stderr.fileno()])
self.assertFalse(result_fds & unwanted_fds,
"Expected no fds from %r to be open in child, "
"found %r" %
(unwanted_fds, result_fds & unwanted_fds))
示例7: test_pass_fds_inheritable
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import findfile [as 别名]
def test_pass_fds_inheritable(self):
script = support.findfile("fd_status.py", subdir="subprocessdata")
inheritable, non_inheritable = os.pipe()
self.addCleanup(os.close, inheritable)
self.addCleanup(os.close, non_inheritable)
os.set_inheritable(inheritable, True)
os.set_inheritable(non_inheritable, False)
pass_fds = (inheritable, non_inheritable)
args = [sys.executable, script]
args += list(map(str, pass_fds))
p = subprocess.Popen(args,
stdout=subprocess.PIPE, close_fds=True,
pass_fds=pass_fds)
output, ignored = p.communicate()
fds = set(map(int, output.split(b',')))
# the inheritable file descriptor must be inherited, so its inheritable
# flag must be set in the child process after fork() and before exec()
self.assertEqual(fds, set(pass_fds), "output=%a" % output)
# inheritable flag must not be changed in the parent process
self.assertEqual(os.get_inheritable(inheritable), True)
self.assertEqual(os.get_inheritable(non_inheritable), False)
示例8: test_close_fds_after_preexec
# 需要导入模块: from test import support [as 别名]
# 或者: from test.support import findfile [as 别名]
def test_close_fds_after_preexec(self):
fd_status = support.findfile("fd_status.py", subdir="subprocessdata")
# this FD is used as dup2() target by preexec_fn, and should be closed
# in the child process
fd = os.dup(1)
self.addCleanup(os.close, fd)
p = subprocess.Popen([sys.executable, fd_status],
stdout=subprocess.PIPE, close_fds=True,
preexec_fn=lambda: os.dup2(1, fd))
output, ignored = p.communicate()
remaining_fds = set(map(int, output.split(b',')))
self.assertNotIn(fd, remaining_fds)
示例9: check_create_from_data
# 需要导入模块: from test import support [as 别名]
# 或者: from 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())
示例10: test_random_files
# 需要导入模块: from test import support [as 别名]
# 或者: from 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 = support.findfile("tokenize_tests.txt")
tempdir = os.path.dirname(fn) or os.curdir
testfiles = glob.glob(os.path.join(tempdir, "test*.py"))
# Tokenize is broken on test_pep3131.py because regular expressions are
# broken on the obscure unicode identifiers in it. *sigh*
# With roundtrip extended to test the 5-tuple mode of untokenize,
# 7 more testfiles fail. Remove them also until the failure is diagnosed.
testfiles.remove(os.path.join(tempdir, "test_pep3131.py"))
for f in ('buffer', 'builtin', 'fileio', 'inspect', 'os', 'platform', 'sys'):
testfiles.remove(os.path.join(tempdir, "test_%s.py") % f)
if not support.is_resource_enabled("cpu"):
testfiles = random.sample(testfiles, 10)
for testfile in testfiles:
with open(testfile, 'rb') as f:
with self.subTest(file=testfile):
self.check_roundtrip(f)
示例11: test_parse_errors
# 需要导入模块: from test import support [as 别名]
# 或者: from 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)
示例12: test_read_returns_file_list
# 需要导入模块: from test import support [as 别名]
# 或者: from 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, [])
示例13: test_cfgparser_dot_3
# 需要导入模块: from test import support [as 别名]
# 或者: from 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')
示例14: __init__
# 需要导入模块: from test import support [as 别名]
# 或者: from 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()
示例15: test_file
# 需要导入模块: from test import support [as 别名]
# 或者: from 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")