Пример #1
0
    def test_unhighlight_paren_bugs(self):
        """two previous bugs, parent didn't highlight until next render
        and paren didn't unhighlight until enter"""
        self.assertEqual(self.repl.rl_history.entries, [''])
        self.enter('(')
        self.assertEqual(self.repl.rl_history.entries, [''])
        screen = [">>> (",
                  "... "]
        self.assertEqual(self.repl.rl_history.entries, [''])
        self.assert_paint_ignoring_formatting(screen)
        self.assertEqual(self.repl.rl_history.entries, [''])

        with output_to_repl(self.repl):
            self.assertEqual(self.repl.rl_history.entries, [''])
            self.repl.process_event(')')
            self.assertEqual(self.repl.rl_history.entries, [''])
        screen = fsarray([cyan(">>> ") + on_magenta(bold(red('('))),
                         green("... ") + on_magenta(bold(red(')')))])
        self.assert_paint(screen, (1, 5))

        with output_to_repl(self.repl):
            self.repl.process_event(' ')
        screen = fsarray([cyan(">>> ") + yellow('('),
                         green("... ") + yellow(')') + bold(cyan(" "))])
        self.assert_paint(screen, (1, 6))
Пример #2
0
    def test_unhighlight_paren_bugs(self):
        """two previous bugs, parent didn't highlight until next render
        and paren didn't unhighlight until enter"""
        self.assertEqual(self.repl.rl_history.entries, [""])
        self.enter("(")
        self.assertEqual(self.repl.rl_history.entries, [""])
        screen = [">>> (", "... "]
        self.assertEqual(self.repl.rl_history.entries, [""])
        self.assert_paint_ignoring_formatting(screen)
        self.assertEqual(self.repl.rl_history.entries, [""])

        with output_to_repl(self.repl):
            self.assertEqual(self.repl.rl_history.entries, [""])
            self.repl.process_event(")")
            self.assertEqual(self.repl.rl_history.entries, [""])
        screen = fsarray(
            [
                cyan(">>> ") + on_magenta(bold(red("("))),
                green("... ") + on_magenta(bold(red(")"))),
            ]
        )
        self.assert_paint(screen, (1, 5))

        with output_to_repl(self.repl):
            self.repl.process_event(" ")
        screen = fsarray(
            [
                cyan(">>> ") + yellow("("),
                green("... ") + yellow(")") + bold(cyan(" ")),
            ]
        )
        self.assert_paint(screen, (1, 6))
Пример #3
0
 def test_argspec(self):
     def foo(x, y, z=10):
         "docstring!"
         pass
     argspec = inspection.getargspec('foo', foo) + [1]
     array = replpainter.formatted_argspec(argspec, 30, setup_config())
     screen = [(bold(cyan(u'foo'))+cyan(':')+cyan(' ')+cyan('(')+cyan('x') +
               yellow(',')+yellow(' ')+bold(cyan('y'))+yellow(',') +
               yellow(' ')+cyan('z')+yellow('=')+bold(cyan('10'))+yellow(')'))]
     self.assertFSArraysEqual(fsarray(array), fsarray(screen))
Пример #4
0
    def test_paint_lasts_events(self):
        actual = replpainter.paint_last_events(
            4, 100, ["a", "b", "c"], config=setup_config()
        )
        if config.supports_box_chars():
            expected = fsarray(["┌─┐", "│c│", "│b│", "└─┘"])
        else:
            expected = fsarray(["+-+", "|c|", "|b|", "+-+"])

        self.assertFSArraysEqualIgnoringFormatting(actual, expected)
Пример #5
0
 def test_argspec(self):
     def foo(x, y, z=10):
         "docstring!"
         pass
     argspec = inspection.getfuncprops('foo', foo)
     array = replpainter.formatted_argspec(argspec, 1, 30, setup_config())
     screen = [bold(cyan('foo')) + cyan(':') + cyan(' ') + cyan('(') +
               cyan('x') + yellow(',') + yellow(' ') + bold(cyan('y')) +
               yellow(',') + yellow(' ') + cyan('z') + yellow('=') +
               bold(cyan('10')) + yellow(')')]
     self.assertFSArraysEqual(fsarray(array), fsarray(screen))
Пример #6
0
    def test_argspec(self):
        def foo(x, y, z=10):
            "docstring!"
            pass

        argspec = inspection.getfuncprops("foo", foo)
        array = replpainter.formatted_argspec(argspec, 1, 30, setup_config())
        screen = [
            bold(cyan("foo")) + cyan(":") + cyan(" ") + cyan("(") + cyan("x") +
            yellow(",") + yellow(" ") + bold(cyan("y")) + yellow(",") +
            yellow(" ") + cyan("z") + yellow("=") + bold(cyan("10")) +
            yellow(")")
        ]
        assertFSArraysEqual(fsarray(array), fsarray(screen))
Пример #7
0
    def test_paint_lasts_events(self):
        actual = replpainter.paint_last_events(4, 100, ['a', 'b', 'c'],
                                               config=setup_config())
        if config.supports_box_chars():
            expected = fsarray(["┌─┐",
                                "│c│",
                                "│b│",
                                "└─┘"])
        else:
            expected = fsarray(["+-+",
                                "|c|",
                                "|b|",
                                "+-+"])

        self.assertFSArraysEqualIgnoringFormatting(actual, expected)
Пример #8
0
 def test_len_of_unicode(self):
     self.assertEqual(len(fmtstr('┌─')), 2)
     lines = ['┌─', 'an', '┌─']
     r = fsarray(lines)
     self.assertEqual(r.shape, (3, 2))
     self.assertEqual(len(fmtstr(fmtstr('┌─'))), len(fmtstr('┌─')))
     self.assertEqual(fmtstr(fmtstr('┌─')), fmtstr('┌─'))
Пример #9
0
 def test_formatted_docstring(self):
     actual = replpainter.formatted_docstring(
         'Returns the results\n\n' 'Also has side effects',
         40, config=setup_config())
     expected = fsarray(['Returns the results', '',
                         'Also has side effects'])
     self.assertFSArraysEqualIgnoringFormatting(actual, expected)
Пример #10
0
 def test_diff_testing(self):
     a = fsarray(["abc", "def"])
     b = fsarray(["abc", "dqf"])
     self.assertRaises(AssertionError, self.assertFSArraysEqual, a, b)
     a = fsarray([blue("abc"), red("def")])
     b = fsarray([blue("abc"), red("dqf")])
     self.assertRaises(AssertionError, self.assertFSArraysEqual, a, b)
     a = fsarray([blue("abc"), red("def")])
     b = fsarray([blue("abc"), red("d") + blue("e") + red("f")])
     self.assertRaises(AssertionError, self.assertFSArraysEqual, a, b)
     a = fsarray(["abc", "def"])
     b = fsarray(["abc", "def"])
     self.assertFSArraysEqual(a, b)
     a = fsarray([blue("abc"), red("def")])
     b = fsarray([blue("abc"), red("def")])
     self.assertFSArraysEqual(a, b)
Пример #11
0
 def test_len_of_unicode(self):
     self.assertEqual(len(fmtstr("┌─")), 2)
     lines = ["┌─", "an", "┌─"]
     r = fsarray(lines)
     self.assertEqual(r.shape, (3, 2))
     self.assertEqual(len(fmtstr(fmtstr("┌─"))), len(fmtstr("┌─")))
     self.assertEqual(fmtstr(fmtstr("┌─")), fmtstr("┌─"))
Пример #12
0
 def test_diff_testing(self):
     a = fsarray(['abc', 'def'])
     b = fsarray(['abc', 'dqf'])
     self.assertRaises(AssertionError, self.assertFSArraysEqual, a, b)
     a = fsarray([blue('abc'), red('def')])
     b = fsarray([blue('abc'), red('dqf')])
     self.assertRaises(AssertionError, self.assertFSArraysEqual, a, b)
     a = fsarray([blue('abc'), red('def')])
     b = fsarray([blue('abc'), red('d') + blue('e') + red('f')])
     self.assertRaises(AssertionError, self.assertFSArraysEqual, a, b)
     a = fsarray(['abc', 'def'])
     b = fsarray(['abc', 'def'])
     self.assertFSArraysEqual(a, b)
     a = fsarray([blue('abc'), red('def')])
     b = fsarray([blue('abc'), red('def')])
     self.assertFSArraysEqual(a, b)
Пример #13
0
 def test_len_of_unicode(self):
     self.assertEqual(len(fmtstr('┌─')), 2)
     lines = ['┌─', 'an', '┌─']
     r = fsarray(lines)
     self.assertEqual(r.shape, (3, 2))
     self.assertEqual(len(fmtstr(fmtstr('┌─'))), len(fmtstr('┌─')))
     self.assertEqual(fmtstr(fmtstr('┌─')), fmtstr('┌─'))
Пример #14
0
 def test_paint_lasts_events(self):
     actual = replpainter.paint_last_events(4, 100, ['a', 'b', 'c'], config=setup_config())
     expected = fsarray(["┌─┐",
                         "│c│",
                         "│b│",
                         "└─┘"])
     self.assertFSArraysEqualIgnoringFormatting(actual, expected)
Пример #15
0
 def test_diff_testing(self):
     a = fsarray(['abc', 'def'])
     b = fsarray(['abc', 'dqf'])
     self.assertRaises(AssertionError, self.assertFSArraysEqual, a, b)
     a = fsarray([blue('abc'), red('def')])
     b = fsarray([blue('abc'), red('dqf')])
     self.assertRaises(AssertionError, self.assertFSArraysEqual, a, b)
     a = fsarray([blue('abc'), red('def')])
     b = fsarray([blue('abc'), red('d')+blue('e')+red('f')])
     self.assertRaises(AssertionError, self.assertFSArraysEqual, a, b)
     a = fsarray(['abc', 'def'])
     b = fsarray(['abc', 'def'])
     self.assertFSArraysEqual(a, b)
     a = fsarray([blue('abc'), red('def')])
     b = fsarray([blue('abc'), red('def')])
     self.assertFSArraysEqual(a, b)
Пример #16
0
 def test_formatted_docstring(self):
     actual = replpainter.formatted_docstring(
         'Returns the results\n\n' 'Also has side effects',
         40, config=setup_config())
     expected = fsarray(['Returns the results', '',
                         'Also has side effects'])
     self.assertFSArraysEqualIgnoringFormatting(actual, expected)
Пример #17
0
 def test_formatted_docstring(self):
     actual = replpainter.formatted_docstring(
         "Returns the results\n\n" "Also has side effects",
         40,
         config=setup_config(),
     )
     expected = fsarray(["Returns the results", "", "Also has side effects"])
     self.assertFSArraysEqualIgnoringFormatting(actual, expected)
Пример #18
0
 def test_enter_text(self):
     [self.repl.add_normal_character(c) for c in '1 + 1']
     screen = fsarray([
         cyan('>>> ') + bold(
             green('1') + cyan(' ') + yellow('+') + cyan(' ') + green('1')),
         cyan('Welcome to')
     ])
     self.assert_paint(screen, (0, 9))
Пример #19
0
 def test_enter_text(self):
     [self.repl.add_normal_character(c) for c in "1 + 1"]
     screen = fsarray([
         cyan(">>> ") + bold(
             green("1") + cyan(" ") + yellow("+") + cyan(" ") + green("1")),
         cyan("Welcome to"),
     ])
     self.assert_paint(screen, (0, 9))
Пример #20
0
 def test_run_line(self):
     try:
         orig_stdout = sys.stdout
         sys.stdout = self.repl.stdout
         [self.repl.add_normal_character(c) for c in '1 + 1']
         self.repl.on_enter(insert_into_history=False)
         screen = fsarray(['>>> 1 + 1', '2', 'Welcome to'])
         self.assert_paint_ignoring_formatting(screen, (1, 1))
     finally:
         sys.stdout = orig_stdout
Пример #21
0
 def test_run_line(self):
     try:
         orig_stdout = sys.stdout
         sys.stdout = self.repl.stdout
         [self.repl.add_normal_character(c) for c in '1 + 1']
         self.repl.on_enter(insert_into_history=False)
         screen = fsarray(['>>> 1 + 1', '2', 'Welcome to'])
         self.assert_paint_ignoring_formatting(screen, (1, 1))
     finally:
         sys.stdout = orig_stdout
Пример #22
0
 def test_run_line(self):
     try:
         orig_stdout = sys.stdout
         sys.stdout = self.repl.stdout
         [self.repl.add_normal_character(c) for c in "1 + 1"]
         self.repl.on_enter(new_code=False)
         screen = fsarray([">>> 1 + 1", "2", "Welcome to"])
         self.assert_paint_ignoring_formatting(screen, (1, 1))
     finally:
         sys.stdout = orig_stdout
Пример #23
0
    def test_unicode_docstrings(self):
        "A bit of a special case in Python 2"
        # issue 653

        def foo():
            u"åß∂ƒ"

        actual = replpainter.formatted_docstring(
                     foo.__doc__, 40, config=setup_config())
        expected = fsarray([u'åß∂ƒ'])
        self.assertFSArraysEqualIgnoringFormatting(actual, expected)
Пример #24
0
    def test_unicode_docstrings(self):
        "A bit of a special case in Python 2"
        # issue 653

        def foo():
            "åß∂ƒ"

        actual = replpainter.formatted_docstring(
            foo.__doc__, 40, config=setup_config()
        )
        expected = fsarray(["åß∂ƒ"])
        self.assertFSArraysEqualIgnoringFormatting(actual, expected)
Пример #25
0
    def test_weird_boto_docstrings(self):
        # Boto does something like this.
        # botocore: botocore/docs/docstring.py
        class WeirdDocstring(str):
            # a mighty hack. See botocore/docs/docstring.py
            def expandtabs(self, tabsize=8):
                return u'asdfåß∂ƒ'.expandtabs(tabsize)

        def foo():
            pass

        foo.__doc__ = WeirdDocstring()
        wd = pydoc.getdoc(foo)
        actual = replpainter.formatted_docstring(wd, 40, config=setup_config())
        expected = fsarray([u'asdfåß∂ƒ'])
        self.assertFSArraysEqualIgnoringFormatting(actual, expected)
Пример #26
0
    def test_weird_boto_docstrings(self):
        # Boto does something like this.
        # botocore: botocore/docs/docstring.py
        class WeirdDocstring(str):
            # a mighty hack. See botocore/docs/docstring.py
            def expandtabs(self, tabsize=8):
                return "asdfåß∂ƒ".expandtabs(tabsize)

        def foo():
            pass

        foo.__doc__ = WeirdDocstring()
        wd = pydoc.getdoc(foo)
        actual = replpainter.formatted_docstring(wd, 40, config=setup_config())
        expected = fsarray(["asdfåß∂ƒ"])
        self.assertFSArraysEqualIgnoringFormatting(actual, expected)
Пример #27
0
 def test_enter_text(self):
     [self.repl.add_normal_character(c) for c in '1 + 1']
     screen = fsarray([cyan('>>> ') + bold(green('1') + cyan(' ') +
                       yellow('+') + cyan(' ') + green('1')),
                       cyan('Welcome to')])
     self.assert_paint(screen, (0, 9))
Пример #28
0
 def test_startup(self):
     screen = fsarray([cyan('>>> '), cyan('Welcome to')])
     self.assert_paint(screen, (0, 4))
Пример #29
0
 def test_oomerror(self):
     a = FSArray(10, 40)
     a[2:-2, 2:-2] = fsarray(["asdf", "zxcv"])
Пример #30
0
 def test_startup(self):
     screen = fsarray([cyan('>>> '), cyan('Welcome to')])
     self.assert_paint(screen, (0, 4))
Пример #31
0
 def test_oomerror(self):
     a = FSArray(10, 40)
     a[2:-2, 2:-2] = fsarray(['asdf', 'zxcv'])
Пример #32
0
 def test_oomerror(self):
     a = FSArray(10, 40)
     a[2:-2, 2:-2] = fsarray(['asdf', 'zxcv'])
Пример #33
0
 def test_startup(self):
     screen = fsarray([cyan(">>> "), cyan("Welcome to")])
     self.assert_paint(screen, (0, 4))