@@ -1,6 +1,9 @@
|
||||
import modulus.build_context
|
||||
import modulus.process
|
||||
import pathlib
|
||||
import runpy
|
||||
import types
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -26,6 +29,32 @@ class PythonTests(unittest.TestCase):
|
||||
self.assertEqual(environment['MODULUS_PYTHON_OFFLINE'], '1')
|
||||
environment = modulus.process.subprocess_environment(context, ['conan', 'install', '.'])
|
||||
self.assertEqual(environment['MODULUS_PYTHON_OFFLINE'], '0')
|
||||
def test_conan_helper_uses_build_context_module_and_preserves_contract(self):
|
||||
helper = runpy.run_path(str(pathlib.Path(__file__).resolve().parents[1] / 'conanfile.py'))['python_cmake_variables']
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
root = pathlib.Path(temporary)
|
||||
(root / 'modulus.json').write_text('{"package":{"name":"example"},"tooling":{"python":{"groups":["assets"]}}}')
|
||||
package = root / 'package'
|
||||
(package / 'modulus').mkdir(parents=True)
|
||||
(package / 'modulus/cli.py').touch()
|
||||
recipe = types.SimpleNamespace(source_folder=str(root), build_folder=str(root / 'build'),
|
||||
dependencies={'modulus': types.SimpleNamespace(package_folder=str(package))})
|
||||
executable = root / 'python/bin/python3'
|
||||
for offline in ('0', '1'):
|
||||
with unittest.mock.patch.dict(os.environ, {'MODULUS_PYTHON_COMMON_DIR': str(root / 'common'), 'MODULUS_PYTHON_OFFLINE': offline}), unittest.mock.patch.object(modulus.python, 'interpreter', return_value=executable) as interpreter:
|
||||
variables = helper(recipe)
|
||||
context = interpreter.call_args_list[0].args[0]
|
||||
self.assertIsInstance(context, modulus.build_context.build_context)
|
||||
self.assertEqual(context.common_dir, root / 'common')
|
||||
self.assertEqual(context.tools_dir, package / 'tools')
|
||||
self.assertEqual(interpreter.call_args_list[0].kwargs, {'install': True, 'offline': offline == '1'})
|
||||
self.assertEqual(variables['Python3_EXECUTABLE'], str(executable))
|
||||
self.assertEqual(variables['MODULUS_PYTHON_RUNNER'], str(package / 'tools/python_runner.py'))
|
||||
self.assertEqual(variables['MODULUS_PYTHON_ROOT'], str(package))
|
||||
self.assertTrue(variables['MODULUS_PYTHON_REQUIREMENTS'].endswith('assets_requirements.txt'))
|
||||
with unittest.mock.patch.dict(os.environ, {}, clear=True), unittest.mock.patch.object(modulus.python, 'interpreter', return_value=executable) as interpreter:
|
||||
helper(recipe)
|
||||
self.assertEqual(interpreter.call_args_list[0].args[0].common_dir, root / 'build/build_python')
|
||||
def test_missing_dependencies_require_configure_and_never_download_during_build(self):
|
||||
with tempfile.TemporaryDirectory() as temporary, unittest.mock.patch.object(subprocess, 'run') as run:
|
||||
context = self.context(pathlib.Path(temporary), ['assets'])
|
||||
|
||||
Reference in New Issue
Block a user