Skip to content
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

Add IXMP_DATA / execute all tests in temporary directories #130

Merged
merged 7 commits into from
Apr 1, 2019

Conversation

khaeru
Copy link
Member

@khaeru khaeru commented Mar 13, 2019

This code causes all tests to be executed in temporary directories, without touching the user's local database or configuration file. This is accomplished by checking a new environment variable IXMP_DATA, which points to a directory that is used for both config.json and the DEFAULT_LOCAL_DB_PATH. Along the way, handling of configuration keys is formalized a little.

To check that the code works as advertised, one can make one's own (user) ixmp data directory read-only, e.g. $ chmod -w ~/.local/share/ixmp. Then run the tests. The tests pass; this shows that ixmp-config calls in tests, and any local databases created/used, are not written in this directory.

Closes #124.

  • New class ixmp.config.Config to regularize config handling.
  • Remove ixmp.default_paths, ixmp.default_path_constants submodules.
  • Scenario__init__(): use Config.find_dbprops() and Config.get().
  • cli.config(): use Config.save().
  • Update tests:
    • conftest.py: new fixture 'tmp_env' and hook 'pytest_sessionstart'.
    • test_config.py: test Config features.
    • test_core.py: use pytest 'caplog' fixture to test that configuration values are used.
    • test_tutorials.py: use 'tmp_env' to force tutorial execution in a sandbox.

PR checklist:

  • Tests added
  • Documentation added
  • Description in RELEASE_NOTES.md added

- New class ixmp.config.Config to regularize config handling.
- Remove ixmp.default_paths, ixmp.default_path_constants.
- cli.config(): use Config.save().
- Scenario__init__(): use Config.find_dbprops() and Config.get().
- conftest.py: new fixture 'tmp_env' and hook 'pytest_sessionstart'.
- test_config.py: test Config features.
- test_core.py: use pytest 'caplog' fixture to test that configuration
  values are used.
- test_tutorials.py: use 'tmp_env' to force tutorial execution in a
  sandbox.
@khaeru khaeru added the enh New features & functionality label Mar 13, 2019
@khaeru khaeru added this to the 0.2 milestone Mar 13, 2019
@khaeru khaeru self-assigned this Mar 13, 2019
tests/conftest.py Outdated Show resolved Hide resolved
Copy link
Member

@danielhuppmann danielhuppmann left a comment

Choose a reason for hiding this comment

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

thanks @khaeru, this looks great!

@gidden, as you developed the testing infrastructure, can you take a look?

@khaeru khaeru requested a review from gidden March 14, 2019 12:45
ixmp/config.py Outdated Show resolved Hide resolved
ixmp/config.py Outdated Show resolved Hide resolved
Copy link
Member

@gidden gidden left a comment

Choose a reason for hiding this comment

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

Looks great @khaeru Thanks so much!! One passing comment then I think its good to go!

@gidden
Copy link
Member

gidden commented Apr 1, 2019

Hey @khaeru let me know if there's anything else to do here. Otherwise as soon as it passes, we can pull and continue with other PRs!

@khaeru
Copy link
Member Author

khaeru commented Apr 1, 2019

Done, please go ahead and merge.

@gidden
Copy link
Member

gidden commented Apr 1, 2019

thanks @khaeru, great addition!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enh New features & functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configuration & data are not in expected (XDG) locations
4 participants