8000 fix coveralls report and reference log generation for nexus test by lukaspie · Pull Request #631 · FAIRmat-NFDI/pynxtools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix coveralls report and reference log generation for nexus test #631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
8000
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,17 @@ jobs:
- name: Install nomad
if: "${{ matrix.python-version != '3.8' && matrix.python-version != '3.9'}}"
run: |
uv pip install nomad-lab[infrastructure]
# @git+https://gitlab.mpcdf.mpg.de/nomad-lab/nomad-FAIR.git
uv pip install nomad-lab[infrastructure]@git+https://gitlab.mpcdf.mpg.de/nomad-lab/nomad-FAIR.git
- name: Install pynx
run: |
uv pip install -e ".[dev]"
- name: Test with pytest
run: |
coverage run -m pytest -sv --show-capture=no tests -n auto --dist loadgroup
pytest --cov --cov-report xml:cobertura.xml --full-trace --show-capture=no -sv -n auto --dist loadgroup tests/
- name: Submit to coveralls
continue-on-error: true
if: "${{ matrix.python-version == '3.12'}}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
coveralls --service=github
if: ${{ matrix.python-version == '3.12' }}
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
file: ./cobertura.xml
57 changes: 57 additions & 0 deletions scripts/generate_ref_nexus_log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import os
import logging
import numpy as np

from pynxtools.nexus.nexus import HandleNexus

# Set up the logger for the test output
logger = logging.getLogger("pynxtools")


def generate_ref_log():
"""
Function to run the nexus test and generate the Ref_nexus_test.log file.
"""
dirpath = os.path.join(
os.path.dirname(os.path.abspath(__file__)), "../tests/data/nexus"
)
dirpath = os.path.abspath(dirpath)
example_data = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"../src/pynxtools/data/201805_WSe2_arpes.nxs",
)
example_data = os.path.abspath(example_data)

# Ensure the directory exists for the log file
if not os.path.exists(dirpath):
os.makedirs(dirpath)

# Set up logger to write directly to the reference log
logger.handlers.clear()
logger.setLevel(logging.DEBUG)
ref_log_path = os.path.join(dirpath, "Ref_nexus_test.log")
handler = logging.FileHandler(ref_log_path, "w", encoding="utf-8")
formatter = logging.Formatter("%(levelname)s - %(message)s")
handler.setLevel(logging.DEBUG)
handler.setFormatter(formatter)
logger.addHandler(handler)

# Set default print options for numpy (if needed)
default_print_options = {
"edgeitems": 3,
"threshold": 1000,
"precision": 8,
"linewidth": 75,
}

np.set_printoptions(**default_print_options)

# Run the actual processing with the nexus_helper
nexus_helper = HandleNexus(logger, example_data, None, None)
nexus_helper.process_nexus_master_file(None)

print(f"Reference log generated at {ref_log_path}")


if __name__ == "__main__":
generate_ref_log()
16 changes: 10 additions & 6 deletions tests/nexus/test_nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import lxml.etree as ET
import numpy as np
import pytest
import difflib

from pynxtools.definitions.dev_tools.utils.nxdl_utils import (
get_inherited_nodes,
Expand Down Expand Up @@ -159,7 +160,6 @@ def test_get_nexus_classes_units_attributes():
assert "NX_FLOAT" in nexus_attribute_list


@pytest.mark.xdist_group(name="shared_file_201805_WSe2_arpes")
def test_nexus(tmp_path):
"""
The nexus test function
Expand All @@ -177,6 +177,15 @@ def test_nexus(tmp_path):
handler.setFormatter(formatter)
logger.addHandler(handler)
nexus_helper = HandleNexus(logger, example_data, None, None)

default_print_options = {
"edgeitems": 3,
"threshold": 1000,
"precision": 8,
"linewidth": 75,
}

np.set_printoptions(**default_print_options)
nexus_helper.process_nexus_master_file(None)

with open(
Expand All @@ -203,11 +212,6 @@ def test_nexus(tmp_path):
f"Log output does not match reference even though each individual line matches."
)

# import filecmp
# # didn't work with filecmp library
# log = os.path.join(local_dir, '../data/nexus_test_data/nexus_test.log')
# ref = os.path.join(local_dir, '../data/nexus_test_data/Ref_nexus_test.log')


def test_get_node_at_nxdl_path():
"""Test to verify if we receive the right XML element for a given NXDL path"""
Expand Down
1 change: 0 additions & 1 deletion tests/nomad/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from pynxtools.nomad.utils import _rename_nx_for_nomad as rename_nx_for_nomad


@pytest.mark.xdist_group(name="shared_file_201805_WSe2_arpes")
def test_nexus_example():
archive = EntryArchive()

Expand Down
Loading
0