Exemplo n.º 1
0
    def test_displayNone(self):
        fio = FakeIO()

        with fio:
            displayPretty(None)

        fio.checkLiteral(self, '', '')
Exemplo n.º 2
0
        def test_output(arg, expected):
            sh = self.scope['sh']

            fio = FakeIO()
            with fio:
                result = sh(arg)

            self.assertIsNone(result,
                              'sh() returned non-None: %r' % (result, ))
            fio.checkLiteral(self, expected, '')
Exemplo n.º 3
0
    def test_displayValues(self):
        for value in [42, "banana", range(1024), vars()]:
            f = StringIO()
            pprint.pprint(value, f)
            expected = f.getvalue()

            fio = FakeIO()

            with fio:
                displayPretty(value)

            fio.checkLiteral(self, expected, '')
Exemplo n.º 4
0
    def test_magicFunctionNamesMatchBinding(self):
        for (name, _) in self.scope.getMagicDocs():
            with FakeIO():
                value = self.scope[name]

            if isinstance(value, FunctionType):
                self.assertEqual(name, value.__name__)
Exemplo n.º 5
0
    def test_inputCaching(self):
        rawin = 'foo\nbar\n\n'
        stripin = rawin.strip()
        rlines = rawin.split('\n')
        lines = [l.strip() for l in rlines]

        with FakeIO(rawin):
            for i in range(2):
                self.assertEqual(rawin, self.scope['ri'])
                self.assertEqual(stripin, self.scope['i'])
                self.assertEqual(rlines, self.scope['rlines'])
                self.assertEqual(lines, self.scope['lines'])
                self.assertIsInstance(self.scope['help'], HelpBrowser)
Exemplo n.º 6
0
    def test_helpAlias(self):
        fio = FakeIO()
        with fio:
            main(['help'])

        (expected, error) = fio.getOutputs()
        self.assertEqual('', error)

        for args in [[], ['-h'], ['--help']]:
            fio = FakeIO()
            with fio:
                main(args)

            fio.checkLiteral(self, expected, '')
Exemplo n.º 7
0
    def test_docs(self):

        hb = HelpBrowser(buildStandardMagicScope([]))

        count = 0

        topics = [(topic, hb.getTopicText(topic)) for topic in hb.getTopics()]

        for (topicname, helptext) in topics:
            for (expr, args, inputText,
                 outlines) in self._parseEntries(helptext):
                count += 1
                try:
                    if inputText is None:
                        inputText = ''

                    expectedOut = '\n'.join(outlines)

                    # Implement wildcard matches on "...":
                    expectedRawPattern = re.escape(expectedOut)
                    expectedPattern = expectedRawPattern.replace(
                        r'\.\.\.', '.*?')
                    expectedRgx = re.compile(expectedPattern, re.DOTALL)

                    fio = FakeIO(inputText + '\n')

                    with fio:
                        try:
                            main([expr] + args)
                        except Exception:
                            traceback.print_exc(file=fio.fakeerr)

                    if expectedOut.startswith(
                            'Traceback (most recent call last)'):
                        fio.checkRegexp(self, '^$', expectedRgx)
                    else:
                        fio.checkRegexp(self, expectedRgx, '^$')

                except Exception, e:
                    e.args += (
                        'In topic %r' % (topicname, ),
                        'In EXPR %r' % (expr, ),
                    )
                    raise
Exemplo n.º 8
0
    def test_fortytwo(self):
        fio = FakeIO()
        with fio:
            main(['42'])

        fio.checkLiteral(self, '42\n', '')
Exemplo n.º 9
0
    def test_scopeRepr(self):
        fio = FakeIO()
        with fio:
            main(['scope'])

        fio.checkRegexp(self, '^<MagicScope \[.*\]>$', '^$')