Skip to content

13. テストと開発 ​

リポジトリの構成と、テストの実行方法です。

リポジトリ構成 ​

text
elabftw-toolkit/
├── pyproject.toml
├── README.md
├── README_en.md
├── LICENSE
├── .env.example
├── mkdocs.yml               # docs/ をサイトにするときの設定(任意)
├── docs/                    # 利用者向けガイド(ja / en)
├── src/
│   └── elabftw_toolkit/
│       ├── __init__.py
│       ├── client.py        # client() と elab.experiments / elab.items / entry(id)
│       ├── teams.py
│       ├── categories.py
│       ├── statuses.py
│       ├── templates.py
│       ├── experiments.py
│       ├── items.py
│       ├── search.py
│       ├── metadata_utils.py
│       ├── fields.py        # entry.fields と extra_fields() など
│       ├── links.py
│       ├── tags.py
│       ├── html_tables.py
│       ├── files.py
│       ├── images.py
│       ├── steps.py
│       ├── permissions.py
│       ├── common.py
│       ├── dataframe.py
│       ├── maiml.py
│       └── _http.py         # SDK を通さない API 呼び出し(timeout・GET の試し直し)
└── tests/
    ├── test_client.py       # オフラインの単体テスト(pytest)
    ├── test_utils.py        # オフラインの単体テスト(pytest)
    ├── test_maiml.py        # オフラインの単体テスト(pytest)
    └── live/                # 実サーバーに書き込む動作確認用スクリプト(pytest では集めない)
        ├── test_init.py
        ├── test_id.py
        ├── test_exp_*.py
        ├── test_item_*.py
        ├── test_usergroups.py
        ├── test_allowed_tags.csv
        ├── .env.test.example
        ├── test_file/
        └── output/

オフラインの単体テスト ​

tests/test_*.py は eLabFTW に接続しない単体テストです(API は unittest.mock で置き換えます)。リポジトリのルートで pytest を実行すると、これだけが集められます。

bash
python -m pip install -e ".[maiml]" pytest
pytest

tests/test_maiml.py は pymaiml が無ければ飛ばします。

tests/conftest.py の fake(FakeELN)は、entry を dict で持つ ELN の代わりです。スキーマ・試行と計画・二重登録・変更の記録・リンクの項目の試験(test_schema.py・test_plan.py・test_find.py)が使います。tests/test_compat.py は、入っている elabapi_python に toolkit が使う API のクラスとメソッドが全部あるかを dir() で確かめます(elabapi_python を上げたら最初にこれを流します)。

実サーバーでの動作確認用スクリプト(tests/live/) ​

tests/live/ には、各機能を実際の eLabFTW サーバーで確かめるスクリプトがあります。pytest では集めません(pyproject.toml の --ignore=tests/live)。どのスクリプトも実行時に作業フォルダーを tests/live/ に移すので、.env.test・test_file/・output/・test_allowed_tags.csv はこのフォルダーに置きます(.env.test.example をコピーして使います)。

bash
python tests/live/test_init.py
python tests/live/test_id.py

python tests/live/test_exp_init.py
python tests/live/test_exp_search.py
python tests/live/test_exp_metadata.py
python tests/live/test_exp_structured_metadata.py
python tests/live/test_exp_field_link.py
python tests/live/test_exp_link.py
python tests/live/test_exp_category_status.py
python tests/live/test_exp_tags.py
python tests/live/test_exp_html.py
python tests/live/test_exp_files_upload.py
python tests/live/test_exp_files_download.py
python tests/live/test_exp_image.py
python tests/live/test_exp_download.py
python tests/live/test_exp_lock.py
python tests/live/test_exp_steps.py
python tests/live/test_exp_permissions.py
python tests/live/test_exp_templates.py

python tests/live/test_item_init.py
python tests/live/test_item_search.py
python tests/live/test_item_metadata.py
python tests/live/test_item_structured_metadata.py
python tests/live/test_item_field_link.py
python tests/live/test_item_link.py
python tests/live/test_item_category_status.py
python tests/live/test_item_tags.py
python tests/live/test_item_html.py
python tests/live/test_item_files_upload.py
python tests/live/test_item_files_download.py
python tests/live/test_item_image.py
python tests/live/test_item_download.py
python tests/live/test_item_lock.py
python tests/live/test_item_steps.py
python tests/live/test_item_permissions.py
python tests/live/test_item_templates.py

python tests/live/test_usergroups.py

python tests/live/test_sdk_compat.py   # 読むだけ。入っている elabapi_python が実物(6.0.x)で動くか

これらのスクリプトは実際の eLabFTW サーバーにアクセスし、Experiment / Resource item、metadata、タグ、リンク、添付ファイル、本文 HTML などを作成・更新・削除することがあります。

実行する前に、.env、experiment_id、item_id、template 名、category 名、status 名、Resource item 名、リンク先の Experiment 名、upload するファイルなどを実環境に合わせて確かめてください。検証用の team・template・Experiment・Resource item で実行してください。

ドキュメント ​

利用者向けのガイドは docs/ja/(日本語)と docs/en/(英語)にあります。目次は docs/README.md です。mkdocs.yml があるので、MkDocs を入れれば mkdocs serve でサイトとして見られます(ビルドの仕組みはリポジトリには入れていません)。

Apache License 2.0