compas-dev / compas

Core packages of the COMPAS framework.
https://compas.dev/compas/
MIT License
307 stars 107 forks source link

Unittests for compas_rhino.conversions #1054

Open chenkasirer opened 2 years ago

chenkasirer commented 2 years ago

Continuing the discussion started in https://github.com/compas-dev/compas/pull/1052.

As suggested by @brgcode, it can be beneficial to have the functions in compas_rhino.conversions tested as part of the build. These are not currently being tested due to their context specific nature, e.g. they contain imports of types from Rhino.Geometry which is only available when the code is run in the integrated Ironpython environment of Rhino.

One potential approach is using rhino3dm which offers a C++ python binding, mirroring at least parts of the RhinoCommon library. It also provides API for reading .3dm files.

Alternatively, rhino.inside provides access to the Rhino runtime from CPython. This allows importingRhino.Geometry directly, given that a running instance of Rhino is available. No hacking sys.modules is required here and all of the Rhino namespace should be available. Downside is, of course, that since it requires a running Rhino instance, such tests will only be able to run locally.

gonzalocasas commented 2 years ago

If the tests are to be run locally, could we flip the equation and run them from Rhino directly? I did a quick test, and our ironpython-pytest thing works correctly inside Rhino:

from __future__ import print_function

import os
import sys
path_to_pytest = r'C:\Users\gcasas\eth\Projects\gramaziokohler\ironpython-pytest\src'
if path_to_pytest not in sys.path:
    sys.path.append(path_to_pytest)

import pytest

HERE = os.path.dirname(__file__)

if __name__ == '__main__':
    pytest.run(HERE)

Interestingly enough, some tests fail, I haven't looked into the reasons: image