Ejemplo n.º 1
0
 def test_refresh_l_size(self):
     pgb_stream = StringIO()
     expected_stream = StringIO()
     pgb = ProgressBar(20, 3, stream=pgb_stream)
     pgb.refresh()
     expected_stream.write("\r["+' '*3+"]")
     self.assertEqual(pgb_stream.getvalue(), expected_stream.getvalue())
Ejemplo n.º 2
0
 def test_refresh(self):
     pgb_stream = StringIO()
     expected_stream = StringIO()
     pgb = ProgressBar(20, stream=pgb_stream)
     self.assertEqual(pgb_stream.getvalue(), expected_stream.getvalue()) # nothing print before refresh
     pgb.refresh()
     expected_stream.write("\r["+' '*20+"]")
     self.assertEqual(pgb_stream.getvalue(), expected_stream.getvalue())
Ejemplo n.º 3
0
 def test_update_relative(self):
     pgb_stream = StringIO()
     expected_stream = StringIO()
     size=20
     pgb = ProgressBar(100, size, stream=pgb_stream)
     last = 0
     for dots in range(5, 105, 5):
         pgb.update(5, exact=False)
         dots //= 5
         expected_stream.write("\r["+('='*dots)+(' '*(size-dots))+"]")
         self.assertEqual(pgb_stream.getvalue(), expected_stream.getvalue())
Ejemplo n.º 4
0
    def test_rewrite_config(self):
        changes = [('renamed', 'renamed', 'choice'),
                   ('moved', 'named', 'old', 'test'),
                   ]
        read_old_config(self.cfg, changes, join(DATA, 'test.ini'))
        stream = StringIO()
        self.cfg.generate_config(stream)
        self.assertMultiLineEqual(stream.getvalue().strip(), """[TEST]

dothis=yes

value='    '

# you can also document the option
multiple=yop

# boom
number=2

choice=yo

multiple-choice=yo,ye

named=key:val

reset-value='    '


[AGROUP]

diffgroup=pouet""")
Ejemplo n.º 5
0
 def setUp(self):
     self.stream = StringIO()
     self.table = Table()
     self.table.create_rows(['row1', 'row2', 'row3'])
     self.table.create_columns(['col1', 'col2'])
     self.writer = DocbookTableWriter(self.stream, self.table, None)
     self.writer.set_renderer(DocbookRenderer())
Ejemplo n.º 6
0
    def compute_content(self, layout):
        """trick to compute the formatting of children layout before actually
        writing it

        return an iterator on strings (one for each child element)
        """
        # use cells !
        def write(data):
            try:
                stream.write(data)
            except UnicodeEncodeError:
                stream.write(data.encode(self.encoding))
        def writeln(data=''):
            try:
                stream.write(data+linesep)
            except UnicodeEncodeError:
                stream.write(data.encode(self.encoding)+linesep)
        self.write = write
        self.writeln = writeln
        self.__compute_funcs.append((write, writeln))
        for child in layout.children:
            stream = StringIO()
            child.accept(self)
            yield stream.getvalue()
        self.__compute_funcs.pop()
        try:
            self.write, self.writeln = self.__compute_funcs[-1]
        except IndexError:
            del self.write
            del self.writeln
Ejemplo n.º 7
0
    def test_generate_config_with_space_string(self):
        self.cfg['value'] = '    '
        stream = StringIO()
        self.cfg.generate_config(stream)
        self.assertMultiLineEqual(stream.getvalue().strip(), """[TEST]

dothis=yes

value='    '

# you can also document the option
multiple=yop,yep

# boom
number=2

choice=yo

multiple-choice=yo,ye

named=key:val

reset-value='    '


[AGROUP]

diffgroup=pouet""")
Ejemplo n.º 8
0
 def setUp(self):
     """Builds a simple table to test the stylesheet
     """
     self.table = Table()
     self.table.create_row('row1')
     self.table.create_columns(['a', 'b', 'c'])
     self.stylesheet = TableStyleSheet()
     # We don't want anything to be printed
     self.stdout_backup = sys.stdout
     sys.stdout = StringIO()
Ejemplo n.º 9
0
 def _update_test(self, nbops, expected, size = None):
     pgb_stream = StringIO()
     expected_stream = StringIO()
     if size is None:
         pgb = ProgressBar(nbops, stream=pgb_stream)
         size=20
     else:
         pgb = ProgressBar(nbops, size, stream=pgb_stream)
     last = 0
     for round in expected:
         if not hasattr(round, '__int__'):
             dots, update = round
         else:
             dots, update = round, None
         pgb.update()
         if update or (update is None and dots != last):
             last = dots
             expected_stream.write("\r["+('='*dots)+(' '*(size-dots))+"]")
         self.assertEqual(pgb_stream.getvalue(), expected_stream.getvalue())
Ejemplo n.º 10
0
    def compute_content(self, layout: VNode) -> Generator[str, Any, None]:
        """trick to compute the formatting of children layout before actually
        writing it

        return an iterator on strings (one for each child element)
        """
        # use cells !
        def write(data: str) -> None:
            try:
                stream.write(data)
            except UnicodeEncodeError:
                # mypy: Argument 1 to "write" of "TextIOWrapper" has incompatible type "bytes";
                # mypy: expected "str"
                # error from porting to python3?
                stream.write(data.encode(self.encoding))  # type: ignore

        def writeln(data: str = "") -> None:
            try:
                stream.write(data + linesep)
            except UnicodeEncodeError:
                # mypy: Unsupported operand types for + ("bytes" and "str")
                # error from porting to python3?
                stream.write(data.encode(self.encoding) + linesep)  # type: ignore

        # mypy: Cannot assign to a method
        # this really looks like black dirty magic since self.write is reused elsewhere in the code
        # especially since self.write and self.writeln are conditionally
        # deleted at the end of this function
        self.write = write  # type: ignore
        self.writeln = writeln  # type: ignore

        self.__compute_funcs.append((write, writeln))

        # mypy: Item "Table" of "Union[ListType[Any], Table, Title]" has no attribute "children"
        # dynamic attribute?
        for child in layout.children:  # type: ignore
            stream = StringIO()

            child.accept(self)

            yield stream.getvalue()

        self.__compute_funcs.pop()

        try:
            # mypy: Cannot assign to a method
            # even more black dirty magic
            self.write, self.writeln = self.__compute_funcs[-1]  # type: ignore
        except IndexError:
            del self.write
            del self.writeln
Ejemplo n.º 11
0
 def _test_output(self, test_id, layout, msg=None):
     buffer = StringIO()
     self.writer.format(layout, buffer)
     got = buffer.getvalue()
     expected = getattr(self, test_id)
     try:
         self.assertMultiLineEqual(got, expected)
     except:
         print('**** got for %s' % test_id)
         print(got)
         print('**** while expected')
         print(expected)
         print('****')
         raise
Ejemplo n.º 12
0
 def colorize(source, start_lineno, curlineno):
     """colorize and annotate source with linenos
     (as in pdb's list command)
     """
     parser = PyColorize.Parser()
     output = StringIO()
     parser.format(source, output)
     annotated = []
     for index, line in enumerate(output.getvalue().splitlines()):
         lineno = index + start_lineno
         if lineno == curlineno:
             annotated.append('%4s\t->\t%s' % (lineno, line))
         else:
             annotated.append('%4s\t\t%s' % (lineno, line))
     return '\n'.join(annotated)
Ejemplo n.º 13
0
    def test_generate_config_with_multiline_string(self):
        self.cfg['value'] = 'line1\nline2\nline3'
        stream = StringIO()
        self.cfg.generate_config(stream)
        self.assertMultiLineEqual(
            stream.getvalue().strip(), """[TEST]

dothis=yes

value=
    line1
    line2
    line3

# you can also document the option
multiple=yop,yep

# boom
number=2

bytes=1KB

choice=yo

multiple-choice=yo,ye

named=key:val

reset-value=
    line1
    line2
    line3


[AGROUP]

diffgroup=pouet


[BGROUP]

#opt-b-1=

#opt-b-2=""")
Ejemplo n.º 14
0
    def test_generate_config(self):
        stream = StringIO()
        self.cfg.generate_config(stream)
        self.assertMultiLineEqual(
            stream.getvalue().strip(), """[TEST]

dothis=yes

#value=

# you can also document the option
multiple=yop,yep

# boom
number=2

bytes=1KB

choice=yo

multiple-choice=yo,ye

named=key:val

#reset-value=


[AGROUP]

diffgroup=pouet


[BGROUP]

#opt-b-1=

#opt-b-2=""")
Ejemplo n.º 15
0
 def test_manpage(self):
     pkginfo = {}
     with open(join(DATA, '__pkginfo__.py')) as fobj:
         exec(fobj.read(), pkginfo)
     self.cfg.generate_manpage(attrdict(pkginfo), stream=StringIO())
Ejemplo n.º 16
0
 def colorize_source(source):
     """colorize given source"""
     parser = PyColorize.Parser()
     output = StringIO()
     parser.format(source, output)
     return output.getvalue()
Ejemplo n.º 17
0
 def test_round_trip(self):
     cl = self.cl_class(self.cl_file)
     out = StringIO()
     cl.write(out)
     with open(self.cl_file) as stream:
         self.assertMultiLineEqual(stream.read(), out.getvalue())
Ejemplo n.º 18
0
 def test_manpage(self):
     from logilab.common import __pkginfo__
     self.cfg.generate_manpage(__pkginfo__, stream=StringIO())
Ejemplo n.º 19
0
 def setUp(self):
     output = StringIO()
     self.runner = SkipAwareTextTestRunner(stream=output, exitfirst=True)
Ejemplo n.º 20
0
 def setUp(self):
     self.loader = NonStrictTestLoader()
     self.module = TestLoaderTC  # mock_object(FooTC=TestLoaderTC.FooTC, BarTC=TestLoaderTC.BarTC)
     self.output = StringIO()
     self.runner = SkipAwareTextTestRunner(stream=self.output)