当前位置: 首页>>代码示例>>Python>>正文


Python StringIO.readlines方法代码示例

本文整理汇总了Python中six.moves.StringIO.readlines方法的典型用法代码示例。如果您正苦于以下问题:Python StringIO.readlines方法的具体用法?Python StringIO.readlines怎么用?Python StringIO.readlines使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在six.moves.StringIO的用法示例。


在下文中一共展示了StringIO.readlines方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_split_at_with_header

# 需要导入模块: from six.moves import StringIO [as 别名]
# 或者: from six.moves.StringIO import readlines [as 别名]
    def test_split_at_with_header(self):
        source = StringIO("""@header1
AGCTTTTT
+
@IIIB+++
@header2
AGCTTTTT
+
IIIIB+++
""")
        target1 = StringIO()
        target2 = StringIO()

        srf2fastq.convert_single_to_two_fastq(source, target1, target2, header="foo_")

        target1.seek(0)
        lines1 = target1.readlines()
        self.assertEqual(len(lines1),8)
        self.assertEqual(lines1[0].rstrip(), '@foo_header1/1')
        self.assertEqual(lines1[1].rstrip(), 'AGCT')
        self.assertEqual(lines1[2].rstrip(), '+')
        self.assertEqual(lines1[3].rstrip(), '@III')

        target2.seek(0)
        lines2 = target2.readlines()
        self.assertEqual(len(lines2),8)
        self.assertEqual(lines2[0].rstrip(), '@foo_header1/2')
        self.assertEqual(lines2[1].rstrip(), 'TTTT')
        self.assertEqual(lines2[2].rstrip(), '+')
        self.assertEqual(lines2[3].rstrip(), 'B+++')
开发者ID:detrout,项目名称:htsworkflow,代码行数:32,代码来源:test_srf2fastq.py

示例2: test_split_good

# 需要导入模块: from six.moves import StringIO [as 别名]
# 或者: from six.moves.StringIO import readlines [as 别名]
    def test_split_good(self):
        source = StringIO("""@header
AGCTTTTT
+
IIIIB+++
""")
        target1 = StringIO()
        target2 = StringIO()

        srf2fastq.convert_single_to_two_fastq(source, target1, target2)

        target1.seek(0)
        lines1 = target1.readlines()
        self.assertEqual(len(lines1),4)
        self.assertEqual(lines1[0].rstrip(), '@header/1')
        self.assertEqual(lines1[1].rstrip(), 'AGCT')
        self.assertEqual(lines1[2].rstrip(), '+')
        self.assertEqual(lines1[3].rstrip(), 'IIII')

        target2.seek(0)
        lines2 = target2.readlines()
        self.assertEqual(len(lines2),4)
        self.assertEqual(lines2[0].rstrip(), '@header/2')
        self.assertEqual(lines2[1].rstrip(), 'TTTT')
        self.assertEqual(lines2[2].rstrip(), '+')
        self.assertEqual(lines2[3].rstrip(), 'B+++')
开发者ID:detrout,项目名称:htsworkflow,代码行数:28,代码来源:test_srf2fastq.py

示例3: TestProgressMeter

# 需要导入模块: from six.moves import StringIO [as 别名]
# 或者: from six.moves.StringIO import readlines [as 别名]
class TestProgressMeter(TestCase):
    def setUp(self):
        self.buf = StringIO()

    def tearDown(self):
        del self.buf

    def _assert_in(self, output, string):
        assert_(string in output,
                "Output '{0}' does not match required format '{1}'.".format(
                output.replace('\r', '\\r'), string))


    def test_default_ProgressMeter(self, n=101, interval=10):
        format = "Step %(step)5d/%(numsteps)d [%(percentage)5.1f%%]\r"
        with RedirectedStderr(self.buf):
            pm = MDAnalysis.lib.log.ProgressMeter(n, interval=interval)
            for frame in range(n):
                pm.echo(frame)
        self.buf.seek(0)
        output = "".join(self.buf.readlines())
        self._assert_in(output, format % {'step': 1, 'numsteps': n, 'percentage': 100./n})
        # last line always has \n instead of \r!
        self._assert_in(output, format.replace('\r', '\n') %
                        {'step': n, 'numsteps': n, 'percentage': 100.})

    def test_custom_ProgressMeter(self, n=51, interval=7):
        format = "RMSD %(rmsd)5.2f at %(step)03d/%(numsteps)4d [%(percentage)5.1f%%]\r"
        with RedirectedStderr(self.buf):
            pm = MDAnalysis.lib.log.ProgressMeter(n, interval=interval,
                                                  format=format, offset=1)
            for frame in range(n):
                rmsd = 0.02 * frame * (n+1)/float(n)  # n+1/n correction for 0-based frame vs 1-based counting
                pm.echo(frame, rmsd=rmsd)
        self.buf.seek(0)
        output = "".join(self.buf.readlines())
        self._assert_in(output, format %
                        {'rmsd': 0.0, 'step': 1, 'numsteps': n, 'percentage': 100./n})
        # last line always has \n instead of \r!
        self._assert_in(output, format.replace('\r', '\n') %
                        {'rmsd': 0.02*n, 'step': n, 'numsteps': n, 'percentage': 100.0})
开发者ID:BartBruininks,项目名称:mdanalysis,代码行数:43,代码来源:test_log.py

示例4: test_single_at

# 需要导入模块: from six.moves import StringIO [as 别名]
# 或者: from six.moves.StringIO import readlines [as 别名]
    def test_single_at(self):
        source = StringIO("""@header1
AGCTTTTT
+
@IIIB+++
@header2
AGCTTTTT
+
IIIIB+++
""")
        target1 = StringIO()

        srf2fastq.convert_single_to_fastq(source, target1)

        target1.seek(0)
        lines1 = target1.readlines()
        self.assertEqual(len(lines1),8)
        self.assertEqual(lines1[0].rstrip(), '@header1')
        self.assertEqual(lines1[1].rstrip(), 'AGCTTTTT')
        self.assertEqual(lines1[2].rstrip(), '+')
        self.assertEqual(lines1[3].rstrip(), '@IIIB+++')
开发者ID:detrout,项目名称:htsworkflow,代码行数:23,代码来源:test_srf2fastq.py

示例5: len

# 需要导入模块: from six.moves import StringIO [as 别名]
# 或者: from six.moves.StringIO import readlines [as 别名]
            log.removeHandler(logging_handler)
            args_obj, _, _ = app.make_cli_parser().interpret_args(['--verbose'])
            logging_handler = app.setup_logging(args_obj)
            log.debug("this one is captured")

            log.removeHandler(logging_handler)
            args_obj, _, _ = app.make_cli_parser().interpret_args(['--silent'])
            logging_handler = app.setup_logging(args_obj)
            log.debug("not captured")
            log.warning("not captured")
            log.info("not captured")
            log.error("also captured")

            fle.flush()
            fle.seek(0)
            logs = fle.readlines()
            now = datetime.datetime.now()
            date = now.strftime("%Y-%m-%d [^ ]+")
            expect = [
                  re.compile("{0} INFO    blah            hello there".format(date))
                , re.compile("{0} ERROR   blah            hmmm".format(date))
                , re.compile("{0} WARNING blah            yeap".format(date))
                , re.compile("{0} DEBUG   blah            this one is captured".format(date))
                , re.compile("{0} ERROR   blah            also captured".format(date))
                ]

            self.assertEqual(len(expect), len(logs), logs)
            for index, line in enumerate(expect):
                assert line.match(logs[index].strip()), "Expected '{0}' to match '{1}'".format(logs[index].strip().replace('\t', '\\t').replace(' ', '.'), line.pattern.replace('\t', '\\t').replace(' ', '.'))

    describe "make_cli_parser":
开发者ID:delfick,项目名称:delfick_app,代码行数:33,代码来源:test_the_app.py


注:本文中的six.moves.StringIO.readlines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。