Skip to content

Commit 5a653be

Browse files
chore: clean up testing scripts to provide the package name
1 parent da10d65 commit 5a653be

5 files changed

Lines changed: 28 additions & 40 deletions

File tree

python-test/cdm-tests/run_cdm_tests.sh

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ while [[ $# -gt 0 ]]; do
6565
done
6666

6767
CDM_WHEEL_DIR="$MY_PATH/../../target/python-cdm"
68-
CDM_WHEEL_COUNT=$(find "$CDM_WHEEL_DIR" -name "python_cdm-*-py3-none-any.whl" 2>/dev/null | wc -l)
68+
CDM_WHEEL_COUNT=$(find "$CDM_WHEEL_DIR" -name "*-py3-none-any.whl" 2>/dev/null | wc -l)
6969

7070
if [[ $CDM_WHEEL_COUNT -eq 0 && $UPDATE_CDM -eq 0 && $REBUILD_CDM -eq 0 ]]; then
7171
echo "CDM Python wheel not found in $CDM_WHEEL_DIR. Triggering build (fetch + build)..."
@@ -85,12 +85,11 @@ echo "***** setting up common environment"
8585
source $MY_PATH/setup_cdm_test_env.sh || error
8686

8787

88-
# run tests
89-
90-
# Validating test execution
88+
# run tests — venv is active at this point; use bare 'python' so the venv's
89+
# interpreter is used, not the system python path cached in $PYEXE
9190
echo "***** run tests"
92-
$PYEXE -m pip install pytest
93-
$PYEXE -m pytest -p no:cacheprovider $MY_PATH
91+
python -m pip install pytest
92+
python -m pytest -p no:cacheprovider $MY_PATH
9493
TEST_EXIT_CODE=$?
9594
rm -rf .pytest
9695

python-test/cdm-tests/setup/build_cdm.sh

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -82,46 +82,24 @@ fi
8282
ensure_jar_exists "$PROJECT_ROOT_PATH" "$JAR_PATH"
8383

8484
echo "***** build CDM"
85-
java -cp "$JAR_PATH" com.regnosys.rosetta.generator.python.PythonCodeGeneratorCLI -s $CDM_SOURCE_PATH -t $PYTHON_TARGET_PATH -n $CDM_PROJECT_NAME -v $CDM_VERSION -x $CDM_PREFIX|| error "Failed to generate CDM Python code"
86-
# java -cp "$JAR_PATH" com.regnosys.rosetta.generator.python.PythonCodeGeneratorCLI -s $CDM_SOURCE_PATH -t $PYTHON_TARGET_PATH || error "Failed to generate CDM Python code"
85+
java -cp "$JAR_PATH" com.regnosys.rosetta.generator.python.PythonCodeGeneratorCLI -s $CDM_SOURCE_PATH -t $PYTHON_TARGET_PATH -p $CDM_PROJECT_NAME -v $CDM_VERSION -x $CDM_PREFIX || error "Failed to generate CDM Python code"
8786
JAVA_EXIT_CODE=$?
8887
if [[ $JAVA_EXIT_CODE -eq 1 ]]; then
8988
echo "Java program returned exit code 1. Stopping script."
9089
exit 1
9190
fi
9291

93-
echo "***** setting up common environment"
94-
source $PYTHON_SETUP_PATH/setup_python_env.sh
95-
96-
echo "***** activating virtual environment"
97-
VENV_NAME=".pyenv"
98-
if [ -z "${WINDIR}" ]; then PY_SCRIPTS='bin'; else PY_SCRIPTS='Scripts'; fi
99-
source "$PROJECT_ROOT_PATH/$VENV_NAME/${PY_SCRIPTS}/activate" || error
100-
101-
echo "***** removing prior instance of cdm"
102-
python -m pip uninstall -y python-cdm 2>/dev/null
103-
10492
echo "***** build CDM Python package"
10593
cd $PYTHON_TARGET_PATH
106-
rm -f *-*.*.*-py3-none-any.whl
107-
python -m pip wheel --no-deps --only-binary :all: . || error
94+
rm -f *-py3-none-any.whl
95+
$PYEXE -m pip wheel --no-deps --only-binary :all: . || error
10896

109-
echo "***** install CDM Python package"
110-
CDM_WHL=$(ls *-*.*.*-py3-none-any.whl 2>/dev/null | head -1)
97+
CDM_WHL=$(ls *-py3-none-any.whl 2>/dev/null | head -1)
11198
if [ -z "$CDM_WHL" ]; then
112-
echo "ERROR: cdm wheel was not produced. Stopping."
99+
echo "ERROR: CDM wheel was not produced. Stopping."
113100
error
114101
fi
115-
python -m pip install --no-deps "$CDM_WHL" --force-reinstall || error
116-
117-
echo "***** cleanup"
118-
119-
deactivate
120-
if [[ "${REUSE_ENV}" != "1" && "${REUSE_ENV}" != "true" ]]; then
121-
source $PYTHON_SETUP_PATH/cleanup_python_env.sh
122-
else
123-
echo "Skipping cleanup (REUSE_ENV set)"
124-
fi
102+
echo "***** CDM wheel produced: $CDM_WHL"
125103

126104
echo ""
127105
echo ""

python-test/cdm-tests/setup_cdm_test_env.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ cd ${MY_PATH} || error
3737

3838
echo "***** setting up common environment"
3939
PYTHONSETUPPATH="../env-setup"
40-
source $MY_PATH/$PYTHONSETUPPATH/setup_python_env.sh
40+
source $MY_PATH/$PYTHONSETUPPATH/setup_python_env.sh -r
4141

4242
echo "***** activating virtual environment"
4343
VENV_NAME=".pyenv"
@@ -50,11 +50,20 @@ source "$MY_PATH/$PYTHONSETUPPATH/$VENV_PATH/${PY_SCRIPTS}/activate" || error
5050
PYTHONCDMDIR="../../target/python-cdm"
5151

5252
# Construct pip install command
53-
PIP_ARGS=( "$MY_PATH/$PYTHONCDMDIR"/python_cdm-*-py3-none-any.whl "--force-reinstall" "--pre" )
53+
PIP_ARGS=( "$MY_PATH/$PYTHONCDMDIR"/*-*-py3-none-any.whl "--force-reinstall" "--pre" )
5454

5555
if [[ -n "$RUNE_RUNTIME_DIR" && -d "$RUNE_RUNTIME_DIR" ]]; then
5656
PIP_ARGS+=( "--find-links" "$RUNE_RUNTIME_DIR" )
5757
fi
5858

5959
echo "**** Install CDM package ****"
60-
python -m pip install "${PIP_ARGS[@]}"
60+
python -m pip install "${PIP_ARGS[@]}"
61+
62+
# The CDM wheel install (--force-reinstall) may have replaced the local editable
63+
# runtime with a PyPI release. Re-source setup_python_env.sh with REUSE_ENV=1 so
64+
# it reinstalls the runtime without recreating the venv, then re-activate.
65+
_reuse_env_saved="${REUSE_ENV:-}"
66+
export REUSE_ENV=1
67+
source "$MY_PATH/$PYTHONSETUPPATH/setup_python_env.sh"
68+
export REUSE_ENV="$_reuse_env_saved"
69+
source "$MY_PATH/$PYTHONSETUPPATH/$VENV_PATH/${PY_SCRIPTS}/activate" || error

python-test/cdm-tests/test_import_trade_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
def test_import_tradestate():
66
'''confirm that tradestate can be imported'''
77
try:
8-
from cdm.event.common.TradeState import TradeState
8+
from finos.cdm.event.common.TradeState import TradeState
99
except ImportError:
1010
pytest.fail("Importing cdm.event.common.TradeState failed")

python-test/unit-tests/run_python_unit_tests.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ JAR_PATH="$PROJECT_ROOT_PATH/target/python-0.0.0.main-SNAPSHOT.jar"
116116

117117
# Always generate from the root of the test suite to ensure the "overall model" is complete
118118
INPUT_ROSETTA_PATH="$MY_PATH"
119+
PTYHON_PROJECT_NAME="python-test"
119120

120121
if [[ $RUN_ALL -eq 1 ]]; then
121122
TEST_TARGET="$MY_PATH"
@@ -143,7 +144,8 @@ echo "***** generating Python for unit tests"
143144
mkdir -p "$PYTHON_TESTS_TARGET_PATH"
144145
java -cp "$JAR_PATH" com.regnosys.rosetta.generator.python.PythonCodeGeneratorCLI \
145146
-s "$INPUT_ROSETTA_PATH" \
146-
-t "$PYTHON_TESTS_TARGET_PATH"
147+
-t "$PYTHON_TESTS_TARGET_PATH" \
148+
-p "$PTYHON_PROJECT_NAME"
147149
JAVA_EXIT_CODE=$?
148150
if [[ $JAVA_EXIT_CODE -ne 0 ]]; then
149151
echo "Java program returned exit code $JAVA_EXIT_CODE. Stopping script."
@@ -173,7 +175,7 @@ fi
173175
# package and install generated Python
174176
cd "$PYTHON_TESTS_TARGET_PATH" || error
175177
python -m pip wheel --no-deps --only-binary :all: . || error
176-
python -m pip install python_rosetta_dsl-0.0.0-py3-none-any.whl
178+
python -m pip install *-0.0.0-py3-none-any.whl
177179

178180
# Find and run all build_and_install.sh scripts to ensure the environment matches the "overall model"
179181
echo "***** installing all native implementations"

0 commit comments

Comments
 (0)