Skip to content

bpo-34248: add filename to DbmError at gdbm_open()#8590

Merged
berkerpeksag merged 1 commit intopython:masterfrom
csernazs:fix-issue-34248
Sep 27, 2018
Merged

bpo-34248: add filename to DbmError at gdbm_open()#8590
berkerpeksag merged 1 commit intopython:masterfrom
csernazs:fix-issue-34248

Conversation

@csernazs
Copy link
Copy Markdown
Contributor

@csernazs csernazs commented Jul 31, 2018

Add the filename to the DbmError raised when dbm.gnu.open() is called and
errno is set.

https://bugs.python.org/issue34248

Comment thread Lib/test/test_dbm_gnu.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should use filename instead of TESTFN for consistency with the other tests in this file.

This self.assertFalse() should probably be replaced by a simple unlink(filename) (like in test_error_conditions()).

Comment thread Lib/test/test_dbm_gnu.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You should probably use assertRaisesRegex() to check the exception message (instead of the separate assertEqual() call).

Comment thread Lib/test/test_dbm_gnu.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this test is needed. It's also missing a unittest.skipUnless() decorator for TESTFN_NONASCII.

Comment thread Lib/test/test_dbm_gnu.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you meant to use TESTFN_NONASCII here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:func:`dbm.gnu.open`

@csernazs csernazs force-pushed the fix-issue-34248 branch 2 times, most recently from 6624138 to 4a74533 Compare August 4, 2018 14:15
Comment thread Lib/test/test_dbm_gnu.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

assertRaisesRegexp() is deprecated. Please use assertRaisesRegex().

Comment thread Lib/test/test_dbm_gnu.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need this? Can't we just call gdbm.open() with an non-existing file name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Which filename should be there which is guaranteed to be non-existing? I think we should use a file which is under our control and thereby I re-used the filename variable.
The unlink is a very last resort to ensure that the file won't exist, this would normall not remove any file as it is already removed in tearDown.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Using something like gdbm.open('nonexisting-file') is enough.

Comment thread Lib/test/test_dbm_gnu.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It is better to use raw string literals for regexes.

Since filename can contain regex metacharacters, it should be wrapped with re.escape() if used in a regex pattern.

Errno 2 is platform depending.

Is the filename attribute of the exception set?

with self.assertRaises(gdbm.error) as cm:
    gdbm.open(filename)
self.assertIn(filename, str(cm.exception))
self.assertEqual(cm.exception.filename, filename)  # is this true?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Missed : before func.

Comment thread Lib/test/test_dbm_gnu.py Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Typo: nonexising

@csernazs csernazs force-pushed the fix-issue-34248 branch 2 times, most recently from 3ff85c6 to 4a7cad7 Compare August 6, 2018 19:11
@csernazs
Copy link
Copy Markdown
Contributor Author

csernazs commented Aug 6, 2018

I've added ndbm also to this commit due to the request in the bpo ticket. If you want to have this in two commits, let me know. Thanks!

…dbm.open

Report the filename to the exception when raising error in dbm.gnu.open and
db.ndbm.open functions, so it gets printed when the exception is unhandled,
and also can be obtained by the filename attribute of the exception object.
@csernazs
Copy link
Copy Markdown
Contributor Author

csernazs commented Sep 4, 2018

@berkerpeksag could you please help how to have this pull request merged to master? Is there any action required from my side? I think I have made everything which was requested.

@berkerpeksag
Copy link
Copy Markdown
Member

I had to close and reopen thid because the AppVeyor build wasn't completed.

@berkerpeksag berkerpeksag merged commit 9df346b into python:master Sep 27, 2018
@berkerpeksag
Copy link
Copy Markdown
Member

Thanks!

@csernazs
Copy link
Copy Markdown
Contributor Author

Thank you!

@csernazs
Copy link
Copy Markdown
Contributor Author

@berkerpeksag should we backport of this patch to 3.7? It seems for me that this patch was not included in 3.7.1. Should I need to open a new PR for the backport?

@berkerpeksag
Copy link
Copy Markdown
Member

New features can only go into the next feature release, which will be 3.8. 3.7 is now in maintenance mode, so we can't backport it into 3.7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants