Skip to content

Commit

Permalink
Merge pull request #67 from AngelFP/add_tests
Browse files Browse the repository at this point in the history
Add basic tests
  • Loading branch information
AngelFP authored Mar 8, 2024
2 parents 78294c3 + 15692d6 commit 24dc7d6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,30 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.7, 3.8, 3.9, '3.10', 3.11]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[test]"
- name: Download test data
run: |
git clone https://github.com/openPMD/openPMD-example-datasets.git ./tests/test_data/
cd ./tests/test_data
tar -zxvf example-2d.tar.gz
tar -zxvf example-3d.tar.gz
tar -zxvf example-thetaMode.tar.gz
- name: Lint with flake8
run: |
flake8 --extend-ignore=E722 --exclude QVTKRenderWindowInteractor.py ./visualpic
- shell: bash -l {0}
name: Run unit tests
run: |
cd tests
python -m pytest .
30 changes: 30 additions & 0 deletions tests/test_data_container.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from visualpic import DataContainer


def test_data_container():
"""Test basic functionality of the DataContainer using sample data."""
data_path = "./test_data/example-3d/hdf5"
diags = DataContainer("openpmd", data_path)
diags.load_data()
available_fields = diags.get_list_of_fields()
available_species = diags.get_list_of_species()
assert available_fields == ["Ex", "Ey", "Ez", "rho", "I", "A", "a"]
assert available_species == ["electrons"]
assert diags.get_list_of_species(required_data=["x"]) == ["electrons"]
assert diags.get_list_of_species(required_data=["magic"]) == []
for f_name in available_fields:
field = diags.get_field(f_name)
assert field.get_geometry() == "3dcartesian"
its = field.timesteps
for it in its:
fld_data, md = field.get_data(time_step=it)
for sp in available_species:
species = diags.get_species(sp)
for it in species.timesteps:
comps = species.get_list_of_available_components()
assert comps == ["q", "m", "x", "y", "z", "px", "py", "pz", "w", "x_prime"]
sp_data = species.get_data(it)


if __name__ == "__main__":
test_data_container()

0 comments on commit 24dc7d6

Please sign in to comment.