[Python-Dev] [Python-checkins] cpython (2.7): PDB now will properly escape backslashes in the names of modules it executes.

Éric Araujo merwok at netwok.org
Fri Nov 18 16:10:17 CET 2011


Hi Jason,

> http://hg.python.org/cpython/rev/f7dd5178f36a
> branch:      2.7
> user:        Jason R. Coombs <jaraco at jaraco.com>
> date:        Thu Nov 17 18:03:24 2011 -0500
> summary:
>   PDB now will properly escape backslashes in the names of modules it executes. Fixes #7750

> diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
> +class Tester7750(unittest.TestCase):
I think we have an unwritten rule that test class and method names
should tell something about what they test.  (We do have things like
TestWeirdBugs and test_12345, but I don’t think it’s a useful pattern to
follow :)  Not a big deal anyway.

> +    # if the filename has something that resolves to a python
> +    #  escape character (such as \t), it will fail
> +    test_fn = '.\\test7750.py'
> +
> +    msg = "issue7750 only applies when os.sep is a backslash"
> +    @unittest.skipUnless(os.path.sep == '\\', msg)
> +    def test_issue7750(self):
> +        with open(self.test_fn, 'w') as f:
> +            f.write('print("hello world")')
> +        cmd = [sys.executable, '-m', 'pdb', self.test_fn,]
> +        proc = subprocess.Popen(cmd,
> +            stdout=subprocess.PIPE,
> +            stdin=subprocess.PIPE,
> +            stderr=subprocess.STDOUT,
> +            )
> +        stdout, stderr = proc.communicate('quit\n')
> +        self.assertNotIn('IOError', stdout, "pdb munged the filename")
Why not check for assertIn(filename, stdout)?  (In other words, check
for intended behavior rather than implementation of the erstwhile bug.)

BTW, I’ve just tested that giving a message argument to assertNotIn (the
third argument), unittest still displays the other arguments to allow
for easier debugging.  I didn’t know that, it’s cool!

> +    def tearDown(self):
> +        if os.path.isfile(self.test_fn):
> +            os.remove(self.test_fn)
In my own tests, I’ve become fond of using “self.addCleanup(os.remove,
filename)”: It’s shorter that a tearDown and is right there on the line
that follows or precedes the file creation.

>  if __name__ == '__main__':
>      test_main()
> +    unittest.main()
This looks strange.

Regards


More information about the Python-Dev mailing list