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

feat/testing: add tests to ensure that code works as intended #27

Merged
merged 6 commits into from
Apr 24, 2024

Conversation

mlederbauer
Copy link
Owner

TLDR: What does this mean for developing this code? Nothing really, you get a checkmark that tells you whether the tests "passed" or not. This so-called unit testing is standard practice to check whether the code works as intended, and is not broken at any stage of coding. When adding a new feature, it would be good to add tests in the directory tests/ - but it shouldn't be a priority right now. Mainly, I've been experimenting with github workflows and this is a first attempt :)


This pull request introduces several changes aimed at improving the quality and reliability of the NMRcraft codebase. Specifically, it adds a suite of unit tests and a continuous integration (CI) workflow that runs these tests automatically whenever code is pushed to the main branch or a pull request is opened against it.

Unit Tests
The new unit tests are located in the tests/ directory. These tests cover the load_model function in nmrcraft/models/models.py, ensuring that it correctly loads the supported models and raises an error when an unsupported model or keyword argument is provided.

Here's an example of one of the new tests:

def test_load_model_unsupported_model():
    with pytest.raises(ValueError):
        load_model("unsupported_model")

This test asserts that a ValueError is raised when we try to load a model named "unsupported_model", which is not supported by the load_model function.

Continuous Integration Workflow
Continuous Integration Workflow
The new CI workflow is defined in .github/workflows/tests.yml. This workflow runs on Ubuntu and performs the following steps:

  1. Checks out the code.
  2. Sets up Python 3.11.
  3. Installs the project's dependencies using Poetry.
  4. Runs the unit tests using the make test command.

Here's an excerpt from the workflow file:

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: "3.8"
      - name: Install dependencies
        run: |
          pip install poetry
          poetry install
      - name: Run tests
        run: make test

With these changes, we can ensure that all tests pass before any code is merged into the main branch, helping to prevent bugs and regressions.

Please review these changes and let me know if you have any questions or feedback.

@mlederbauer
Copy link
Owner Author

The consequence of this feature is what you see next to commits:
image

The green checkmark tells us that all tests have passed. If they haven't, a red X pops up!

Tiago Würthner added 2 commits April 23, 2024 14:51
Switch the Test OS as the one we use for the Docker is also arch, so
this should increase compatibility of the code with the test. (Very
unlikely that there would have been any problems on Ubuntu, but worth
fixing up).
This reverts accidental commit 9f1eb55.
@tiaguinho-code
Copy link
Collaborator

Looks good so far! In the future I will try to make this run on archlinux, like the docker so we have maximum compatibility between the docker and the testing environment.

@mlederbauer
Copy link
Owner Author

thanks @tiaguinho-code !

@mlederbauer
Copy link
Owner Author

is there a reason for reverting the changes, did it not pass the tests ?

@tiaguinho-code
Copy link
Collaborator

is there a reason for reverting the changes, did it not pass the tests ?

If I see correctly I reverted my own accidental push, where I tried to configure the testing os. If I reverted any of your commits that must have been a mistake.

@mlederbauer
Copy link
Owner Author

No I meant your commit, but no worries! You can perhaps check if something you want to push passes make test, then it should be alright to go to push to GitHub. Feel free to overwrite ubuntu with arch if that is what you planned!

@tiaguinho-code
Copy link
Collaborator

Yeah, will do. I reverted my commit because I was just messing around a bit and the test got stuck, so I guess I must have broken it lol

@tiaguinho-code tiaguinho-code self-requested a review April 23, 2024 21:08
@kbiniek kbiniek self-requested a review April 24, 2024 05:26
@kbiniek
Copy link
Collaborator

kbiniek commented Apr 24, 2024

Looks great to me! Thank you @mlederbauer for implementing the tests and pipeline! I approved the changes and imo we can already merge it if thats alright with you @tiaguinho-code since we have working tests and the switch to arch is not urgent rn

@mlederbauer
Copy link
Owner Author

mlederbauer commented Apr 24, 2024

thx guys! @tiaguinho-code @kbiniek

@mlederbauer mlederbauer merged commit 4a8ef01 into main Apr 24, 2024
1 check passed
@mlederbauer mlederbauer deleted the feat/testing branch April 24, 2024 06:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants