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

Hi Jason,
http://hg.python.org/cpython/rev/f7dd5178f36a branch: 2.7 user: Jason R. Coombs jaraco@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

Éric, These are all good suggestions. I'll make them at some point.
Thanks.
-----Original Message----- From: python-dev-bounces+jaraco=jaraco.com@python.org [mailto:python- dev-bounces+jaraco=jaraco.com@python.org] On Behalf Of Éric Araujo Sent: Friday, 18 November, 2011 10:10 To: python-dev@python.org Subject: Re: [Python-Dev] [Python-checkins] cpython (2.7): PDB now will properly escape backslashes in the names of modules it executes.
Hi Jason,
http://hg.python.org/cpython/rev/f7dd5178f36a branch: 2.7 user: Jason R. Coombs jaraco@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 _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python- dev/jaraco%40jaraco.com

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 :)
I completely disagree. test_12345 is a very good name for a test case, in particular if it tests the value of a tau constant in the math module. There can't be any more precise documentation of the test purpose.
Regards, Martin
participants (3)
-
"Martin v. Löwis"
-
Jason R. Coombs
-
Éric Araujo