From 11d727d0f4d2999cff862805c6cc967680daf1a1 Mon Sep 17 00:00:00 2001 From: Jack Greenlee Date: Wed, 23 Oct 2024 18:59:41 -0400 Subject: [PATCH] Fixes for `run_jest.sh` on GH Actions and JS compatibility (#11) * fix realpath in run_jest.sh Although 'realpath' with no argument works on MacOS, it failed in the GH Actions workflow which runs on Ubuntu. Use `.` for current directory * don't use keyword args to calc_footprint (for JS compat) keyword arguments only work properly in Transcrypt if we have the `__kwargs__` pragma enabled on the funtion that accepts them. Since we are giving all the arguments here, it's easy enough to just pass them as positional arguments, eliminating the need for keyword arguments here * if shopt is available, enable 'globstar' before iterating over ** glob * only run unit-tests on PRs or pushes to `master` --- .github/workflows/unit-tests.yml | 4 ++++ bin/run_jest.sh | 7 ++++++- src/emcommon/metrics/footprint/footprint_calculations.py | 8 ++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 3691eca..5398e60 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -5,7 +5,11 @@ name: unit-tests # Controls when the action will run. Triggers the workflow on push or pull request on: push: + branches: + - master pull_request: + branches: + - master # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: diff --git a/bin/run_jest.sh b/bin/run_jest.sh index 860d6f3..ab96372 100755 --- a/bin/run_jest.sh +++ b/bin/run_jest.sh @@ -4,11 +4,16 @@ echo "Running JavaScript tests..." -ROOT_DIR_ABSOLUTE=$(realpath) +ROOT_DIR_ABSOLUTE=$(realpath .) # remove any existing test_js_* directories (from previous runs) rm -rf $ROOT_DIR_ABSOLUTE/test_js_* +# if shopt is available, enable globstar +if command -v shopt >/dev/null 2>&1; then + shopt -s globstar + echo "Enabled globstar in shopt" +fi for file in test/**/test_*.py; do # if there is a .js file in the same directory, skip diff --git a/src/emcommon/metrics/footprint/footprint_calculations.py b/src/emcommon/metrics/footprint/footprint_calculations.py index a43bf68..868e598 100644 --- a/src/emcommon/metrics/footprint/footprint_calculations.py +++ b/src/emcommon/metrics/footprint/footprint_calculations.py @@ -31,10 +31,10 @@ async def calc_footprint_for_trip(trip, label_options, mode_key='mode', mode_val trip['distance'], emcmfu.year_of_trip(trip), trip['start_loc']['coordinates'], - uace=trip.get('uace_region'), - egrid_region=trip.get('egrid_region'), - passengers=rich_mode.get('passengers', 1), - metadata={'trip_id': trip['_id']} + trip.get('uace_region'), + trip.get('egrid_region'), + rich_mode.get('passengers', 1), + {'trip_id': trip['_id']} ) # If is_uncertain, the kwh and kg_co2 values represent the upper bound (worst-case scenario) # Mark them as them uncertain, then set the main values to 0 to represent the lower bound.