本文整理汇总了Python中KMCLib.Backend.Backend.MPICommons.myRank方法的典型用法代码示例。如果您正苦于以下问题:Python MPICommons.myRank方法的具体用法?Python MPICommons.myRank怎么用?Python MPICommons.myRank使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KMCLib.Backend.Backend.MPICommons
的用法示例。
在下文中一共展示了MPICommons.myRank方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testPrettyPrint
# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import myRank [as 别名]
def testPrettyPrint(self):
""" Test that we can call the pretty print function. """
# Print to stdout.
original_sys_stdout = sys.stdout
try:
stream_1 = StringIO.StringIO()
sys.stdout = stream_1
# Print to stdout.
ref_str = "This is what we print"
prettyPrint(ref_str)
# Check.
if MPICommons.myRank() == 0:
ref_str = ref_str + "\n"
else:
ref_str = ""
self.assertEqual(stream_1.getvalue(), ref_str)
finally:
# Put the original stdout back.
sys.stdout = original_sys_stdout
# Print to another stream.
stream_2 = StringIO.StringIO()
ref_str = "This is what we print next time."
prettyPrint(ref_str, output=stream_2)
# Check.
if MPICommons.myRank() == 0:
ref_str = ref_str + "\n"
else:
ref_str = ""
self.assertEqual(stream_2.getvalue(), ref_str)
示例2: testPrintHeader
# 需要导入模块: from KMCLib.Backend.Backend import MPICommons [as 别名]
# 或者: from KMCLib.Backend.Backend.MPICommons import myRank [as 别名]
def testPrintHeader(self):
""" Test the print header function. """
# Print to stdout.
original_sys_stdout = sys.stdout
try:
stream_1 = StringIO.StringIO()
sys.stdout = stream_1
# Print to stdout.
printHeader()
# Check.
if MPICommons.myRank() == 0:
ref_str = """# -----------------------------------------------------------------------------
# KMCLib version 1.1.01
# Distributed under the GPLv3 license
# Copyright (C) 2012-2015 Mikael Leetmaa
# Developed by Mikael Leetmaa <[email protected]>
#
# This program is distributed in the hope that it will be useful
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# LICENSE and README files, and the source code, for details.
#
# You should have received a copy of the GNU General Public License version 3
# (GPLv3) along with this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
"""
else:
ref_str = ""
# Check.
self.assertEqual(ref_str, stream_1.getvalue())
finally:
# Put the original stdout back.
sys.stdout = original_sys_stdout
# Print to another stream.
stream_2 = StringIO.StringIO()
prettyPrint(ref_str, output=stream_2)
# Check.
self.assertTrue(ref_str in stream_2.getvalue())