Esempio n. 1
0
    def test_doctest_main_issue4197(self):
        test_src = textwrap.dedent("""\
                    class Test:
                        ">>> 'line 2'"
                        pass

                    import doctest
                    doctest.testmod()
                    """)
        pattern = 'File "%s", line 2, in %s'
        with temp_dir() as d:
            script_name = make_script(d, 'script', test_src)
            exit_code, data = run_python(script_name)
            expected = pattern % (script_name, "__main__.Test")
            if verbose:
                print "Expected line", expected
                print "Got stdout:"
                print data
            self.assertIn(expected, data)
            zip_name, run_name = make_zip_script(d, "test_zip",
                                                script_name, '__main__.py')
            exit_code, data = run_python(zip_name)
            expected = pattern % (run_name, "__main__.Test")
            if verbose:
                print "Expected line", expected
                print "Got stdout:"
                print data
            self.assertIn(expected, data)
Esempio n. 2
0
    def test_doctest_main_issue4197(self):
        test_src = textwrap.dedent("""\
                    class Test:
                        ">>> 'line 2'"
                        pass

                    import doctest
                    doctest.testmod()
                    """)
        pattern = 'File "%s", line 2, in %s'
        with temp_dir() as d:
            script_name = make_script(d, 'script', test_src)
            exit_code, data = run_python(script_name)
            expected = pattern % (script_name, "__main__.Test")
            if verbose:
                print "Expected line", expected
                print "Got stdout:"
                print data
            self.assertIn(expected, data)
            zip_name, run_name = make_zip_script(d, "test_zip",
                                                script_name, '__main__.py')
            exit_code, data = run_python(zip_name)
            expected = pattern % (run_name, "__main__.Test")
            if verbose:
                print "Expected line", expected
                print "Got stdout:"
                print data
            self.assertIn(expected, data)
Esempio n. 3
0
 def _check_import_error(self, script_name, expected_msg, *cmd_line_switches):
     run_args = cmd_line_switches + (script_name,)
     exit_code, data = run_python(*run_args)
     if verbose:
         print "Output from test script %r:" % script_name
         print data
         print "Expected output: %r" % expected_msg
     self.assertIn(expected_msg, data)
Esempio n. 4
0
 def _check_import_error(self, script_name, expected_msg,
                         *cmd_line_switches):
     run_args = cmd_line_switches + (script_name, )
     exit_code, data = run_python(*run_args)
     if verbose:
         print 'Output from test script %r:' % script_name
         print data
         print 'Expected output: %r' % expected_msg
     self.assertIn(expected_msg, data)
Esempio n. 5
0
 def _check_script(self, script_name, expected_file, expected_argv0, expected_package, *cmd_line_switches):
     run_args = cmd_line_switches + (script_name,)
     exit_code, data = run_python(*run_args)
     if verbose:
         print "Output from test script %r:" % script_name
         print data
     self.assertEqual(exit_code, 0)
     printed_file = "__file__==%r" % expected_file
     printed_argv0 = "sys.argv[0]==%r" % expected_argv0
     printed_package = "__package__==%r" % expected_package
     if verbose:
         print "Expected output:"
         print printed_file
         print printed_package
         print printed_argv0
     self.assertIn(printed_file, data)
     self.assertIn(printed_package, data)
     self.assertIn(printed_argv0, data)
Esempio n. 6
0
 def _check_script(self, script_name, expected_file, expected_argv0,
                   expected_package, *cmd_line_switches):
     run_args = cmd_line_switches + (script_name, )
     exit_code, data = run_python(*run_args)
     if verbose:
         print 'Output from test script %r:' % script_name
         print data
     self.assertEqual(exit_code, 0)
     printed_file = '__file__==%r' % expected_file
     printed_argv0 = 'sys.argv[0]==%r' % expected_argv0
     printed_package = '__package__==%r' % expected_package
     if verbose:
         print 'Expected output:'
         print printed_file
         print printed_package
         print printed_argv0
     self.assertIn(printed_file, data)
     self.assertIn(printed_package, data)
     self.assertIn(printed_argv0, data)
Esempio n. 7
0
 def test_surrogates(self):
     # Issue #8438: try to open a filename containing surrogates.
     # It should either fail because the file doesn't exist or the filename
     # can't be represented using the filesystem encoding, but not because
     # of a LookupError for the error handler "surrogateescape".
     filename = u'\udc80.txt'
     try:
         with _FileIO(filename):
             pass
     except (UnicodeEncodeError, IOError):
         pass
     # Spawn a separate Python process with a different "file system
     # default encoding", to exercise this further.
     env = dict(os.environ)
     env[b'LC_CTYPE'] = b'C'
     _, out = run_python('-c', 'import _io; _io.FileIO(%r)' % filename, env=env)
     if ('UnicodeEncodeError' not in out and
         'IOError: [Errno 2] No such file or directory' not in out):
         self.fail('Bad output: %r' % out)
Esempio n. 8
0
 def test_surrogates(self):
     # Issue #8438: try to open a filename containing surrogates.
     # It should either fail because the file doesn't exist or the filename
     # can't be represented using the filesystem encoding, but not because
     # of a LookupError for the error handler "surrogateescape".
     filename = u'\udc80.txt'
     try:
         with _FileIO(filename):
             pass
     except (UnicodeEncodeError, IOError):
         pass
     # Spawn a separate Python process with a different "file system
     # default encoding", to exercise this further.
     env = dict(os.environ)
     env[b'LC_CTYPE'] = b'C'
     _, out = run_python('-c', 'import _io; _io.FileIO(%r)' % filename, env=env)
     if ('UnicodeEncodeError' not in out and
         'IOError: [Errno 2] No such file or directory' not in out):
         self.fail('Bad output: %r' % out)
 def _check_script(self, script_name, expected_file,
                         expected_argv0, expected_package,
                         *cmd_line_switches):
     run_args = cmd_line_switches + (script_name,)
     exit_code, data = run_python(*run_args)
     if verbose:
         print 'Output from test script %r:' % script_name
         print data
     self.assertEqual(exit_code, 0)
     printed_file = '__file__==%r' % str(expected_file)
     printed_argv0 = 'sys.argv[0]==%r' % str(expected_argv0)
     printed_package = '__package__==%r' % (str(expected_package) if expected_package is not None else expected_package)
     if verbose:
         print 'Expected output:'
         print printed_file
         print printed_package
         print printed_argv0
     self.assertIn(printed_file, data)
     self.assertIn(printed_package, data)
     self.assertIn(printed_argv0, data)
Esempio n. 10
0
 def test_surrogates(self):
     # Issue #8438: try to open a filename containing surrogates.
     # It should either fail because the file doesn't exist or the filename
     # can't be represented using the filesystem encoding, but not because
     # of a LookupError for the error handler "surrogateescape".
     filename = "\udc80.txt"
     try:
         with _FileIO(filename):
             pass
     except (UnicodeEncodeError, IOError):
         pass
     # Spawn a separate Python process with a different "file system
     # default encoding", to exercise this further.
     env = dict(os.environ)
     env[b"LC_CTYPE"] = b"C"
     _, out = run_python("-c", "import _io; _io.FileIO(%r)" % filename, env=env)
     if "UnicodeEncodeError" not in out and not (
         ("IOError: [Errno 2] No such file or directory" in out) or ("IOError: [Errno 22] Invalid argument" in out)
     ):
         self.fail("Bad output: %r" % out)
Esempio n. 11
0
 def _check_script(self, script_name, expected_file, expected_argv0,
                   expected_package, *cmd_line_switches):
     run_args = cmd_line_switches + (script_name, )
     exit_code, data = run_python(*run_args)
     if verbose:
         print('Output from test script %r:' % script_name)
         print(data)
     self.assertEqual(exit_code, 0)
     printed_file = '__file__==%r' % str(expected_file)
     printed_argv0 = 'sys.argv[0]==%r' % str(expected_argv0)
     printed_package = '__package__==%r' % (str(expected_package)
                                            if expected_package is not None
                                            else expected_package)
     if verbose:
         print('Expected output:')
         print(printed_file)
         print(printed_package)
         print(printed_argv0)
     self.assertIn(printed_file, data)
     self.assertIn(printed_package, data)
     self.assertIn(printed_argv0, data)