-
Notifications
You must be signed in to change notification settings - Fork 0
Improve tests and test workflow #14
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
Draft
RobLevv
wants to merge
8
commits into
main
Choose a base branch
from
improve-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f06a559
fix: use fixture to run automatically the server in tests
RobLevv 205ab12
feat: fix some workflows and add coverage
RobLevv d4ef965
fix dependency of test
RobLevv 86c9224
try coverage
RobLevv 903d788
add test_neck_instrument.py
eliot-christon baf3c32
test coverage
RobLevv 2f4a14f
fix
RobLevv 694274c
new test
RobLevv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| name: Tests and coverage on python | ||
|
|
||
| on: [push] | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Set up Python 3.12 | ||
| uses: actions/setup-python@v3 | ||
| with: | ||
| python-version: '3.12' | ||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install uv | ||
| uv sync | ||
| - name: Run tests | ||
| run: | | ||
| source .venv/bin/activate | ||
| pytest --cov=backend --cov-report=xml:coverage.xml | ||
| - name: Get Coverage | ||
| uses: orgoro/coverage@v3.2 | ||
| with: | ||
| coverageFile: coverage.xml | ||
| token: ${{ secrets.GITHUB_TOKEN }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| """This file contains the pytest fixture to run the server before tests. | ||
eliot-christon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| It ensures that the server is running before executing any tests that require it. | ||
| """ | ||
|
|
||
| import subprocess | ||
| import sys | ||
| import time | ||
| from collections.abc import Generator | ||
| from typing import Any | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session", autouse=True) | ||
| def run_server() -> Generator[Any, None, None]: | ||
| """Fixture to run the server before tests.""" | ||
| with subprocess.Popen([sys.executable, "main.py", "--quiet"]) as proc: | ||
| time.sleep(2) | ||
| yield | ||
| proc.terminate() | ||
| proc.wait() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| """ | ||
| This is the test file for the neck instrument module. | ||
| It tests the functionality of the NeckInstrument class and its methods. | ||
| """ | ||
|
|
||
| from backend.src.instruments.neck_instrument import NeckInstrument | ||
| from backend.src.positions.neck_position import NeckPosition | ||
| from backend.src.utils.note2num import note2num | ||
|
|
||
| untuned_strings = ["E2", "A2", "D3", "G3", "B3", "F4"] | ||
| untuned_guitar = NeckInstrument( | ||
| name="Test Untuned Guitar", | ||
| open_strings=untuned_strings, | ||
| number_of_frets=14, | ||
| ) | ||
| notes = [note2num(note) for note in ["C4", "E4", "G4"]] | ||
| possible_positions = untuned_guitar.possible_positions(notes) | ||
|
|
||
|
|
||
| def test_neck_instrument_initialization() -> None: | ||
| """Test the initialization of a NeckInstrument object.""" | ||
| assert untuned_guitar.name == "Test Untuned Guitar" | ||
| assert untuned_guitar.open_strings == [note2num(s) for s in untuned_strings] | ||
| assert untuned_guitar.number_of_frets == 14 | ||
|
|
||
|
|
||
| def test_neck_instrument_possible_positions() -> None: | ||
| """Test the possible positions method of NeckInstrument.""" | ||
| assert isinstance(possible_positions, list) | ||
| assert all(isinstance(pos, NeckPosition) for pos in possible_positions) | ||
| assert len(possible_positions) > 0 | ||
| assert possible_positions[0].fingers != [0, 0, 0] | ||
| # assert placements are 3 digits numbers | ||
| assert all(len(str(placement)) == 3 for placement in possible_positions[0].placements) | ||
|
|
||
|
|
||
| def test_neck_instrument_is_valid_position() -> None: | ||
| """Test the is_valid_position method of NeckInstrument.""" | ||
| valid_positions = [pos for pos in possible_positions if untuned_guitar.is_valid_position(pos)] | ||
| assert len(valid_positions) <= len(possible_positions) | ||
| # valid positions must have different strings | ||
| assert all(len(set(pos.strings)) == len(pos.strings) for pos in valid_positions) | ||
|
|
||
|
|
||
| def test_neck_instrument_position_cost() -> None: | ||
| """Test the position_cost method of NeckInstrument.""" | ||
| position = possible_positions[0] | ||
| cost = untuned_guitar.position_cost(position) | ||
| assert isinstance(cost, int) | ||
| assert cost >= 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.