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

Improve testing for v3.3; misc cleanup #416

Merged
merged 47 commits into from
May 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
6c8ba1a
Add Backend.handle_config() method
khaeru May 25, 2021
55d0c21
Implement JDBCBackend.handle_config(); use in Config.add_platform()
khaeru May 25, 2021
f4d0717
Reflow comments and docstrings in ._config
khaeru May 25, 2021
34cce77
Apply Path.resolve() in _config._iter_config_paths()
khaeru May 25, 2021
4af5540
Simplify ._config._locate()
khaeru May 25, 2021
cb860c4
Use consistent parameter/variable name 'type_' in ._config
khaeru May 25, 2021
9e63456
Add Config.unregister(); _strict parameter to Config.set()
khaeru May 25, 2021
7a8f2b2
Split distinct try: blocks in Config.read(); tolerate unregistered
khaeru May 25, 2021
88851c4
Split "config" CLI command to a group; add "config show"
khaeru May 25, 2021
da43a6e
Add .tests.test_compat.test_message_model_dir()
khaeru May 25, 2021
4c66d30
Add genno, message_ix_models to show_versions()
khaeru May 25, 2021
6d6adf0
Simplify test_format_scenario_list()
khaeru May 25, 2021
b53835a
Add and use test fixture protect_rename_dims
khaeru May 25, 2021
f2255bd
Set jdbc._GC_AGGRESSIVE = False when running tests
khaeru May 25, 2021
5a40841
Gitignore pytest-profiling output
khaeru May 25, 2021
8ca020c
Add column headers from export_timeseries_data() to backend.FIELDS
khaeru May 25, 2021
fbe1ac6
Convert Java to Python exceptions in {gs}et_meta()
khaeru May 25, 2021
57f0d9f
Convert Java to Python exceptions in get_scenarios() and commit()
khaeru May 25, 2021
d000e90
Tidy & reflow docstrings & comments
khaeru May 25, 2021
5ce874e
Type Scenario.__init__()
khaeru May 25, 2021
2aca599
Organize shared data in the test suite
khaeru May 25, 2021
3bc8af6
Skip calling Model.initialize() when cloning
khaeru May 25, 2021
8f79d1a
Change test_mp fixture from class- to module-scope
khaeru May 25, 2021
9d8c4bc
Ensure the database is open in test_reporter.test_cli()
khaeru May 25, 2021
0ee0b6c
Re-use common test data in test_platform
khaeru May 25, 2021
2ff92fc
Avoid collision in test_jdbc.test_exceptions()
khaeru May 25, 2021
ec6040c
Rescue test_timeseries.py
khaeru May 25, 2021
69584f5
Test JDBCBackend.handle_config
khaeru May 26, 2021
bc7f03e
Split .testing to 3 submodules; collect all fixtures and data
khaeru May 26, 2021
14bee37
Adjust imports from ixmp.testing
khaeru May 26, 2021
c9b514c
Add test_testing for .testing.resource
khaeru May 26, 2021
6514a4e
Mark some lines uncovered by tests
khaeru May 26, 2021
3e8fd16
Convert args tuple to list for pop() in JDBCBackend.handle_config()
khaeru May 26, 2021
f2af739
Add #416 to release notes
khaeru May 26, 2021
2f648e9
Split "platform" CLI command to a group; expand help
khaeru May 26, 2021
86e60f8
Update CLI tests
khaeru May 26, 2021
b58bb37
Make test_resource_limit more permissive
khaeru May 26, 2021
e2e6dc3
Protect test_platform_units against --verbose pytest option
khaeru May 26, 2021
d990fc8
Remove (empty) .tests.conftest
khaeru May 26, 2021
6ee1204
Remove rixmp from the documentation and tutorials
khaeru May 26, 2021
52b7559
Remove R CMD check from "pytest" CI workflow (closes #403)
khaeru May 26, 2021
0b9d857
Adjust test_jdbc.test_handle_config() for Windows
khaeru May 26, 2021
9119a57
Test "config show" CLI command
khaeru May 26, 2021
af5dc69
Test base.Backend.handle_config()
khaeru May 26, 2021
67a130c
Test .testing.data.random_ts_data()
khaeru May 26, 2021
f050e9b
Correct R tutorial JSON
khaeru May 26, 2021
1bfdbdd
Address Sphinx warnings
khaeru May 26, 2021
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
32 changes: 8 additions & 24 deletions .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,41 +99,25 @@ jobs:
- name: Install Python package and dependencies
run: pip install .[tests]

- name: Install R package and dependencies
- name: Install R dependencies and tutorial requirements
run: |
install.packages("remotes")
remotes::install_cran(c("rcmdcheck", "IRkernel"))
remotes::install_deps("rixmp", upgrade = "never", dependencies = TRUE)
remotes::install_cran(
c("IRkernel", "reticulate"),
dependencies = TRUE,
# force = TRUE,
)

IRkernel::installspec()

# commented: for debugging
# print(reticulate::py_config())
# reticulate::py_run_string("import os; print(os.environ)")

# For R tutorial notebooks, run via the pytest suite: set up R kernel;
# actually install the R package
IRkernel::installspec()
remotes::install_local(
"rixmp",
force = TRUE,
INSTALL_opts = c("--no-multiarch"),
)
shell: Rscript {0}

- name: Run test suite using pytest
run: pytest ixmp -m "not performance" --verbose -rA --cov-report=xml --color=yes

- name: Run R CMD check
# Temporarily disabled: see https://github.com/iiasa/ixmp/issues/403
if: false
run: |
rcmdcheck::rcmdcheck(
"rixmp",
args = c("--no-manual", "--as-cran", "--no-multiarch"),
error_on = "warning",
check_dir = "check"
)
shell: Rscript {0}

- name: Test documentation build using Sphinx
if: matrix.python-version != '3.6'
run: make --directory=doc html
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ rixmp/source/inst/docum/*.html
*.pid
coverage.xml
htmlcov
prof/

# JetBrains IDEs
*.iml
Expand Down
9 changes: 9 additions & 0 deletions RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
.. _v3.3.0:

Next release
============

All changes
-----------

- :pull:`416`:

- Add ``ixmp config show`` CLI command.
- Add :mod:`genno` and :mod:`message_ix_models` to the output of :func:`show_versions` / ``ixmp show-versions``.
- Clean up test suite, improve performance, increase coverage ().

- Deprecate :func:`.utils.logger` (:pull:`399`).
- Add a `quiet` option to :meth:`.GAMSModel.solve` and use in testing (:pull:`399`).
- :pull:`398`:

- Fix :class:`.GAMSModel` would try to write GDX data to filenames containing invalid characters on Windows.
- Format user-friendly exceptions when GAMSModel errors (:issue:`383`).

- :pull:`397`: Adjust :mod:`ixmp.reporting` to use :mod:`genno`.
- :pull:`396`: Fix two minor bugs in reporting.

Expand Down
1 change: 1 addition & 0 deletions doc/api-backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Backend API
get_scenarios
get_scenario_names
get_units
handle_config
open_db
read_file
remove_meta
Expand Down
43 changes: 17 additions & 26 deletions doc/api-r.rst
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
.. _rixmp:

R (``rixmp`` package)
*********************
Usage in R via ``reticulate``
*****************************

An R interface to the `ixmp` is provided by the ``rixmp`` package.
``rixmp`` uses the `reticulate <https://rstudio.github.io/reticulate/>`_ R-to-Python adapter to provide access to all features of the :mod:`ixmp` *Python* package
:mod:`ixmp` is fully usable in R via `reticulate`_, a package that allows nearly seamless access to the Python API.
No additional R packages are needed.

.. code-block:: R

# Load the rixmp package
library(rixmp)
ixmp <- import('ixmp')

# An 'ixmp' object is added to the global namespace.
# It can be used in the same way as the Python ixmp package.
mp <- ixmp$Platform(dbtype = 'HSQLDB')
scen <- ixmp$Scenario(mp, 'model name', 'scenario name', version = 'new')
.. note:: The former ``rixmp`` package was removed in :mod:`ixmp` :ref:`v3.3.0`.

# etc.
See :ref:`message_ix:install-r` for installing R and `reticulate`_ to use with :mod:`ixmp`.
Those instructions are suitable whether :mod:`message_ix` is also installed, or only :mod:`ixmp`.

One additional method, :meth:`adapt_to_ret` is provided.
Access its documentation with
Once installed, use reticulate to import the Python package:

.. code-block:: R

?rixmp::adapt_to_ret
library(reticulate)
ixmp <- import("ixmp")

This function is useful when adding :class:`data.frames` objects to a Scenario:
This creates a global variable, ``ixmp``, that can be used much like the Python module:

.. code-block:: R

scen$init_set("i")
i.set = c("seattle", "san-diego")
scen$add_set("i", i.set)
# load dataframes
scen$init_par("a", c("i"))
a.df = data.frame(i = i.set, value = c(350, 600) , unit = 'cases')
scen$add_par("a", adapt_to_ret(a.df))
mp <- ixmp$Platform(name = 'default')
scen <- ixmp$Scenario(mp, 'model name', 'scenario name', version = 'new')

Finally, see the R versions of the :doc:`tutorials`.

.. _reticulate: https://rstudio.github.io/reticulate/
2 changes: 1 addition & 1 deletion doc/file-io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ Multiple dimensions indexed by the same set
File formats other than :file:`.xlsx`
The :file:`.xlsx` (Office Open XML) file format is preferred for input and output.
:mod:`ixmp` uses `openpyxl <https://openpyxl.readthedocs.io>`_ and :mod:`pandas` in order to read and write this format.
For other Excel file formats, including :file:`.xls` and :file:`.xlsb`, see the :pandas:ref:`Pandas documentation <io.excel>`.
For other Excel file formats, including :file:`.xls` and :file:`.xlsb`, see the :ref:`Pandas documentation <pandas:io.excel>`.
55 changes: 3 additions & 52 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ The sections below cover other use cases.
Ensure you have first read the :doc:`prerequisites <prereqs>` for understanding and using |MESSAGEix|.
These include specific points of knowledge that are necessary to understand these instructions and choose among different installation options.

To use :mod:`ixmp` from R, see :ref:`message_ix:install-r` in the |MESSAGEix| documentation.

Use cases for installing ixmp directly include:

- Installing *ixmp* to be used alone (i.e., with models or frameworks other than |MESSAGEix|).
Expand All @@ -21,13 +23,6 @@ Use cases for installing ixmp directly include:
- `Install system dependencies`_, then
- `From source`_.

- Installing the :doc:`rixmp <api-r>` R package, to use the :mod:`ixmp`, alone, from R.
Again, to use |MESSAGEix| from R, it is sufficient to install ``rmessageix``; and not necessary to also/separately install ``rximp``.

- Start with `Install system dependencies`_.
- Then install :mod:`ixmp` from source.
- Finally, see `Install rixmp`_.

**Contents:**

.. contents::
Expand Down Expand Up @@ -123,7 +118,7 @@ From source

4. (Optional) If you intend to contribute changes to *ixmp*, first register a Github account, and fork the `ixmp repository <https://github.com/iiasa/ixmp>`_.
This will create a new repository ``<user>/ixmp``.
(Please also see :message_ix:doc:`contributing`.)
(Please also see :doc:`message_ix:contributing`.)

5. Clone either the main repository, or your fork; using the `Github Desktop`_ client, or the command line::

Expand All @@ -144,42 +139,6 @@ From source
$ pytest


Install ``rixmp``
=================

``rixmp`` is the R interface to :mod:`ixmp`; see :doc:`its documentaiton <api-r>`.
You only need to install ``rixmp`` if you intend to use :mod:`ixmp` from R, rather than from Python.

Install :mod:`ixmp` **from source**, per the section above.
Then:

8. `Install R <https://www.r-project.org>`_.
Ensure that your ``PATH`` environment variable is configured correctly so that the ``Rscript`` executable is available.

.. warning::
Ensure the the R version installed is either 32- *or* 64-bit (and >= 3.5.0), consistently with GAMS and Java.
Having both 32- and 64-bit versions of R, or mixed 32- and 64-bit versions of different packages, can cause errors.

9. Open a command prompt in the :file:`ixmp/` directory.
Type the following commands to build, then install, ``rixmp`` and its dependencies, including reticulate_::

$ R CMD build rixmp

10. Check that there is only one :file:`*.tar.gz` or :file:`.zip` file in the folder, then run::

# On Windows
$ R CMD INSTALL rixmp_*.zip

# Other operating systems
$ R CMD INSTALL rixmp_*.tar.gz

11. (Optional) Install `IRKernel`_, which allows running R code in Jupyter notebooks (see the link for instructions).

12. (Optional) Check that the R interface works by using the built-in test suite to run the R tutorial notebooks::

$ pytest -m rixmp


Troubleshooting
===============

Expand Down Expand Up @@ -216,12 +175,6 @@ Java Development Kit (JDK)

.. warning:: Do not overwrite the existing ``PATH`` environment variable, but add to the list of existing paths.

Rtools
https://cran.r-project.org/bin/windows/Rtools/

For installing or modifying some R packages on Windows.


.. _`installing MESSAGEix`: https://docs.messageix.org/en/latest/getting_started.html
.. _`Anaconda`: https://www.continuum.io/downloads
.. _`GAMS`: http://www.gams.com
Expand All @@ -234,6 +187,4 @@ Rtools
.. _conda glossary: https://docs.conda.io/projects/conda/en/latest/glossary.html
.. _Anaconda Navigator documentation: https://docs.anaconda.com/anaconda/navigator/
.. _`Github Desktop`: https://desktop.github.com
.. _reticulate: https://rstudio.github.io/reticulate/
.. _IRkernel: https://irkernel.github.io/installation/
.. _JDK website instructions: https://docs.oracle.com/cd/E19182-01/820-7851/inst_cli_jdk_javahome_t/
2 changes: 1 addition & 1 deletion ixmp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

try:
__version__ = get_distribution(__name__).version
except DistributionNotFound:
except DistributionNotFound: # pragma: no cover
# Package is not installed
__version__ = "999"

Expand Down
Loading