Skip to content

Commit 9bb891f

Browse files
added a key / ref unit test and updated unit test script to optionally skip clean up
1 parent 10b559d commit 9bb891f

File tree

4 files changed

+85
-18
lines changed

4 files changed

+85
-18
lines changed

test/python_unit_tests/model/test_date_serialization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
def test_date_serialization():
1010
'''test date serialization'''
11-
dt_in = DateSerializatonTest(dateValue=DateTimeWithMeta(datetime.datetime(2025, 10, 30)))
11+
dt_in = DateSerializatonTest(dateValue=datetime.datetime(2025, 10, 30))
1212
dt_in.validate_model()
1313
dt_str = dt_in.rune_serialize()
1414
print('dt_str:', dt_str)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'''key ref unit test'''
2+
from rune.runtime.metadata import IntWithMeta, Reference
3+
4+
from rosetta_dsl.test.model.key_ref.A import A
5+
from rosetta_dsl.test.model.key_ref.B import B
6+
7+
def test_key_ref():
8+
'''test key ref'''
9+
a = A(aValue=IntWithMeta(value=1, key="key-123"))
10+
b = B(aReference=Reference(target=a, ext_key="key-123"))
11+
assert(len(b.validate_model())== 0)
12+
13+
if __name__ == "__main__":
14+
test_key_ref()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace rosetta_dsl.test.model.key_ref : <"generate Python unit tests from Rosetta.">
2+
3+
type A:
4+
[metadata key]
5+
aValue int (1..1)
6+
7+
type B:
8+
aReference A (1..1)
9+
[metadata reference]

test/python_unit_tests/run_python_unit_tests.sh

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,64 @@
11
#!/bin/bash
2-
function error
3-
{
2+
3+
function usage {
4+
cat <<EOF
5+
Usage: $(basename "$0") [options]
6+
7+
Options:
8+
-k, --no-clean, --skip-clean, --keep-venv Skip the cleanup step (leave venv active; do not run cleanup script)
9+
-h, --help Show this help
10+
Env:
11+
SKIP_CLEANUP=1 Same as --no-clean
12+
EOF
13+
}
14+
15+
function error {
416
echo
517
echo "***************************************************************************"
618
echo "* *"
719
echo "* DEV ENV Initialization FAILED! *"
820
echo "* *"
921
echo "***************************************************************************"
1022
echo
11-
exit -1
23+
exit 1
1224
}
1325

26+
# Default: perform cleanup unless asked not to
27+
CLEANUP=1
28+
# Env toggle
29+
if [[ "${SKIP_CLEANUP:-}" == "1" || "${SKIP_CLEANUP:-}" == "true" ]]; then
30+
CLEANUP=0
31+
fi
32+
# CLI options
33+
while [[ $# -gt 0 ]]; do
34+
case "$1" in
35+
-k|--no-clean|--skip-clean|--keep-venv)
36+
CLEANUP=0
37+
shift
38+
;;
39+
-h|--help)
40+
usage
41+
exit 0
42+
;;
43+
*)
44+
echo "Unknown option: $1"
45+
usage
46+
exit 2
47+
;;
48+
esac
49+
done
50+
1451
export PYTHONDONTWRITEBYTECODE=1
1552

16-
type -P python > /dev/null && PYEXE=python || PYEXE=python3
17-
if ! $PYEXE -c 'import sys; assert sys.version_info >= (3,11)' > /dev/null 2>&1; then
18-
echo "Found $($PYEXE -V)"
19-
echo "Expecting at least python 3.11 - exiting!"
20-
exit 1
53+
type -P python >/dev/null && PYEXE=python || PYEXE=python3
54+
if ! $PYEXE -c 'import sys; assert sys.version_info >= (3,11)' >/dev/null 2>&1; then
55+
echo "Found $($PYEXE -V)"
56+
echo "Expecting at least python 3.11 - exiting!"
57+
exit 1
2158
fi
2259

2360
MY_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
24-
cd ${MY_PATH} || error
61+
cd "${MY_PATH}" || error
2562
PROJECT_ROOT_PATH="$MY_PATH/../.."
2663
PYTHON_SETUP_PATH="$MY_PATH/../python_setup"
2764

@@ -48,27 +85,34 @@ java -cp "$JAR_PATH" com.regnosys.rosetta.generator.python.PythonCodeGeneratorCL
4885
-t "$PYTHON_TESTS_TARGET_PATH"
4986
JAVA_EXIT_CODE=$?
5087
if [[ $JAVA_EXIT_CODE -ne 0 ]]; then
51-
echo "Java program returned exit code $JAVA_EXIT_CODE. Stopping script."
52-
exit 1
88+
echo "Java program returned exit code $JAVA_EXIT_CODE. Stopping script."
89+
exit 1
5390
fi
5491

5592
echo "***** setting up common environment"
93+
# shellcheck disable=SC1090
5694
source "$PYTHON_SETUP_PATH/setup_python_env.sh"
5795

5896
echo "***** activating virtual environment"
5997
VENV_NAME=".pyenv"
98+
# shellcheck disable=SC1090
6099
source "$PROJECT_ROOT_PATH/$VENV_NAME/${PY_SCRIPTS}/activate" || error
61100

62101
# package and install generated Python
63-
cd $PYTHON_TESTS_TARGET_PATH
64-
$PYEXE -m pip wheel --no-deps --only-binary :all: . || processError
102+
cd "$PYTHON_TESTS_TARGET_PATH" || error
103+
$PYEXE -m pip wheel --no-deps --only-binary :all: . || error
65104
$PYEXE -m pip install python_rosetta_dsl-0.0.0-py3-none-any.whl
66105

67106
# run tests
68107
echo "***** run unit tests"
69-
cd "$MY_PATH"
108+
cd "$MY_PATH" || error
70109
$PYEXE -m pytest -p no:cacheprovider "$MY_PATH"
71110

72-
echo "***** cleanup"
73-
deactivate
74-
source "$PYTHON_SETUP_PATH/cleanup_python_env.sh"
111+
if (( CLEANUP )); then
112+
echo "***** cleanup"
113+
deactivate 2>/dev/null || true
114+
# shellcheck disable=SC1090
115+
source "$PYTHON_SETUP_PATH/cleanup_python_env.sh"
116+
else
117+
echo "***** skipping cleanup (requested)"
118+
fi

0 commit comments

Comments
 (0)