Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,14 @@ def __init__(self, completekey='tab', stdin=None, stdout=None, skip=None,
self.rcLines.extend(rcFile)
except OSError:
pass
try:
with open(".pdbrc", encoding='utf-8') as rcFile:
self.rcLines.extend(rcFile)
except OSError:
pass
if os.path.join(
os.path.abspath(os.curdir), ".pdbrc"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the equivalent check should be os.path.abspath(".pdbrc") right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaogaotiantian yeah i don't know what i was thinking there, updated

btw would it be ok to send a separate pr updating the pdb module & its tests to start using pathlib or preferring to keep os.path ?

) != os.path.expanduser("~/.pdbrc"):
try:
with open(".pdbrc", encoding='utf-8') as rcFile:
self.rcLines.extend(rcFile)
except OSError:
pass

self.commands = {} # associates a command list to breakpoint numbers
self.commands_defining = False # True while in the process of defining
Expand Down
19 changes: 19 additions & 0 deletions Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -3935,6 +3935,25 @@ def test_readrc_homedir(self):
f.write("invalid")
self.assertEqual(pdb.Pdb().rcLines[0], "invalid")

def test_readrc_current_dir(self):
with os_helper.temp_cwd() as cwd:
rc_path = os.path.join(cwd, ".pdbrc")
with open(rc_path, "w") as f:
f.write("invalid")
self.assertEqual(pdb.Pdb().rcLines[0], "invalid")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should combine this line and the line below. Just check pdb.Pdb().rcLines directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it self.assertEqual(pdb.Pdb().rcLines[-1], "invalid"), this test is not patching a .pdbrc at $HOME so potentially there can be other lines first in rcLines, so now it only checks that the last one comes from the file written during the test

incidentally, i just found there are 5 other tests that fail if you do happen to have a non-empty .pdbrc at $home, it's ok in CI because there is none, but locally a few unrelated things fail when the file is present

self.assertEqual(len(pdb.Pdb().rcLines), 1)

def test_readrc_home_twice(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename the function name to be something more descriptive. test_readrc_cwd_is_home maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

with os_helper.EnvironmentVarGuard() as env:
env.unset("HOME")
with os_helper.temp_cwd() as cwd, patch("os.path.expanduser"):
rc_path = os.path.join(cwd, ".pdbrc")
os.path.expanduser.return_value = rc_path
with open(rc_path, "w") as f:
f.write("invalid")
self.assertEqual(pdb.Pdb().rcLines, ["invalid"])
self.assertEqual(len(pdb.Pdb().rcLines), 1)

def test_header(self):
stdout = StringIO()
header = 'Nobody expects... blah, blah, blah'
Expand Down
Loading