Skip to main content

pytest plugin for PAIA Blockly: verify get_solution() against test cases

Project description

pytest-paia-blockly

pytest 外掛,用於 PAIA Blockly:依 case.json 測資驗證 solution.py 中的 get_solution() 是否正確。


安裝

pip install pytest-paia-blockly

或從原始碼可編輯安裝:

pip install -e .
# 或
uv pip install -e .

使用方式

1. 用 pytest 直接跑(需提供測試檔)

pytest tests/test_framework.py \
  --paia-target-module ./solution.py \
  --paia-testcases ./case.json \
  --paia-result ./var/result.json \
  -v

2. 用指令 paia-blockly-test(套件內建測試入口)

paia-blockly-test \
  --paia-target-module ./solution.py \
  --paia-testcases ./case.json \
  --paia-result ./var/result.json \
  -v

3. 用 python -m 執行

python -m pytest_paia_blockly \
  --paia-target-module ./solution.py \
  --paia-testcases ./case.json \
  --paia-result ./var/result.json \
  -v

命令列選項

選項 必填 說明
--paia-target-module solution.py 的檔案路徑,該模組需提供 get_solution(input: dict)
--paia-testcases case.json 的路徑,格式見下方。
--paia-result 結果 JSON 輸出路徑,預設 ./var/paia_result.json

選項可用 --option 值--option=值;建議用空格分隔以利 shell 路徑自動補齊。
若未提供任一共用選項,test_verify_case 會參數化為 0 筆,不會執行任何測資。


題目格式

  • case.json:陣列,每筆為 { "index", "input", "expected": { "type", "value" } }

    [
      { "index": 1, "input": { "list": [1, 2] }, "expected": { "type": "int", "value": 3 } },
      { "index": 2, "input": { "list": [3, 4] }, "expected": { "type": "int", "value": 7 } }
    ]
    
  • solution.py:需定義 get_solution(input: dict),回傳值會與 expected 比對(型別與值)。


範例腳本(本 repo)

專案內 examples/ 為範例題目,可用以下腳本跑對應題目:

目錄 說明
scripts/cli/ 使用 paia-blockly-test 的腳本(如 run_sum_the_list.shrun_all.sh)。
scripts/python_m/ 使用 python -m pytest_paia_blockly 的腳本。
scripts/pytest/ 使用 pytest tests/test_framework.py 的腳本(檔名以 pytest_ 開頭)。

執行前請先啟動虛擬環境或安裝套件,例如:

bash scripts/cli/run_sum_the_list.sh
# 或
bash scripts/pytest/pytest_sum_the_list.sh

開發

  • 測試pytest tests/(含 test_plugin.pytest_examples.py 等)。
  • 建構與上傳bash scripts/build_and_upload.sh(需先設定 PyPI token)。

授權

Copyright (c) 2025 PAIA Technology Inc. All rights reserved.
詳見 LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_paia_blockly-0.3.0.tar.gz (33.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_paia_blockly-0.3.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file pytest_paia_blockly-0.3.0.tar.gz.

File metadata

  • Download URL: pytest_paia_blockly-0.3.0.tar.gz
  • Upload date:
  • Size: 33.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for pytest_paia_blockly-0.3.0.tar.gz
Algorithm Hash digest
SHA256 5415cbaacc62964b28ae9355eea87920e7d30d33b1edaea19c637f6de3b6228b
MD5 0e09d9b20430b0e0997590fe6fde35fa
BLAKE2b-256 2c9910c69c97fc5935e6fe96e151c3170dd6faca9b61587d38d6d65f615c6efa

See more details on using hashes here.

File details

Details for the file pytest_paia_blockly-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_paia_blockly-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 50266ed34d6aa420001695074c14789d96ed920af0830dd116b41dd432dd8594
MD5 2e0c841f3b92fba89043310c9f588db9
BLAKE2b-256 c563884f551779c3c929b18fca2fff9d81ef76b023bbd62aac4e1e391a59f8a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page