Skip to content

[3.9] bpo-45500: Rewrite test_dbm (GH-29002) #29074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 20, 2021

Conversation

ambv
Copy link
Contributor

@ambv ambv commented Oct 19, 2021

  • Generate test classes at import time. It allows to filter them when
    run with unittest. E.g: "./python -m unittest test.test_dbm.TestCase_gnu -v".
  • Create a database class in a new directory which will be removed after
    test. It guarantees that all created files and directories be removed
    and will not conflict with other dbm tests.
  • Restore dbm._defaultmod after tests. Previously it was set to the last
    dbm module (dbm.dumb) which affected other tests.
  • Enable the whichdb test for dbm.dumb.
  • Move test_keys to the correct test class. It does not test whichdb().
  • Remove some outdated code and comments..
    (cherry picked from commit 975b94b)

Co-authored-by: Serhiy Storchaka storchaka@gmail.com

NOTE: this is a little different from GH-29002 because 3.9 doesn't have support for bytes filenames and os.PathLike paths (only added in GH-21849). It also doesn't have test.support.os_helper and test.support.import_helper so the imports are different for that.

https://bugs.python.org/issue45500

* Generate test classes at import time. It allows to filter them when
  run with unittest. E.g: "./python -m unittest test.test_dbm.TestCase_gnu -v".
* Create a database class in a new directory which will be removed after
  test. It guarantees that all created files and directories be removed
  and will not conflict with other dbm tests.
* Restore dbm._defaultmod after tests. Previously it was set to the last
  dbm module (dbm.dumb) which affected other tests.
* Enable the whichdb test for dbm.dumb.
* Move test_keys to the correct test class. It does not test whichdb().
* Remove some outdated code and comments..
(cherry picked from commit 975b94b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@corona10
Copy link
Member

I reopen this PR due to bot staling.

setup_test_dir()
dbm._defaultmod = module
# Try with empty files first
with module.open(_fname, 'c'): pass
Copy link
Member

Choose a reason for hiding this comment

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

diff

fnames = [_fname, os_helper.FakePath(_fname),
_bytes_fname, os_helper.FakePath(_bytes_fname)]
for module in dbm_iterator():

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the difference is noted in the PR description.

try:
from dbm import ndbm
except ImportError:
ndbm = None

_fname = test.support.TESTFN
dirname = test.support.TESTFN
Copy link
Member

Choose a reason for hiding this comment

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

diff

from test.support import import_helper
from test.support import os_helper
try:
from dbm import ndbm
except ImportError:
ndbm = None
dirname = os_helper.TESTFN
_fname = os.path.join(dirname, os_helper.TESTFN)

@corona10 corona10 merged commit d46b221 into python:3.9 Oct 20, 2021
@ambv
Copy link
Contributor Author

ambv commented Oct 20, 2021

Thanks for taking care of this, @corona10!

@ambv ambv deleted the backport-975b94b-3.9 branch October 20, 2021 11:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants