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


Python testfixtures.generator函数代码示例

本文整理汇总了Python中testfixtures.generator函数的典型用法代码示例。如果您正苦于以下问题:Python generator函数的具体用法?Python generator怎么用?Python generator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_generator_second_shorted

 def test_generator_second_shorted(self):
     self.checkRaises(
         generator(1, 2, 3), generator(1, 2),
         "Sequence not as expected:\n\n"
         "same:\n(1, 2)\n\n"
         "first:\n(3,)\n\n"
         "second:\n()")
开发者ID:babbageclunk,项目名称:testfixtures,代码行数:7,代码来源:test_compare.py

示例2: test_generator_different

 def test_generator_different(self):
     self.checkRaises(
         generator(1, 2, 3), generator(1, 2, 4),
         "Sequence not as expected:\n\n"
         "same:\n(1, 2)\n\n"
         "first:\n(3,)\n\n"
         "second:\n(4,)")
开发者ID:babbageclunk,项目名称:testfixtures,代码行数:7,代码来源:test_compare.py

示例3: test_generator_totally_different

 def test_generator_totally_different(self):
     self.check_raises(
         generator(1, ), generator(2, ),
         "sequence not as expected:\n\n"
         "same:\n()\n\n"
         "first:\n(1,)\n\n"
         "second:\n(2,)"
         )
开发者ID:nebulans,项目名称:testfixtures,代码行数:8,代码来源:test_compare.py

示例4: test_generator_first_shorter

 def test_generator_first_shorter(self):
     self.check_raises(
         generator(1, 2), generator(1, 2, 3),
         "sequence not as expected:\n\n"
         "same:\n(1, 2)\n\n"
         "first:\n()\n\n"
         "second:\n(3,)"
         )
开发者ID:nebulans,项目名称:testfixtures,代码行数:8,代码来源:test_compare.py

示例5: test_nested_labels

 def test_nested_labels(self):
     obj1 = singleton('obj1')
     obj2 = singleton('obj2')
     gen1 = generator(obj1, obj2)
     gen2 = generator(obj1, )
     # dict -> list -> tuple -> generator
     self.check_raises(
         dict(x=[1, ('a', 'b', gen1), 3], y=[3, 4]),
         dict(x=[1, ('a', 'b', gen2), 3], y=[3, 4]), (
             "dict not as expected:\n"
             "\n"
             "same:\n"
             "['y']\n"
             "\n"
             "values differ:\n"
             "'x': [1, ('a', 'b', {gen1}), 3] (expected) != "
             "[1, ('a', 'b', {gen2}), 3] (actual)\n"
             "\n"
             "While comparing ['x']: sequence not as expected:\n"
             "\n"
             "same:\n"
             "[1]\n"
             "\n"
             "expected:\n"
             "[('a', 'b', {gen1}), 3]\n"
             "\n"
             "actual:\n"
             "[('a', 'b', {gen2}), 3]\n"
             "\n"
             "While comparing ['x'][1]: sequence not as expected:\n"
             "\n"
             "same:\n"
             "('a', 'b')\n"
             "\n"
             "expected:\n"
             "({gen1},)\n"
             "\n"
             "actual:\n"
             "({gen2},)\n"
             "\n"
             "While comparing ['x'][1][2]: sequence not as expected:\n"
             "\n"
             "same:\n"
             "(<obj1>,)\n"
             "\n"
             "expected:\n"
             "(<obj2>,)\n"
             "\n"
             "actual:\n"
             "()"
             ).format(gen1=hexsub(repr(gen1)),
                      gen2=hexsub(repr(gen2))),
         x_label='expected',
         y_label='actual',
         )
开发者ID:nebulans,项目名称:testfixtures,代码行数:55,代码来源:test_compare.py

示例6: test_deep_breadcrumbs

 def test_deep_breadcrumbs(self):
     obj1 = singleton('obj1')
     obj2 = singleton('obj2')
     gen1 = generator(obj1, obj2)
     gen2 = generator(obj1, )
     # dict -> list -> tuple -> generator
     self.check_raises(
         dict(x=[1, ('a', 'b', gen1), 3], y=[3, 4]),
         dict(x=[1, ('a', 'b', gen2), 3], y=[3, 4]), (
             "dict not as expected:\n"
             "\n"
             "same:\n"
             "['y']\n"
             "\n"
             "values differ:\n"
             "'x': [1, ('a', 'b', {gen1}), 3] != [1, ('a', 'b', {gen2}), 3]"
             "\n\n"
             "While comparing ['x']: sequence not as expected:\n"
             "\n"
             "same:\n"
             "[1]\n"
             "\n"
             "first:\n"
             "[('a', 'b', {gen1}), 3]\n"
             "\n"
             "second:\n"
             "[('a', 'b', {gen2}), 3]\n"
             "\n"
             "While comparing ['x'][1]: sequence not as expected:\n"
             "\n"
             "same:\n"
             "('a', 'b')\n"
             "\n"
             "first:\n"
             "({gen1},)\n"
             "\n"
             "second:\n"
             "({gen2},)\n"
             "\n"
             "While comparing ['x'][1][2]: sequence not as expected:\n"
             "\n"
             "same:\n"
             "(<obj1>,)\n"
             "\n"
             "first:\n"
             "(<obj2>,)\n"
             "\n"
             "second:\n"
             "()"
             ).format(gen1=hexsub(repr(gen1)),
                      gen2=hexsub(repr(gen2)))
         )
开发者ID:nebulans,项目名称:testfixtures,代码行数:52,代码来源:test_compare.py

示例7: test_nested_generator_different

 def test_nested_generator_different(self):
     self.check_raises(
         generator(1, 2, generator(3), 4),
         generator(1, 2, generator(3), 5),
         "sequence not as expected:\n"
         "\n"
         "same:\n"
         "(1, 2, <generator object generator at ...>)\n"
         "\n"
         "first:\n"
         "(4,)\n"
         "\n"
         "second:\n"
         "(5,)"
         )
开发者ID:nebulans,项目名称:testfixtures,代码行数:15,代码来源:test_compare.py

示例8: test_simple

    def test_simple(self):
        # we use our own parser to get a convertor and a constant in there
        class TheParser(Parser):
            
            class ARecord(Record):
                prefix = Discriminator('A')
                data = Field(2, int)
                const = Field(1, one_of(
                    x = Constant('X', 'an X'),
                    y = Constant('Y', 'a Y'),
                    ))
                    
            class BRecord(Record):
                prefix = Discriminator('B')
                d1 = Field(2)
                d2 = Field(2)

        compare(generator(
            TheParser.BRecord.type(prefix='B', d1='XX', d2='YY'),
            TheParser.ARecord.type(prefix='A',
                                   data=2,
                                   const=TheParser.ARecord.const.x
                                   ),
            TheParser.ARecord.type(prefix='A',
                                   data=13,
                                   const=TheParser.ARecord.const.y),
            ), TheParser(['BXXYY', 'A 2X', 'A13Y']))
开发者ID:APSL,项目名称:fixed,代码行数:27,代码来源:test_parser.py

示例9: test_short_lines_for_disc

 def test_short_lines_for_disc(self):
     compare(generator(
         C('fixed.UnknownRecordType',
           discriminator='',
           line='',
           args=())
         ), self.parser(['']))
开发者ID:APSL,项目名称:fixed,代码行数:7,代码来源:test_parser.py

示例10: test_generator_and_sequence

 def test_generator_and_sequence(self):
     expected = compile(
         "\(1, 2, 3\) != <generator object (generator )?at ...>")
     self.checkRaises(
         (1, 2, 3),
         generator(1, 2, 3),
         regex=expected,
     )
开发者ID:babbageclunk,项目名称:testfixtures,代码行数:8,代码来源:test_compare.py

示例11: test_file

 def test_file(self):
     with TempDirectory() as dir:
         path = dir.write('file', 'AXX\nBYY\n')
         with open(path) as source:
             compare(generator(
                 self.parser.ARecord.type('A', 'XX'),
                 self.parser.BRecord.type('B', 'YY'),
                 ), self.parser(source))
开发者ID:APSL,项目名称:fixed,代码行数:8,代码来源:test_parser.py

示例12: test_generator_with_buggy_generator

    def test_generator_with_buggy_generator(self):
        def bad_gen():
            yield 1
            # raising a TypeError here is important :-/
            raise TypeError('foo')

        with ShouldRaise(TypeError('foo')):
            compare(generator(1, 2, 3), bad_gen())
开发者ID:nebulans,项目名称:testfixtures,代码行数:8,代码来源:test_compare.py

示例13: test_fixed_width

 def test_fixed_width(self):
     # make sure file wrapped with iterator works
     with TempDirectory() as dir:
         path = dir.write('file', 'AXXBYY')
         with open(path) as source:
             compare(generator(
                 self.parser.ARecord.type('A', 'XX'),
                 self.parser.BRecord.type('B', 'YY'),
                 ), self.parser(Chunker(source, 3)))
开发者ID:APSL,项目名称:fixed,代码行数:9,代码来源:test_parser.py

示例14: test_unknown_record_type_returns

 def test_unknown_record_type_returns(self):
     # Return rather than raise exception.
     # This is optimised to be fast.
     compare(generator(
         C('fixed.UnknownRecordType',
           discriminator='C',
           line='CXX',
           args=())
         ), self.parser(['CXX']))
开发者ID:APSL,项目名称:fixed,代码行数:9,代码来源:test_parser.py

示例15: test_sequence_and_generator_strict

 def test_sequence_and_generator_strict(self):
     expected = compile(
         "\(1, 2, 3\) \(<(class|type) 'tuple'>\) != "
         "<generator object (generator )?at... "
         "\(<(class|type) 'generator'>\)"
         )
     self.checkRaises(
         (1,2,3), generator(1,2,3),
         regex=expected,
         strict=True,
         )
开发者ID:hwkns,项目名称:testfixtures,代码行数:11,代码来源:test_compare.py


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