Skip to content
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

Restructure tests #152

Merged
merged 5 commits into from
Jan 7, 2025
Merged

Restructure tests #152

merged 5 commits into from
Jan 7, 2025

Conversation

ka-sarthak
Copy link
Collaborator

@ka-sarthak ka-sarthak commented Jan 7, 2025

As we will have more types of measurement schemas added (upcoming PPMS, transmission), it's nicer to have some common fixtures for testing to avoid code duplication.

Parsing a measurement file is one common step. This PR moves the parsing fixture into conftest.py. Along with caplog, this fixture can be used while testing different measurements.

Also, we should have individual folders to contain tests for each measurement technique.

tests
├── conftest.py
├── test_first_utils.py
├── data
│   ├── ppms
│   ├── transmission
│   └── xrd
├── ppms
│   └── test_parser.py
├── transmission
│   └── test_parser.py
└── xrd
    └── test_parser.py

@hampusnasstrom @aalbino2 What are your thoughts?

Summary by Sourcery

Tests:

  • Introduce a common fixture for parsing measurement files and create separate test folders for each measurement technique (XRD, PPMS, transmission).

@ka-sarthak ka-sarthak self-assigned this Jan 7, 2025
Copy link

sourcery-ai bot commented Jan 7, 2025

Reviewer's Guide by Sourcery

This PR restructures the tests by moving the parsing fixture into conftest.py and creating individual folders for each measurement technique.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Moved parsing fixture to conftest.py to avoid code duplication and enable reuse across different measurement types.
  • Created a new fixture parsed_measurement_archive in conftest.py. This fixture parses a measurement file and returns an EntryArchive object.
  • The fixture takes a file path as a parameter and handles parsing the .archive.json file.
  • The fixture also cleans up the generated .archive.json file after the test is complete.
  • Added imports for necessary modules like os, pytest, and parsing utilities.
tests/conftest.py
Created individual test folders for each measurement technique.
  • Created a new folder xrd under tests.
  • Added test_parser.py within the xrd folder. This file contains tests specific to XRD measurements.
  • The tests in test_parser.py utilize the parsed_measurement_archive and caplog fixtures.
  • Tests cover various XRD data files and log levels.
  • Added imports for necessary modules like pytest, normalize_all, and test data files.
tests/xrd/test_parser.py
Removed the old test file.
  • Deleted the old test_parser.py file at the root level of the tests directory.
tests/test_parser.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ka-sarthak - I've reviewed your changes - here's some feedback:

Overall Comments:

  • There's a typo in the parsed_measurement_archive fixture docstring: 'yeilded' should be 'yielded'
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

tests/xrd/test_parser.py Outdated Show resolved Hide resolved
tests/conftest.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@hampusnasstrom hampusnasstrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure we need to nest the tests in folders rather than just having test_xrd.py etc. but looks good!

@ka-sarthak
Copy link
Collaborator Author

So rather have one file for each technique, which contains all related tests. I like that too.

@ka-sarthak
Copy link
Collaborator Author

@JonathanNoky This might be interesting for you. I renamed test_ppms_parser.py to test_ppms.py. You can also try using/inheriting the parsed_measurement_archive fixture in your tests to avoid some code duplication.

@ka-sarthak ka-sarthak merged commit 617fb72 into main Jan 7, 2025
5 checks passed
@ka-sarthak ka-sarthak deleted the restructure-tests branch January 7, 2025 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants