本文整理汇总了Python中pyramid.compat.NativeIO.close方法的典型用法代码示例。如果您正苦于以下问题:Python NativeIO.close方法的具体用法?Python NativeIO.close怎么用?Python NativeIO.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.compat.NativeIO
的用法示例。
在下文中一共展示了NativeIO.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Test_copy_dir
# 需要导入模块: from pyramid.compat import NativeIO [as 别名]
# 或者: from pyramid.compat.NativeIO import close [as 别名]
class Test_copy_dir(unittest.TestCase):
def setUp(self):
import tempfile
from pyramid.compat import NativeIO
self.dirname = tempfile.mkdtemp()
self.out = NativeIO()
self.fixturetuple = ('pyramid.tests.test_scaffolds',
'fixture_scaffold')
def tearDown(self):
import shutil
shutil.rmtree(self.dirname, ignore_errors=True)
self.out.close()
def _callFUT(self, *arg, **kw):
kw['out_'] = self.out
from pyramid.scaffolds.copydir import copy_dir
return copy_dir(*arg, **kw)
def test_copy_source_as_pkg_resource(self):
vars = {'package':'mypackage'}
self._callFUT(self.fixturetuple,
self.dirname,
vars,
1, False,
template_renderer=dummy_template_renderer)
result = self.out.getvalue()
self.assertTrue('Creating %s/mypackage/' % self.dirname in result)
self.assertTrue(
'Copying fixture_scaffold/+package+/__init__.py_tmpl to' in result)
source = pkg_resources.resource_filename(
'pyramid.tests.test_scaffolds',
'fixture_scaffold/+package+/__init__.py_tmpl')
target = os.path.join(self.dirname, 'mypackage', '__init__.py')
with open(target, 'r') as f:
tcontent = f.read()
with open(source, 'r') as f:
scontent = f.read()
self.assertEqual(scontent, tcontent)
def test_copy_source_as_dirname(self):
vars = {'package':'mypackage'}
source = pkg_resources.resource_filename(*self.fixturetuple)
self._callFUT(source,
self.dirname,
vars,
1, False,
template_renderer=dummy_template_renderer)
result = self.out.getvalue()
self.assertTrue('Creating %s/mypackage/' % self.dirname in result)
self.assertTrue('Copying __init__.py_tmpl to' in result)
source = pkg_resources.resource_filename(
'pyramid.tests.test_scaffolds',
'fixture_scaffold/+package+/__init__.py_tmpl')
target = os.path.join(self.dirname, 'mypackage', '__init__.py')
with open(target, 'r') as f:
tcontent = f.read()
with open(source, 'r') as f:
scontent = f.read()
self.assertEqual(scontent, tcontent)
示例2: Test_copy_dir
# 需要导入模块: from pyramid.compat import NativeIO [as 别名]
# 或者: from pyramid.compat.NativeIO import close [as 别名]
class Test_copy_dir(unittest.TestCase):
def setUp(self):
import tempfile
from pyramid.compat import NativeIO
self.dirname = tempfile.mkdtemp()
self.out = NativeIO()
self.fixturetuple = ('pyramid.tests.test_scaffolds',
'fixture_scaffold')
def tearDown(self):
import shutil
shutil.rmtree(self.dirname, ignore_errors=True)
self.out.close()
def _callFUT(self, *arg, **kw):
kw['out_'] = self.out
from pyramid.scaffolds.copydir import copy_dir
return copy_dir(*arg, **kw)
def test_copy_source_as_pkg_resource(self):
vars = {'package':'mypackage'}
self._callFUT(self.fixturetuple,
self.dirname,
vars,
1, False,
template_renderer=dummy_template_renderer)
result = self.out.getvalue()
self.assertTrue('Creating %s/mypackage/' % self.dirname in result)
self.assertTrue(
'Copying fixture_scaffold/+package+/__init__.py_tmpl to' in result)
source = pkg_resources.resource_filename(
'pyramid.tests.test_scaffolds',
'fixture_scaffold/+package+/__init__.py_tmpl')
target = os.path.join(self.dirname, 'mypackage', '__init__.py')
with open(target, 'r') as f:
tcontent = f.read()
with open(source, 'r') as f:
scontent = f.read()
self.assertEqual(scontent, tcontent)
def test_copy_source_as_dirname(self):
vars = {'package':'mypackage'}
source = pkg_resources.resource_filename(*self.fixturetuple)
self._callFUT(source,
self.dirname,
vars,
1, False,
template_renderer=dummy_template_renderer)
result = self.out.getvalue()
self.assertTrue('Creating %s/mypackage/' % self.dirname in result)
self.assertTrue('Copying __init__.py_tmpl to' in result)
source = pkg_resources.resource_filename(
'pyramid.tests.test_scaffolds',
'fixture_scaffold/+package+/__init__.py_tmpl')
target = os.path.join(self.dirname, 'mypackage', '__init__.py')
with open(target, 'r') as f:
tcontent = f.read()
with open(source, 'r') as f:
scontent = f.read()
self.assertEqual(scontent, tcontent)
def test_content_is_same_message(self):
vars = {'package':'mypackage'}
source = pkg_resources.resource_filename(*self.fixturetuple)
self._callFUT(source,
self.dirname,
vars,
2, False,
template_renderer=dummy_template_renderer)
self._callFUT(source,
self.dirname,
vars,
2, False,
template_renderer=dummy_template_renderer)
result = self.out.getvalue()
self.assertTrue('%s already exists (same content)' % \
os.path.join(self.dirname, 'mypackage', '__init__.py') in result)
def test_direxists_message(self):
vars = {'package':'mypackage'}
source = pkg_resources.resource_filename(*self.fixturetuple)
# if not os.path.exists(self.dirname):
# os.mkdir(self.dirname)
self._callFUT(source,
self.dirname,
vars,
2, False,
template_renderer=dummy_template_renderer)
result = self.out.getvalue()
self.assertTrue('Directory %s exists' % self.dirname in result, result)
def test_overwrite_false(self):
vars = {'package':'mypackage'}
source = pkg_resources.resource_filename(*self.fixturetuple)
self._callFUT(source,
self.dirname,
vars,
1, False,
overwrite=False,
template_renderer=dummy_template_renderer)
#.........这里部分代码省略.........
示例3: Test_query_interactive
# 需要导入模块: from pyramid.compat import NativeIO [as 别名]
# 或者: from pyramid.compat.NativeIO import close [as 别名]
class Test_query_interactive(unittest.TestCase):
def setUp(self):
import tempfile
from pyramid.compat import NativeIO
self.dirname = tempfile.mkdtemp()
self.out = NativeIO()
self.fixturetuple = ('pyramid.tests.test_scaffolds',
'fixture_scaffold')
self.src_content = """\
These are not the droids
that you are looking for."""
self.dest_content = """\
These are the droids for
whom you are looking;
now you have found them."""
self.src_fn = os.path.join(self.dirname, 'mypackage', '__init__.py')
self.dest_fn = os.path.join(self.dirname, 'mypackage', '__init__.py')
# query_interactive is only normally executed when the destination
# is discovered to be already occupied by existing files, so ...
# create the required occupancy.
from pyramid.scaffolds.copydir import copy_dir
copy_dir(self.fixturetuple,
self.dirname,
{'package':'mypackage'},
0, False,
template_renderer=dummy_template_renderer)
def tearDown(self):
import shutil
shutil.rmtree(self.dirname, ignore_errors=True)
self.out.close()
def _callFUT(self, *arg, **kw):
from pyramid.scaffolds.copydir import query_interactive
return query_interactive(*arg, **kw)
def test_query_interactive_0y(self):
from pyramid.scaffolds import copydir
copydir.input_ = RawInputMockObject("y")
self._callFUT(self.src_fn, self.dest_fn,
self.src_content, self.dest_content,
simulate=False,
out_=self.out)
self.assertTrue("Replace" in self.out.getvalue())
def test_query_interactive_1n(self):
from pyramid.scaffolds import copydir
copydir.input_ = RawInputMockObject("n")
self._callFUT(self.src_fn, self.dest_fn,
self.src_content,
'\n'.join(self.dest_content.split('\n')[:-1]),
simulate=False,
out_=self.out)
self.assertTrue("Replace" in self.out.getvalue())
def test_query_interactive_2b(self):
from pyramid.scaffolds import copydir
copydir.input_ = RawInputMockObject("b")
with open(os.path.join(
self.dirname, 'mypackage', '__init__.py.bak'), 'w') as fp:
fp.write("")
fp.close()
self._callFUT(self.src_fn, self.dest_fn,
self.dest_content, self.src_content,
simulate=False,
out_=self.out)
self.assertTrue("Backing up" in self.out.getvalue())
def test_query_interactive_3d(self):
from pyramid.scaffolds import copydir
copydir.input_ = RawInputMockObject("d")
self._callFUT(self.src_fn, self.dest_fn,
self.dest_content, self.src_content,
simulate=False,
out_=self.out)
output = self.out.getvalue()
# The useful text in self.out gets wiped out on the second
# call to raw_input, otherwise the test could be made
# more usefully precise...
# print("3d", output)
# self.assertTrue("@@" in output, output)
self.assertTrue("Replace" in output)
def test_query_interactive_4dc(self):
from pyramid.scaffolds import copydir
copydir.input_ = RawInputMockObject("dc")
self._callFUT(self.src_fn, self.dest_fn,
self.dest_content, self.src_content,
simulate=False,
out_=self.out)
output = self.out.getvalue()
# The useful text in self.out gets wiped out on the second
# call to raw_input, otherwise, the test could be made
# more usefully precise...
# print("4dc", output)
# self.assertTrue("***" in output, output)
self.assertTrue("Replace" in output)
def test_query_interactive_5allbad(self):
#.........这里部分代码省略.........