From 3212850763f535959cd009b767771d8d56da6c55 Mon Sep 17 00:00:00 2001 From: Darth Vader Date: Tue, 30 Jul 2024 16:33:41 +0000 Subject: [PATCH] Squashed 'src/phast/PhreeqcRM/' changes from 95667e83..4d74c437 4d74c437 Merge commit 'caf28aaf1f79121433a330b3a88e11cef0d8b5dc' caf28aaf Squashed 'src/' changes from 0696861f..26aa6771 a2af527e Bumped wheels version 1a6688e4 Merge pull request #168 from scharlton2/cibuildwheel-numpy-2 4e6efe61 Added conftest.py and constants.py to EXTRA_DIST b46dba14 Undid refactoring of enum State 114fabc6 Added merge_wheels job cf4a4532 Enabled all plats and python versions 8d13e68f Enabled all tests c8ddb92f Added missing import 3157b1c6 Added setup code 2e05db21 Turned on stdout 9a3251db test_prereqs 61d8f649 More debug fe1ceb8e Debugging c714e5dc Updated constants.py e0fbf526 Added variable to get yaml file path b7e55e63 Debugging 988f9678 Added debugging d196f982 debug cwd 81fca3dd Added prereqs to test_basic.py fe6d6439 Check just windows a4f0534b Missed a CIBW_TEST_REQUIRES f7580195 Added phreeqc.dat and advect.pqi to swig/python test directory d1aaa6ac Test tests directory 96c3dc27 Removed tests 157c989a Try modifying __init__.py e50fb864 Removed tests 6abdb1ef Unguarded enum STATE test c6e08c1f Quick test cbd99bf6 Changed SWIGPYTHON to swig_python_EXPORTS f47dca10 Turned off testing fdcb7ab7 Try to set -fPIC for yaml-cpp build dcc9dd72 Trying to fix -fPIC on ubuntu 98372dee Missed USE_YAML for PYTHON_TARGET_NAME 10df34a7 Fixed USE_YAML define for cibuildwheel/scikit-build 73567db7 Turned-off testing c280192a Removed windows x64 cp313 exclusion 842767e3 Added cp313 72041396 Refactored enum State 7831fcde WIP: Added cp38 954fea96 WIP: Adding pytest tests 987206cd Add testing to cibuildwheel 7adf40e7 Merged CMakeListst.txt from scharlton/_fetch using: $ git checkout scharlton2/_fetch -- .\CMakeLists.txt cdeda137 Try uncontrained numpy cf66838a Test numpy>=2 in requires d89f2dc1 Updated numpy contraints c30da111 Enabled build wheels 5abc3d7e Bumped version and cleanup dd90fce6 Added sdist 879ed4ec Fixed python exclude 6c858032 Disabled python=3.13 on windows 4bcd4f55 Set numpy<2 5c6fd309 Missed PRERELEASE and added fail-fast=false c67c2102 Added cp313 54bcc581 More buildplats 34f8bf9a Added ubuntu manylinux - disabled windows 3c999997 Added cp38, cp39 for windows 981a4d0c Increased verbosity for build c3eece1f Try forcing the _MSC_VER for wheels d99d88c1 Modified GetComponentName to include _MSC_VER b4c34cf9 Working on customizing cibuildwheel builds 31044136 Added with to actions/setup-python step 17640db9 Commented extra env section 5c4518b0 Try to use env vars to specify toolset and platform 640ee1a8 Increased build verbosity 7477c1ec Only build cp310-manylinux_x86_64 372f08da Added NumPy 404f6688 Modified find Python fcf7845a Test without yaml-cpp d1702e14 WIP Changed name 57a3d446 WIP: try pypa/cibuildwheel git-subtree-dir: src/phast/PhreeqcRM git-subtree-split: 4d74c4374cb37307f607ba39cdac794510b6fe7c --- .github/workflows/wheels.yml | 169 +++++++++++++++----------------- CMakeLists.txt | 38 ++++++- Makefile.am | 2 + pybind/tests/constants.py | 19 ++++ pybind/tests/test_basic.py | 46 ++++----- pybind/tests/test_get_value.py | 16 +-- pybind/tests/test_irf.py | 6 +- pybind/tests/test_set_value.py | 8 +- pyproject.toml | 8 +- src/BMIPhreeqcRM.h | 22 +++++ src/phreeqcrm/__init__.py | 3 +- swig/python/AdvectBMI_py.py | 4 +- swig/python/CMakeLists.txt | 21 +++- swig/python/WriteYAMLFile_py.py | 6 +- swig/python/conftest.py | 15 +++ swig/python/constants.py | 9 ++ swig/python/test_basic.py | 84 +++++++++++----- swig/python/test_get_value.py | 20 ++-- swig/python/test_init.py | 4 +- swig/python/test_irf.py | 6 +- swig/python/test_set_value.py | 10 +- 21 files changed, 342 insertions(+), 174 deletions(-) create mode 100644 pybind/tests/constants.py create mode 100644 swig/python/conftest.py create mode 100644 swig/python/constants.py diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index fae91ceb..f407a658 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -1,114 +1,101 @@ name: wheels -on: - pull_request: - branches: - - master - push: - branches: - - master - workflow_dispatch: - release: - types: - - published - -env: - FORCE_COLOR: 3 - YAML_CPP_REF: b8882652fcbeba4c00dec019a39da91e702e474e - USE_LIB_CMAKE_YAML_CPP: ${{ true }} +on: [push, pull_request] jobs: - build: - name: ${{ matrix.os }} (python ${{ matrix.python-version }}) - + build_wheels: + name: ${{ matrix.python[0] }}(${{ matrix.buildplat[2] }}) on ${{ matrix.buildplat[0] }} + runs-on: ${{ matrix.buildplat[0] }} strategy: fail-fast: false matrix: - os: [macos-12, macos-13, ubuntu-20.04, ubuntu-22.04, windows-2019, windows-2022] - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] - - runs-on: ${{ matrix.os }} + buildplat: + - [macos-13, macosx_x86_64, x86_64] + - [macos-14, macosx_arm64, arm64] + - [ubuntu-20.04, manylinux_x86_64, x86_64] + - [ubuntu-20.04, manylinux_i686, i686] + - [windows-2019, win_amd64, x64] + - [windows-2019, win32, Win32] + python: + - [cp38, v141] + - [cp39, v141] + - [cp310, v141] + - [cp311, v141] + - [cp312, v142] + - [cp313, v142] + exclude: + - buildplat: [windows-2019, win_amd64, x64] + python: [cp313, v142] + - buildplat: [windows-2019, win32, Win32] + python: [cp313, v142] steps: - uses: actions/checkout@v4 - with: - path: phreeqcrm-source - - uses: actions/checkout@v4 + # Used to host cibuildwheel + - uses: actions/setup-python@v5 with: - repository: jbeder/yaml-cpp - ref: ${{ env.YAML_CPP_REF }} - path: yaml-cpp-source - - - name: Install ninja (Linux) - if: ${{ runner.os == 'Linux' }} - run: sudo apt-get -y install ninja-build + python-version: "3.x" - - name: Install ninja (macOS) - if: ${{ runner.os == 'macOS' }} - run: brew install ninja - - - name: Set up Visual Studio shell (Windows) - if: runner.os == 'Windows' - uses: egor-tensin/vs-shell@v2 - with: - arch: x64 - - - name: Cache yaml-cpp - id: cache-yaml-cpp - uses: actions/cache@v4 + - name: Build wheels + if: ${{ runner.os != 'Windows' }} + uses: pypa/cibuildwheel@7e5a838a63ac8128d71ab2dfd99e4634dd1bca09 # v2.19.2 + env: + CIBW_PRERELEASE_PYTHONS: True + CIBW_BUILD: ${{ matrix.python[0] }}-${{ matrix.buildplat[1] }} + CIBW_BUILD_VERBOSITY: 1 + CIBW_TEST_REQUIRES: pytest + # CIBW_BEFORE_TEST: pwd && ls -Ral && ls -Ral {project}/swig/python + CIBW_TEST_COMMAND: "pytest {project}/swig/python" + + - name: Build wheels (Windows) + if: ${{ runner.os == 'Windows' }} + uses: pypa/cibuildwheel@7e5a838a63ac8128d71ab2dfd99e4634dd1bca09 # v2.19.2 + env: + CIBW_PRERELEASE_PYTHONS: True + CIBW_BUILD: ${{ matrix.python[0] }}-${{ matrix.buildplat[1] }} + CIBW_BUILD_VERBOSITY: 1 + CIBW_TEST_REQUIRES: pytest + # CIBW_BEFORE_TEST: pwd && ls -Ral && ls -Ral {project}/swig/python + CIBW_TEST_COMMAND: "pytest {project}/swig/python" + CMAKE_GENERATOR: Visual Studio 16 2019 + CMAKE_GENERATOR_TOOLSET: ${{ matrix.python[1] }} + CMAKE_GENERATOR_PLATFORM: ${{ matrix.buildplat[2] }} + + - uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4 with: - path: ${{ github.workspace }}/yaml-cpp-install - key: ${{ matrix.os }}-yaml-cpp-${{ env.YAML_CPP_REF }} + name: dist-${{ matrix.python[0] }}-${{ matrix.buildplat[1] }} + path: ./wheelhouse/*.whl - - name: Configure yaml-cpp - if: steps.cache-yaml-cpp.outputs.cache-hit != 'true' - run: cmake -G "Ninja Multi-Config" -B yaml-cpp-build -S yaml-cpp-source -DYAML_CPP_BUILD_TOOLS:BOOL=OFF -DCMAKE_INSTALL_PREFIX:PATH=$(pwd)/yaml-cpp-install -DCMAKE_POSITION_INDEPENDENT_CODE=ON - - name: Build yaml-cpp - if: steps.cache-yaml-cpp.outputs.cache-hit != 'true' - run: cmake --build yaml-cpp-build --config Release - - - name: Test yaml-cpp - if: steps.cache-yaml-cpp.outputs.cache-hit != 'true' - run: ctest --test-dir yaml-cpp-build - - - name: Install yaml-cpp - if: steps.cache-yaml-cpp.outputs.cache-hit != 'true' - run: cmake --install yaml-cpp-build + build_sdist: + name: Build sdist + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + - uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1 with: - python-version: ${{ matrix.python-version }} - - - name: Install Python ${{ matrix.python-version }} dependencies + # Build sdist on lowest supported Python + python-version: "3.8" + - name: Build sdist run: | - python --version - python -m pip install --upgrade pip - pip install pipx + python -m pip install -U pip build + python -m build --sdist - - name: Build package (using share/cmake/yaml-cpp) - if: ${{ !env.USE_LIB_CMAKE_YAML_CPP }} - env: - yaml-cpp_DIR: ${{ github.workspace }}/yaml-cpp-install/share/cmake/yaml-cpp - working-directory: phreeqcrm-source - run: pipx run build - - - name: Build package (using lib/cmake/yaml-cpp) - if: ${{ env.USE_LIB_CMAKE_YAML_CPP }} - env: - yaml-cpp_DIR: ${{ github.workspace }}/yaml-cpp-install/lib/cmake/yaml-cpp - working-directory: phreeqcrm-source - run: pipx run build - - - uses: actions/upload-artifact@v4 + - uses: actions/upload-artifact@0b2256b8c012f0828dc542b3febcab082c67f72b # v4.3.4 with: - name: wheels-${{ matrix.os }}-python-${{ matrix.python-version }} - path: phreeqcrm-source/dist/*.whl + name: dist-sdist + path: ./dist/* - - uses: actions/upload-artifact@v4 - if: ${{ matrix.python-version == '3.10' && matrix.os == 'ubuntu-22.04' }} + + merge_wheels: + name: Merge wheels into a combined artifact + runs-on: ubuntu-latest + needs: [build_wheels, build_sdist] + steps: + - name: Merge Artifacts + uses: actions/upload-artifact/merge@v4 with: - name: source - path: phreeqcrm-source/dist/*.tar.gz + name: dist + pattern: dist-* diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b7285e6..225f60f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,12 @@ project( LANGUAGES CXX C ) +if(DEFINED SKBUILD) + include(CheckPIESupported) + check_pie_supported() + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif() + # check if this is the root project if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) set(STANDALONE_BUILD 1) @@ -33,11 +39,29 @@ if(PHREEQCRM_FORTRAN_TESTING) enable_language(Fortran) endif() +if(DEFINED SKBUILD) + # SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml) + + # Include FetchContent module + include(FetchContent) + + # Fetch yaml-cpp + FetchContent_Declare( + yaml-cpp + GIT_REPOSITORY https://github.com/jbeder/yaml-cpp.git + GIT_TAG yaml-cpp-0.7.0 + ) + + # Make yaml-cpp available + FetchContent_MakeAvailable(yaml-cpp) +endif() + option(PHREEQCRM_WITH_YAML_CPP "Build with yaml-cpp support" OFF) if(DEFINED SKBUILD) + # SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml) set(PHREEQCRM_WITH_YAML_CPP ON) endif() -if(PHREEQCRM_WITH_YAML_CPP) +if(PHREEQCRM_WITH_YAML_CPP AND NOT DEFINED SKBUILD) find_package(yaml-cpp REQUIRED) if(yaml-cpp_FOUND) message(STATUS "Found yaml-cpp: TRUE (found version \"${yaml-cpp_VERSION}\")") @@ -60,6 +84,7 @@ endif() option(PHREEQCRM_BUILD_PYTHON "Build python wrapper using SWIG" OFF) if(DEFINED SKBUILD) + # SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml) set(PHREEQCRM_BUILD_PYTHON ON) endif() if(PHREEQCRM_BUILD_PYTHON) @@ -67,7 +92,8 @@ if(PHREEQCRM_BUILD_PYTHON) message(FATAL_ERROR "Building python wrapper requires PHREEQCRM_WITH_YAML_CPP.") endif() find_package(SWIG REQUIRED) - find_package(Python 3.8 REQUIRED COMPONENTS Interpreter Development Development.Module NumPy) + ###find_package(Python 3.8 REQUIRED COMPONENTS Interpreter Development Development.Module NumPy) + find_package(Python COMPONENTS Interpreter Development.Module NumPy REQUIRED) # Set Python_ROOT_DIR to specify which python to use # ie -DPython_ROOT_DIR=C:/Python38-x64 endif() @@ -318,6 +344,11 @@ if(PHREEQCRM_WITH_YAML_CPP AND yaml-cpp_FOUND) # set(phreeqcrm_requires "yaml-cpp") set(useyaml_define "-DUSE_YAML") endif() +if(DEFINED SKBUILD) + # SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml) + target_compile_definitions(PhreeqcRM PUBLIC USE_YAML) + target_link_libraries(PhreeqcRM PUBLIC yaml-cpp) +endif() # check for zlib if(NOT ZLIB_ROOT) @@ -455,6 +486,7 @@ configure_file(phreeqcrm.cmake.in phreeqcrm.pc @ONLY) # install if(STANDALONE_BUILD EQUAL 1 AND NOT DEFINED SKBUILD) + # SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml) include(CMakePackageConfigHelpers) @@ -546,6 +578,7 @@ if(STANDALONE_BUILD EQUAL 1) # subdirs if(NOT DEFINED SKBUILD) + # SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml) add_subdirectory(database) add_subdirectory(doc) add_subdirectory(Doxygen) @@ -563,6 +596,7 @@ if(MSVC) endif() if(DEFINED SKBUILD) + # SKBUILD is defined when scikit-build-core is used to build python wheels (see pyproject.toml) message(STATUS "SKBUILD IS defined") #set_target_properties(PhreeqcRM TestRM TestBMIdtor TestRMdtor PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) set_target_properties(PhreeqcRM PROPERTIES EXCLUDE_FROM_ALL 1 EXCLUDE_FROM_DEFAULT_BUILD 1) diff --git a/Makefile.am b/Makefile.am index 5011a930..a4825fef 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,6 +11,8 @@ PHREEQCRM_EXTRA_DIST=\ swig/python/AdvectBMI_py.py\ swig/python/BMIPhreeqcRM_docstrings.swg\ swig/python/CMakeLists.txt\ + swig/python/conftest.py\ + swig/python/constants.py\ swig/python/PhreeqcRM_docstrings.swg\ swig/python/SimpleAdvect.py\ swig/python/test_basic.py\ diff --git a/pybind/tests/constants.py b/pybind/tests/constants.py new file mode 100644 index 00000000..3dd3f0f3 --- /dev/null +++ b/pybind/tests/constants.py @@ -0,0 +1,19 @@ +# constants.py +class Constants: + def __init__(self): + file_directory = os.path.dirname(__file__) + self._yaml = os.path.join(file_directory, 'AdvectBMI_py.yaml') + self._database = os.path.join(file_directory, 'phreeqc.dat') + self._pqi = os.path.join(file_directory, 'advect_pqi') + + @property + def yaml(self): + return self._yaml + + @property + def database(self): + return self._database + + @property + def pqi(self): + return self._pqi diff --git a/pybind/tests/test_basic.py b/pybind/tests/test_basic.py index 128a1af0..33990eac 100644 --- a/pybind/tests/test_basic.py +++ b/pybind/tests/test_basic.py @@ -6,6 +6,8 @@ from phreeqcrm import bmi_phreeqcrm, IRM_RESULT +from constants import FilePaths + def test_main(): # for debugging print(f"PYTHONPATH={os.getenv('PYTHONPATH')}") @@ -66,19 +68,19 @@ def test_initialize_AdvectBMI(): model = bmi_phreeqcrm() assert(not model._initialized) - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) assert(model._initialized) def test_get_grid_size_AdvectBMI(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) nxyz = model.get_grid_size(0) assert(nxyz == 40) def test_get_value_ptr_is_ndarray(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) nxyz = model.get_grid_size(0) temperature = model.get_value_ptr("Temperature") @@ -91,7 +93,7 @@ def test_get_value_ptr_is_ndarray(): def test_get_temperature_ptr_is_writeable(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) nxyz = model.get_grid_size(0) # test WRITEABLE @@ -111,7 +113,7 @@ def test_get_temperature_ptr_is_writeable(): def test_get_ComponentCount_ptr_is_readonly(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # make sure get_value_ptr can be called before get_input_var_names component_count = model.get_value_ptr("ComponentCount") @@ -128,7 +130,7 @@ def test_get_ComponentCount_ptr_is_readonly(): def test_get_input_var_names_is_tuple(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) input_vars = model.get_input_var_names() assert(isinstance(input_vars, tuple)) @@ -136,7 +138,7 @@ def test_get_input_var_names_is_tuple(): def test_get_output_var_names_is_tuple(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) output_vars = model.get_output_var_names() assert(isinstance(output_vars, tuple)) @@ -144,7 +146,7 @@ def test_get_output_var_names_is_tuple(): def test_get_components_is_tuple(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) components = model.get_components() assert(isinstance(components, tuple)) @@ -152,7 +154,7 @@ def test_get_components_is_tuple(): def test_get_Components_ptr_is_ndarray(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) components = model.get_value_ptr("Components") assert(isinstance(components, np.ndarray)) @@ -165,7 +167,7 @@ def test_get_Components_ptr_is_ndarray(): def test_get_Components_ptr_is_readonly(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) components = model.get_value_ptr("Components") @@ -177,7 +179,7 @@ def test_get_Components_ptr_is_readonly(): def test_get_Porosity_ptr(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) nxyz = model.get_grid_size(0) porosity = model.get_value_ptr("Porosity") @@ -188,7 +190,7 @@ def test_get_Porosity_ptr(): def test_get_SolutionVolume_ptr(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) nxyz = model.get_grid_size(0) solution_volume = model.get_value_ptr("SolutionVolume") @@ -201,7 +203,7 @@ def test_get_SolutionVolume_ptr(): def test_get_Concentrations_ptr(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) nxyz = model.get_grid_size(0) components = model.get_value_ptr("Components") @@ -289,7 +291,7 @@ def test_get_Concentrations_ptr(): def test_get_value_ndarray_str(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) components = model.get_value_ptr("Components") comps = np.empty_like(components) @@ -306,14 +308,14 @@ def test_get_value_ndarray_str(): def test_SetComponentH2O(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) status = model.SetComponentH2O(True) assert(status == IRM_RESULT.IRM_OK) def test_get_value_FilePrefix(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # FilePrefix doesn't support get_value_ptr expected = "AdvectBMI_py" @@ -326,7 +328,7 @@ def test_get_value_FilePrefix(): def test_get_value_FilePrefix_fail(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # FilePrefix doesn't support get_value_ptr spaces = " " * 4 @@ -337,7 +339,7 @@ def test_get_value_FilePrefix_fail(): def test_get_value_FilePrefix_big_buffer(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # FilePrefix doesn't support get_value_ptr expected = "AdvectBMI_py" @@ -351,7 +353,7 @@ def test_get_value_FilePrefix_big_buffer(): def test_get_value_ComponentCount(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # ComponentCount supports get_value_ptr @todo ##component_count = np.full((1,), 0) @@ -362,7 +364,7 @@ def test_get_value_ComponentCount(): def test_get_value_ptr_ComponentCount(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # ComponentCount supports get_value_ptr @todo ##component_count = np.full((1,), 0) @@ -373,7 +375,7 @@ def test_get_value_ptr_ComponentCount(): def test_get_value_ptr_failure(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # "Components" is currently excluded should_raise = ("CurrentSelectedOutputUserNumber", "DensityUser", "ErrorString", "FilePrefix", "NthSelectedOutput", "SaturationUser", "SelectedOutput", "SelectedOutputColumnCount", "SelectedOutputCount", "SelectedOutputHeadings", "SelectedOutputRowCount") @@ -385,7 +387,7 @@ def test_get_value_ptr_failure(): def test_get_value_Time(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # Time supports get_value_ptr @todo time = np.empty((1,), dtype=float) diff --git a/pybind/tests/test_get_value.py b/pybind/tests/test_get_value.py index 7aabbc7e..f7fda0d6 100644 --- a/pybind/tests/test_get_value.py +++ b/pybind/tests/test_get_value.py @@ -3,6 +3,8 @@ from phreeqcrm import bmi_phreeqcrm +from constants import FilePaths + def test_get_initial_value(): model = bmi_phreeqcrm() model.initialize() @@ -24,7 +26,7 @@ def test_get_value_copy(): def test_get_value_copy_int_scalar(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) dest0 = np.empty((1,), dtype=int) dest1 = np.empty((1,), dtype=int) @@ -39,7 +41,7 @@ def test_get_value_copy_int_scalar(): def test_get_value_copy_float_scalar(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) dest0 = np.empty((1,), dtype=float) dest1 = np.empty((1,), dtype=float) @@ -54,7 +56,7 @@ def test_get_value_copy_float_scalar(): def test_get_value_copy_str(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) components = model.get_value_ptr("Components") dest0 = np.empty_like(components) @@ -68,7 +70,7 @@ def test_get_value_copy_str(): def test_get_value_pointer(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) dest1 = np.empty(model.get_grid_size(0), dtype=float) @@ -86,7 +88,7 @@ def test_get_value_pointer(): def test_get_value_at_indices(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) temps = np.linspace(18.0, 30.0, model.get_grid_size(0)) model.set_value("Temperature", temps) @@ -101,7 +103,7 @@ def test_get_value_at_indices(): def test_value_size(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) z = model.get_value_ptr("Temperature") assert model.get_grid_size(0) == z.size @@ -109,7 +111,7 @@ def test_value_size(): def test_value_nbytes(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) z = model.get_value_ptr("Temperature") assert model.get_var_nbytes("Temperature") == z.nbytes \ No newline at end of file diff --git a/pybind/tests/test_irf.py b/pybind/tests/test_irf.py index b053b9c3..d3a6e24e 100644 --- a/pybind/tests/test_irf.py +++ b/pybind/tests/test_irf.py @@ -7,11 +7,13 @@ from phreeqcrm import bmi_phreeqcrm +from constants import FilePaths + def test_component_name(): model = bmi_phreeqcrm() name = model.get_component_name() - assert name == "BMI PhreeqcRM" + assert name[:13] == "BMI PhreeqcRM" #assert model.get_component_name() is name @todo def test_start_time(): @@ -73,7 +75,7 @@ def test_initialize_from_file(): def test_update(): model = bmi_phreeqcrm() ## model.initialize() # @todo - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) for inc in range(10): model.update() diff --git a/pybind/tests/test_set_value.py b/pybind/tests/test_set_value.py index 5910e122..2cdee488 100644 --- a/pybind/tests/test_set_value.py +++ b/pybind/tests/test_set_value.py @@ -3,9 +3,11 @@ from phreeqcrm import bmi_phreeqcrm +from constants import FilePaths + def test_set_value(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) z0 = model.get_value_ptr("Temperature") z1 = np.zeros_like(z0) - 1 @@ -21,7 +23,7 @@ def test_set_value(): def test_set_value_at_indices(): model = bmi_phreeqcrm() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # model.set_value_at_indices("Temperature", np.array([0, 2, 4]), np.array([-1, -1, -1])) model.set_value_at_indices("Temperature", np.array([0, 2, 4]), np.array([-1.0, -1.0, -1.0])) @@ -32,7 +34,7 @@ def test_set_value_at_indices(): # def test_sequence(): # model = bmi_phreeqcrm() -# model.initialize("AdvectBMI_py.yaml") +# model.initialize(FilePaths.YAML) # # Create a list # my_list = [1, 2, 3] diff --git a/pyproject.toml b/pyproject.toml index b43dba2f..caf8020e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [build-system] -requires = ["scikit-build-core", "swig", "oldest-supported-numpy"] +requires = ["scikit-build-core", "swig", "numpy"] build-backend = "scikit_build_core.build" [project] name = "phreeqcrm" -version = "0.0.7" +version = "0.0.9" description = "A reaction module for transport simulators based on the geochemical model PHREEQC." readme = "README.md" requires-python = ">=3.8" @@ -19,8 +19,8 @@ classifiers = [ "Programming Language :: Python :: 3.12", ] dependencies = [ - "numpy", - "PyYAML" + "numpy", + "PyYAML" ] [tool.scikit-build] diff --git a/src/BMIPhreeqcRM.h b/src/BMIPhreeqcRM.h index 3221b2d9..a6711570 100644 --- a/src/BMIPhreeqcRM.h +++ b/src/BMIPhreeqcRM.h @@ -325,7 +325,29 @@ class IRM_DLL_EXPORT BMIPhreeqcRM : public bmi::Bmi, public PhreeqcRM @par MPI: Called by root. */ +#if defined(_MSC_VER) +#if defined(_WIN64) + std::string GetComponentName() override { + char buffer[400]; + sprintf(buffer, "BMI PhreeqcRM [MSC v.%d 64 bit (AMD64)]", _MSC_VER); + return buffer; + }; +#elif defined(_WIN32) + std::string GetComponentName() override { + char buffer[400]; + sprintf(buffer, "BMI PhreeqcRM [MSC v.%d 32 bit (Intel)]", _MSC_VER); + return buffer; + }; +#else + std::string GetComponentName() override { + char buffer[400]; + sprintf(buffer, "BMI PhreeqcRM [MSC v.%d Unknown]", _MSC_VER); + return buffer; + }; +#endif +#else std::string GetComponentName() override { return "BMI PhreeqcRM"; }; +#endif /** @a GetInputVarNames returns the count of input variables that can diff --git a/src/phreeqcrm/__init__.py b/src/phreeqcrm/__init__.py index 9b221125..5449b944 100644 --- a/src/phreeqcrm/__init__.py +++ b/src/phreeqcrm/__init__.py @@ -13,5 +13,6 @@ BoolVector, DoubleVector, IntVector, - StringVector + StringVector, + State ) diff --git a/swig/python/AdvectBMI_py.py b/swig/python/AdvectBMI_py.py index 4ec7938c..64cbfab3 100644 --- a/swig/python/AdvectBMI_py.py +++ b/swig/python/AdvectBMI_py.py @@ -1,6 +1,8 @@ import phreeqcrm import numpy as np +from constants import FilePaths + #module mydata # double precision, dimension(:), pointer :: K_ptr # integer :: rm_id @@ -95,7 +97,7 @@ def AdvectBMI_py(): # -------------------------------------------------------------------------- # Create PhreeqcRM # -------------------------------------------------------------------------- - yaml_file = "AdvectBMI_py.yaml" + yaml_file = FilePaths.YAML # phreeqc_rm.GetGridCellCountYAML must be called BEFORE # the PhreeqcRM instance is created. The diff --git a/swig/python/CMakeLists.txt b/swig/python/CMakeLists.txt index 45325547..3c7548c2 100644 --- a/swig/python/CMakeLists.txt +++ b/swig/python/CMakeLists.txt @@ -10,10 +10,16 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../pyfragments.swg.in pyfragments.swg # copy database to build directory for testing configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../../database/phreeqc.dat phreeqc.dat COPYONLY) +if(DEFINED SKBUILD) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../../database/phreeqc.dat ${CMAKE_CURRENT_SOURCE_DIR}/phreeqc.dat COPYONLY) +endif() # copy advect.pqi to build directory for testing configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/advect.pqi advect.pqi COPYONLY) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/all_reactants.pqi all_reactants.pqi COPYONLY) +if(DEFINED SKBUILD) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../../Tests/advect.pqi ${CMAKE_CURRENT_SOURCE_DIR}/advect.pqi COPYONLY) +endif() # copy SimpleAdvect.py to build directory for testing configure_file(SimpleAdvect.py SimpleAdvect.py COPYONLY) @@ -27,6 +33,8 @@ configure_file(WriteYAMLFile_py.py WriteYAMLFile_py.py COPYONLY) configure_file(TestAllMethods_py.py TestAllMethods_py.py COPYONLY) # copy pytest files to build directory for testing +configure_file(conftest.py conftest.py COPYONLY) +configure_file(constants.py constants.py COPYONLY) configure_file(test_basic.py test_basic.py COPYONLY) configure_file(test_get_value.py test_get_value.py COPYONLY) configure_file(test_init.py test_init.py COPYONLY) @@ -54,7 +62,7 @@ if(NOT PHREEQCRM_DISABLE_OPENMP) endif() endif() -if(PHREEQCRM_WITH_YAML_CPP AND yaml-cpp_FOUND) +if((PHREEQCRM_WITH_YAML_CPP AND yaml-cpp_FOUND) OR (DEFINED SKBUILD)) set_property(SOURCE ${phreeqcrm_INTERFACE_FULLPATH} APPEND PROPERTY COMPILE_DEFINITIONS USE_YAML) set_property(SOURCE ${phreeqcrm_INTERFACE_FULLPATH} APPEND PROPERTY DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/YAMLPhreeqcRM.swg @@ -121,6 +129,17 @@ if(PHREEQCRM_WITH_YAML_CPP AND yaml-cpp_FOUND) endif() endif() +if(DEFINED SKBUILD) + target_compile_definitions(${PYTHON_TARGET_NAME} PUBLIC USE_YAML) + if(TARGET yaml-cpp::yaml-cpp) + message(STATUS "SKBUILD found yaml-cpp::yaml-cpp") + target_link_libraries(${PYTHON_TARGET_NAME} PUBLIC yaml-cpp::yaml-cpp) + else() + message(STATUS "SKBUILD didn't find yaml-cpp::yaml-cpp") + target_link_libraries(${PYTHON_TARGET_NAME} PUBLIC yaml-cpp) + endif() +endif() + if(PHREEQCRM_NO_UTF8_ENCODING) target_compile_definitions(${PYTHON_TARGET_NAME} PRIVATE NO_UTF8_ENCODING) endif() diff --git a/swig/python/WriteYAMLFile_py.py b/swig/python/WriteYAMLFile_py.py index 98697b22..70a549c0 100644 --- a/swig/python/WriteYAMLFile_py.py +++ b/swig/python/WriteYAMLFile_py.py @@ -1,5 +1,7 @@ import numpy as np -import yamlphreeqcrm +import yamlphreeqcrm + +from constants import FilePaths def WriteYAMLFile_py(): # Create YAMLPhreeqcRM document @@ -103,7 +105,7 @@ def WriteYAMLFile_py(): time_step = 86400.0 yrm.YAMLSetTimeStep(time_step) # Write YAML file - yrm.WriteYAMLDoc("AdvectBMI_py.yaml") + yrm.WriteYAMLDoc(FilePaths.YAML) print("Done.") if __name__ == '__main__': diff --git a/swig/python/conftest.py b/swig/python/conftest.py new file mode 100644 index 00000000..fe8c44ba --- /dev/null +++ b/swig/python/conftest.py @@ -0,0 +1,15 @@ +import pytest +import os +import shutil + +from constants import FilePaths + +def pytest_sessionstart(): + cwd = os.getcwd() + + filenames = [FilePaths.DATABASE, FilePaths.PQI] + for filename in filenames: + src = filename + dest = os.path.join(cwd, os.path.basename(filename)) + if not os.path.exists(dest): + shutil.copy(src, dest) diff --git a/swig/python/constants.py b/swig/python/constants.py new file mode 100644 index 00000000..70438d73 --- /dev/null +++ b/swig/python/constants.py @@ -0,0 +1,9 @@ +# constants.py + +import os + +class FilePaths: + file_directory = os.path.dirname(__file__) + YAML = os.path.join(file_directory, 'AdvectBMI_py.yaml') + DATABASE = os.path.join(file_directory, 'phreeqc.dat') + PQI = os.path.join(file_directory, 'advect.pqi') diff --git a/swig/python/test_basic.py b/swig/python/test_basic.py index 3b22b9a8..c1c414db 100644 --- a/swig/python/test_basic.py +++ b/swig/python/test_basic.py @@ -5,6 +5,8 @@ from phreeqcrm import BMIPhreeqcRM, IRM_OK, State +from constants import FilePaths + ERROR_GET_VALUE_PTR_NOT_SUPPORTED = "get_value_ptr not supported for this variable." ERROR_SET_VALUE_NOT_SUPPORTED = "set_value not supported for this variable." @@ -12,6 +14,44 @@ def test_main(): # for debugging print(f"PYTHONPATH={os.getenv('PYTHONPATH')}") +def test_prereqs(): + # for debugging + cwd = os.getcwd() + print(f"Current working directory: {cwd}") + + yaml = FilePaths.YAML + + # Check if src file exists + assert os.path.exists(yaml), f"{yaml} does not exist" + + # Check if src file size is greater than 0 bytes + assert os.path.getsize(yaml) > 0, f"{yaml} is empty" + + database = FilePaths.DATABASE + + # Check if src file exists + assert os.path.exists(database), f"{database} does not exist" + + # Check if src file size is greater than 0 bytes + assert os.path.getsize(database) > 0, f"{database} is empty" + + # database must be in current working directory + database_dest = os.path.join(cwd, os.path.basename(database)) + assert os.path.exists(database_dest), f"{database_dest} does not exist" + + pqi = FilePaths.PQI + print(f"pqi: {pqi}") + + # Check if src file exists + assert os.path.exists(pqi), f"{pqi} does not exist" + + # Check if file size is greater than 0 bytes + assert os.path.getsize(pqi) > 0, f"{pqi} is empty" + + # pqi must be in current working directory + pqi_dest = os.path.join(cwd, os.path.basename(pqi)) + assert os.path.exists(pqi_dest), f"{pqi_dest} does not exist" + def test_dtor(): model = BMIPhreeqcRM() del model @@ -37,14 +77,14 @@ def test_get_components_is_tuple(): def test_get_grid_size_AdvectBMI(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) nxyz = model.get_grid_size(0) assert(nxyz == 40) def test_get_value_ptr_is_ndarray(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) nxyz = model.get_grid_size(0) temperature = model.get_value_ptr("Temperature") @@ -57,7 +97,7 @@ def test_get_value_ptr_is_ndarray(): def test_get_temperature_ptr_is_writeable(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) nxyz = model.get_grid_size(0) # test WRITEABLE @@ -78,7 +118,7 @@ def test_get_temperature_ptr_is_writeable(): def test_get_value_ptr_ComponentCount_is_readonly(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # make sure get_value_ptr can be called before get_input_var_names component_count = model.get_value_ptr("ComponentCount") @@ -96,7 +136,7 @@ def test_get_value_ptr_ComponentCount_is_readonly(): def test_get_input_var_names_is_tuple(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) input_vars = model.get_input_var_names() assert(isinstance(input_vars, tuple)) @@ -104,7 +144,7 @@ def test_get_input_var_names_is_tuple(): def test_get_output_var_names_is_tuple(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) output_vars = model.get_output_var_names() assert(isinstance(output_vars, tuple)) @@ -112,7 +152,7 @@ def test_get_output_var_names_is_tuple(): def test_GetComponents_is_tuple(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) components = model.GetComponents() assert(isinstance(components, tuple)) @@ -120,7 +160,7 @@ def test_GetComponents_is_tuple(): def test_get_value_ptr_Components_is_ndarray(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) components = model.get_value_ptr("Components") assert(isinstance(components, np.ndarray)) @@ -133,7 +173,7 @@ def test_get_value_ptr_Components_is_ndarray(): def test_get_value_ptr_Components_is_readonly(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) components = model.get_value_ptr("Components") @@ -145,7 +185,7 @@ def test_get_value_ptr_Components_is_readonly(): def test_get_value_ptr_Porosity(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) nxyz = model.get_grid_size(0) porosity = model.get_value_ptr("Porosity") @@ -156,7 +196,7 @@ def test_get_value_ptr_Porosity(): def test_get_value_ptr_SolutionVolume(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) nxyz = model.get_grid_size(0) solution_volume = model.get_value_ptr("SolutionVolume") @@ -169,7 +209,7 @@ def test_get_value_ptr_SolutionVolume(): def test_get_value_ptr_Concentrations(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) nxyz = model.get_grid_size(0) components = model.get_value_ptr("Components") @@ -257,7 +297,7 @@ def test_get_value_ptr_Concentrations(): def test_get_value_ptr_ndarray_str(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) components = model.get_value_ptr("Components") comps = np.empty_like(components) @@ -274,14 +314,14 @@ def test_get_value_ptr_ndarray_str(): def test_SetComponentH2O(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) status = model.SetComponentH2O(True) assert(status == IRM_OK) def test_get_value_FilePrefix(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # FilePrefix doesn't support get_value_ptr expected = "AdvectBMI_py" @@ -294,7 +334,7 @@ def test_get_value_FilePrefix(): def test_get_value_FilePrefix_fail(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # FilePrefix doesn't support get_value_ptr sz = 4 @@ -315,7 +355,7 @@ def test_get_value_FilePrefix_fail(): def test_get_value_FilePrefix_big_buffer(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # FilePrefix doesn't support get_value_ptr expected = "AdvectBMI_py" @@ -328,7 +368,7 @@ def test_get_value_FilePrefix_big_buffer(): def test_get_value_ComponentCount(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # ComponentCount supports get_value_ptr @todo ##component_count = np.full((1,), 0) @@ -339,7 +379,7 @@ def test_get_value_ComponentCount(): def test_get_value_ptr_ComponentCount(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # ComponentCount supports get_value_ptr @todo component_count = np.empty((1,), dtype=int) @@ -349,7 +389,7 @@ def test_get_value_ptr_ComponentCount(): def test_get_value_ptr_failure(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # "Components" is currently excluded should_raise = ("CurrentSelectedOutputUserNumber", "DensityUser", "ErrorString", "FilePrefix", "NthSelectedOutput", "SaturationUser", "SelectedOutput", "SelectedOutputColumnCount", "SelectedOutputCount", "SelectedOutputHeadings", "SelectedOutputRowCount") @@ -361,7 +401,7 @@ def test_get_value_ptr_failure(): def test_read_only_vars(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # "Components" is currently excluded readonly_list = model.get_readonly_var_names() @@ -384,7 +424,7 @@ def test_read_only_vars(): def test_get_value_Time(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) # Time supports get_value_ptr @todo time = np.empty((1,), dtype=float) diff --git a/swig/python/test_get_value.py b/swig/python/test_get_value.py index ec1ef325..cbc2d725 100644 --- a/swig/python/test_get_value.py +++ b/swig/python/test_get_value.py @@ -3,6 +3,8 @@ from phreeqcrm import BMIPhreeqcRM +from constants import FilePaths + def test_get_initial_value(): model = BMIPhreeqcRM() model.initialize() @@ -24,7 +26,7 @@ def test_get_value_copy(): def test_get_value_copy_int_scalar(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) dest0 = np.empty((1,), dtype=int) dest1 = np.empty((1,), dtype=int) @@ -39,7 +41,7 @@ def test_get_value_copy_int_scalar(): def test_get_value_copy_float_scalar(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) dest0 = np.empty((1,), dtype=float) dest1 = np.empty((1,), dtype=float) @@ -54,7 +56,7 @@ def test_get_value_copy_float_scalar(): def test_get_value_copy_str(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) components = model.get_value_ptr("Components") dest0 = np.empty_like(components) @@ -68,7 +70,7 @@ def test_get_value_copy_str(): def test_get_value_pointer(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) dest1 = np.empty(model.get_grid_size(0), dtype=float) @@ -85,7 +87,7 @@ def test_get_value_pointer(): def test_get_value_pointer2(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) z0 = model.get_value_ptr("Porosity") assert(z0[0] != 0.999) @@ -105,7 +107,7 @@ def test_get_value_pointer2(): def test_get_value_at_indices(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) temps = np.linspace(18.0, 30.0, model.get_grid_size(0)) model.set_value("Temperature", temps) @@ -119,21 +121,21 @@ def test_get_value_at_indices(): def test_value_size(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) z = model.get_value_ptr("Temperature") assert model.get_grid_size(0) == z.size def test_value_nbytes(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) z = model.get_value_ptr("Temperature") assert model.get_var_nbytes("Temperature") == z.nbytes def test_all_pointable(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) vars = model.get_pointable_var_names() assert(isinstance(vars, tuple)) diff --git a/swig/python/test_init.py b/swig/python/test_init.py index 32aabeb2..fe4dc55a 100644 --- a/swig/python/test_init.py +++ b/swig/python/test_init.py @@ -5,6 +5,8 @@ from phreeqcrm import BMIPhreeqcRM, IRM_OK, State +from constants import FilePaths + ERROR_MUST_INITIALIZE = "must call initialize first" ERROR_NOT_IMPLEMENTED = "Not Implemented" @@ -24,7 +26,7 @@ def test_initialize_AdvectBMI(): model = BMIPhreeqcRM() assert model._state == State.UNINITIALIZED - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) assert model._state == State.INITIALIZED ############################################################################### diff --git a/swig/python/test_irf.py b/swig/python/test_irf.py index e0cd24b1..ad5b0027 100644 --- a/swig/python/test_irf.py +++ b/swig/python/test_irf.py @@ -7,11 +7,13 @@ from phreeqcrm import BMIPhreeqcRM +from constants import FilePaths + def test_component_name(): model = BMIPhreeqcRM() name = model.get_component_name() - assert name == "BMI PhreeqcRM" + assert name[:13] == "BMI PhreeqcRM" #assert model.get_component_name() is name @todo def test_start_time(): @@ -73,7 +75,7 @@ def test_initialize_from_file(): def test_update(): model = BMIPhreeqcRM() ## model.initialize() # @todo - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) for inc in range(10): model.update() diff --git a/swig/python/test_set_value.py b/swig/python/test_set_value.py index b94055d3..55227077 100644 --- a/swig/python/test_set_value.py +++ b/swig/python/test_set_value.py @@ -3,9 +3,11 @@ from phreeqcrm import BMIPhreeqcRM +from constants import FilePaths + def test_set_value(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) z0 = model.get_value_ptr("Temperature") z1 = np.zeros_like(z0) - 1 @@ -20,7 +22,7 @@ def test_set_value(): def test_set_value_at_indices(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) model.set_value_at_indices("Temperature", np.array([0, 2, 4]), np.array([-1.0, -1.0, -1.0])) @@ -29,7 +31,7 @@ def test_set_value_at_indices(): def test_set_value_SelectedOutputOn(): model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) z0 = model.get_value_ptr("SelectedOutputOn") assert str(z0.dtype) == "int32" @@ -50,7 +52,7 @@ def test_numpy_integers_compatibility(): # not being integrated into PhreeqcRM.i model = BMIPhreeqcRM() - model.initialize("AdvectBMI_py.yaml") + model.initialize(FilePaths.YAML) z1 = np.full(1, 0, dtype=int) n = model.GetNthSelectedOutputUserNumber(z1[0])