From f7736e51135245c1d2e6516a48dcbf240d68d577 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Thu, 9 May 2019 14:24:04 +0200 Subject: [PATCH 1/5] Add a test case for PYTHONPATH when using --python3 flag. --- cli/test_pack_python3.bats | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cli/test_pack_python3.bats b/cli/test_pack_python3.bats index b5e699c..8356882 100644 --- a/cli/test_pack_python3.bats +++ b/cli/test_pack_python3.bats @@ -84,4 +84,11 @@ teardown() { run eval "echo '$RESULT' | jq -r '.status'" assert_output "succeeded" + + # Verify PYTHONPATH is correct + + RESULT=$(st2 run examples.python_runner_print_python_environment -j) + assert_success + + assert_output --partial "PYTHONPATH: /opt/stackstorm/packs/examples/lib:/usr/lib/python3.6:/opt/stackstorm/virtualenvs/examples/lib/python3.6" } From 52c97b61eda4065930805d53d18ea60e83b54e9b Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Thu, 9 May 2019 15:30:11 +0200 Subject: [PATCH 2/5] Add another test case for it. --- cli/test_pack_python3.bats | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cli/test_pack_python3.bats b/cli/test_pack_python3.bats index 8356882..2d85baf 100644 --- a/cli/test_pack_python3.bats +++ b/cli/test_pack_python3.bats @@ -92,3 +92,18 @@ teardown() { assert_output --partial "PYTHONPATH: /opt/stackstorm/packs/examples/lib:/usr/lib/python3.6:/opt/stackstorm/virtualenvs/examples/lib/python3.6" } + +@test "python3 imports work correctly" { + PACK_INSTALL_RESULT=$(st2 run pack install python3_test python3=true -j) + assert_success + + + RESULT=$(st2 run python3_test.test_stdlib_import -j) + assert_success + + run eval "echo '$RESULT' | jq -r '.result.stdout'" + assert_success + + assert_output "succeeded" + assert_output --partial "imports work correctly" +} From 36d17133f6d9be7ea68ab383a50c3e79e2220075 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 13 May 2019 10:32:03 +0200 Subject: [PATCH 3/5] Update tests. --- cli/test_pack_python3.bats | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cli/test_pack_python3.bats b/cli/test_pack_python3.bats index 2d85baf..72e127a 100644 --- a/cli/test_pack_python3.bats +++ b/cli/test_pack_python3.bats @@ -94,16 +94,18 @@ teardown() { } @test "python3 imports work correctly" { - PACK_INSTALL_RESULT=$(st2 run pack install python3_test python3=true -j) + PACK_INSTALL_RESULT=$(st2 pack install python3_test --python3 -j) assert_success RESULT=$(st2 run python3_test.test_stdlib_import -j) assert_success - run eval "echo '$RESULT' | jq -r '.result.stdout'" + run eval "echo '$RESULT' | jq -r '.result.result'" assert_success - - assert_output "succeeded" assert_output --partial "imports work correctly" + + run eval "echo '$RESULT' | jq -r '.result.stdout'" + assert_success + assert_output --partial "Using Python version: 3." } From 06198c787e1022a4d4f68955fc0711079d23c25d Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 13 May 2019 10:44:48 +0200 Subject: [PATCH 4/5] Fix tests. --- cli/test_pack_python3.bats | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/cli/test_pack_python3.bats b/cli/test_pack_python3.bats index 72e127a..818dcf5 100644 --- a/cli/test_pack_python3.bats +++ b/cli/test_pack_python3.bats @@ -1,9 +1,6 @@ - load '../test_helpers/bats-support/load' load '../test_helpers/bats-assert/load' - - STATUS_SUCCESS='"status": "succeeded' setup() { @@ -36,9 +33,12 @@ teardown() { st2 run packs.uninstall packs=examples fi [[ ! -d /opt/stackstorm/packs/examples ]] -} - + if [[ -d /opt/stackstorm/packs/python3_test ]]; then + st2 run packs.uninstall packs=python3_test + fi + [[ ! -d /opt/stackstorm/packs/python3_test ]] +} @test "packs.setup_virtualenv without python3 flags works and defaults to Python 2" { SETUP_VENV_RESULTS=$(st2 run packs.setup_virtualenv packs=examples -j) @@ -65,7 +65,6 @@ teardown() { run eval "echo '$SETUP_VENV_RESULTS' | jq -r '.status'" assert_success - assert_output "succeeded" run /opt/stackstorm/virtualenvs/examples/bin/python --version @@ -86,18 +85,18 @@ teardown() { assert_output "succeeded" # Verify PYTHONPATH is correct - RESULT=$(st2 run examples.python_runner_print_python_environment -j) assert_success - assert_output --partial "PYTHONPATH: /opt/stackstorm/packs/examples/lib:/usr/lib/python3.6:/opt/stackstorm/virtualenvs/examples/lib/python3.6" + run eval "echo '$RESULT' | jq -r '.result.stdout'" + assert_success + assert_output --partial "PYTHONPATH: /usr/lib/python3" } @test "python3 imports work correctly" { - PACK_INSTALL_RESULT=$(st2 pack install python3_test --python3 -j) + run st2 pack install python3_test --python3 -j assert_success - RESULT=$(st2 run python3_test.test_stdlib_import -j) assert_success From 0dc2bbebae38ffbb85f5cf85bc6b50989afbf437 Mon Sep 17 00:00:00 2001 From: Tomaz Muraus Date: Mon, 13 May 2019 11:03:35 +0200 Subject: [PATCH 5/5] Update it so it also works on distros where non standard prefix is used. --- cli/test_pack_python3.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/test_pack_python3.bats b/cli/test_pack_python3.bats index 818dcf5..68a4d3f 100644 --- a/cli/test_pack_python3.bats +++ b/cli/test_pack_python3.bats @@ -90,7 +90,7 @@ teardown() { run eval "echo '$RESULT' | jq -r '.result.stdout'" assert_success - assert_output --partial "PYTHONPATH: /usr/lib/python3" + assert_output --regexp ".*PYTHONPATH: /usr/(local/)?lib/python3.*" } @test "python3 imports work correctly" {