本文整理汇总了Python中test.test_support.TESTFN属性的典型用法代码示例。如果您正苦于以下问题:Python test_support.TESTFN属性的具体用法?Python test_support.TESTFN怎么用?Python test_support.TESTFN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类test.test_support
的用法示例。
在下文中一共展示了test_support.TESTFN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_debug_mode
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN [as 别名]
def test_debug_mode(self):
with open(TESTFN, "w") as f:
f.write("[global]\n")
f.write("command_packages = foo.bar, splat")
self.addCleanup(unlink, TESTFN)
files = [TESTFN]
sys.argv.append("build")
with captured_stdout() as stdout:
self.create_distribution(files)
stdout.seek(0)
self.assertEqual(stdout.read(), '')
distutils.dist.DEBUG = True
try:
with captured_stdout() as stdout:
self.create_distribution(files)
stdout.seek(0)
self.assertEqual(stdout.read(), '')
finally:
distutils.dist.DEBUG = False
示例2: test_command_packages_configfile
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN [as 别名]
def test_command_packages_configfile(self):
sys.argv.append("build")
self.addCleanup(os.unlink, TESTFN)
f = open(TESTFN, "w")
try:
print >> f, "[global]"
print >> f, "command_packages = foo.bar, splat"
finally:
f.close()
d = self.create_distribution([TESTFN])
self.assertEqual(d.get_command_packages(),
["distutils.command", "foo.bar", "splat"])
# ensure command line overrides config:
sys.argv[1:] = ["--command-packages", "spork", "build"]
d = self.create_distribution([TESTFN])
self.assertEqual(d.get_command_packages(),
["distutils.command", "spork"])
# Setting --command-packages to '' should cause the default to
# be used even if a config file specified something else:
sys.argv[1:] = ["--command-packages", "", "build"]
d = self.create_distribution([TESTFN])
self.assertEqual(d.get_command_packages(), ["distutils.command"])
示例3: test_with_open
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN [as 别名]
def test_with_open(self):
for bufsize in (0, 1, 100):
f = None
with self.open(support.TESTFN, "wb", bufsize) as f:
f.write(b"xxx")
self.assertEqual(f.closed, True)
f = None
try:
with self.open(support.TESTFN, "wb", bufsize) as f:
1 // 0
except ZeroDivisionError:
self.assertEqual(f.closed, True)
else:
self.fail("1 // 0 didn't raise an exception")
# issue 5008
示例4: test_destructor
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN [as 别名]
def test_destructor(self):
record = []
class MyFileIO(self.FileIO):
def __del__(self):
record.append(1)
try:
f = super(MyFileIO, self).__del__
except AttributeError:
pass
else:
f()
def close(self):
record.append(2)
super(MyFileIO, self).close()
def flush(self):
record.append(3)
super(MyFileIO, self).flush()
f = MyFileIO(support.TESTFN, "wb")
f.write(b"xxx")
del f
support.gc_collect()
self.assertEqual(record, [1, 2, 3])
with self.open(support.TESTFN, "rb") as f:
self.assertEqual(f.read(), b"xxx")
示例5: test_seeking
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN [as 别名]
def test_seeking(self):
chunk_size = _default_chunk_size()
prefix_size = chunk_size - 2
u_prefix = "a" * prefix_size
prefix = bytes(u_prefix.encode("utf-8"))
self.assertEqual(len(u_prefix), len(prefix))
u_suffix = "\u8888\n"
suffix = bytes(u_suffix.encode("utf-8"))
line = prefix + suffix
f = self.open(support.TESTFN, "wb")
f.write(line*2)
f.close()
f = self.open(support.TESTFN, "r", encoding="utf-8")
s = f.read(prefix_size)
self.assertEqual(s, prefix.decode("ascii"))
self.assertEqual(f.tell(), prefix_size)
self.assertEqual(f.readline(), u_suffix)
示例6: test_threads_write
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN [as 别名]
def test_threads_write(self):
# Issue6750: concurrent writes could duplicate data
event = threading.Event()
with self.open(support.TESTFN, "w", buffering=1) as f:
def run(n):
text = "Thread%03d\n" % n
event.wait()
f.write(text)
threads = [threading.Thread(target=run, args=(x,))
for x in range(20)]
with support.start_threads(threads, event.set):
time.sleep(0.02)
with self.open(support.TESTFN) as f:
content = f.read()
for n in range(20):
self.assertEqual(content.count("Thread%03d\n" % n), 1)
示例7: test_unseekable_overflowed_write
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN [as 别名]
def test_unseekable_overflowed_write(self):
with UnseekableIO(TESTFN, 'wb') as testfile:
testfile.write(b'ababagalamaga')
f = self.create_file(testfile)
f.setnframes(self.nframes - 1)
try:
f.writeframes(self.frames)
except IOError:
pass
try:
f.close()
except IOError:
pass
with open(TESTFN, 'rb') as testfile:
self.assertEqual(testfile.read(13), b'ababagalamaga')
framesize = self.nchannels * self.sampwidth
self.check_file(testfile, self.nframes - 1, self.frames[:-framesize])
示例8: test_copy
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN [as 别名]
def test_copy(self):
f = self.f = self.module.open(self.sndfilepath)
fout = self.fout = self.module.open(TESTFN, 'wb')
fout.setparams(f.getparams())
i = 0
n = f.getnframes()
while n > 0:
i += 1
fout.writeframes(f.readframes(i))
n -= i
fout.close()
fout = self.fout = self.module.open(TESTFN, 'rb')
f.rewind()
self.assertEqual(f.getparams(), fout.getparams())
self.assertEqual(f.readframes(f.getnframes()),
fout.readframes(fout.getnframes()))
示例9: test_read_not_from_start
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN [as 别名]
def test_read_not_from_start(self):
with open(TESTFN, 'wb') as testfile:
testfile.write(b'ababagalamaga')
with open(self.sndfilepath, 'rb') as f:
testfile.write(f.read())
with open(TESTFN, 'rb') as testfile:
self.assertEqual(testfile.read(13), b'ababagalamaga')
f = self.module.open(testfile, 'rb')
try:
self.assertEqual(f.getnchannels(), self.nchannels)
self.assertEqual(f.getsampwidth(), self.sampwidth)
self.assertEqual(f.getframerate(), self.framerate)
self.assertEqual(f.getnframes(), self.sndfilenframes)
self.assertEqual(f.readframes(self.nframes), self.frames)
finally:
f.close()
示例10: testModeStrings
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN [as 别名]
def testModeStrings(self):
# check invalid mode strings
for mode in ("", "aU", "wU+"):
try:
f = open(TESTFN, mode)
except ValueError:
pass
else:
f.close()
self.fail('%r is an invalid file mode' % mode)
# Some invalid modes fail on Windows, but pass on Unix
# Issue3965: avoid a crash on Windows when filename is unicode
for name in (TESTFN, unicode(TESTFN), unicode(TESTFN + '\t')):
try:
f = open(name, "rr")
except (IOError, ValueError):
pass
else:
f.close()
示例11: testSetBufferSize
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN [as 别名]
def testSetBufferSize(self):
# make sure that explicitly setting the buffer size doesn't cause
# misbehaviour especially with repeated close() calls
for s in (-1, 0, 1, 512):
try:
f = open(TESTFN, 'w', s)
f.write(str(s))
f.close()
f.close()
f = open(TESTFN, 'r', s)
d = int(f.read())
f.close()
f.close()
except IOError, msg:
self.fail('error setting buffer size %d: %s' % (s, str(msg)))
self.assertEqual(d, s)
示例12: setUp
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN [as 别名]
def setUp(self):
cf = self.newconfig()
for i in range(100):
s = 'section{0}'.format(i)
cf.add_section(s)
for j in range(10):
cf.set(s, 'lovely_spam{0}'.format(j), self.wonderful_spam)
with open(support.TESTFN, 'w') as f:
cf.write(f)
示例13: tearDown
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN [as 别名]
def tearDown(self):
os.unlink(support.TESTFN)
示例14: test_dominating_multiline_values
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN [as 别名]
def test_dominating_multiline_values(self):
# We're reading from file because this is where the code changed
# during performance updates in Python 3.2
cf_from_file = self.newconfig()
with open(support.TESTFN) as f:
cf_from_file.read_file(f)
self.assertEqual(
cf_from_file.get('section8', 'lovely_spam4'),
self.wonderful_spam.replace('\t\n', '\n'),
)
示例15: test_shell_injection
# 需要导入模块: from test import test_support [as 别名]
# 或者: from test.test_support import TESTFN [as 别名]
def test_shell_injection(self):
result = find_library('; echo Hello shell > ' + test_support.TESTFN)
self.assertFalse(os.path.lexists(test_support.TESTFN))
self.assertIsNone(result)