-
Notifications
You must be signed in to change notification settings - Fork 4
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
Update CLI functions to use new classes #55
Merged
+180
−76
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
57cc87a
Refactor shuffle_csv to use new classes
itrujnara e23f3ed
Add test for shuffle_csv
itrujnara ee64bcd
Fix minor issues in DatasetProcessor
itrujnara cf709d1
Auto fix formatting
itrujnara 045f805
Update DNA CSV files
itrujnara 1d2ad92
Refactor split_csv to work with new classes
itrujnara e58f52b
Create test_split_csv and snapshot
itrujnara 0f9b5aa
Auto formatting
itrujnara 01bef45
More auto formatting
itrujnara db67f83
Merge branch 'dev' of https://github.com/itrujnara/stimulus-py into dev
itrujnara f245fe1
Update import paths in CLI functions
itrujnara 7b6abe0
Fix linting in shuffle_csv and split_csv tests
itrujnara 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 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 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 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,4 @@ | ||
# serializer version: 1 | ||
# name: test_shuffle_csv[correct_csv_path-correct_yaml_path-None] | ||
'874d4fc87d68eb8972fea5667ecf6712' | ||
# --- |
This file contains 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,10 @@ | ||
# serializer version: 1 | ||
# name: test_split_csv[csv_path_no_split-yaml_path-False-None] | ||
'1181dc120be24ceb54a6026d18d5e87c' | ||
# --- | ||
# name: test_split_csv[csv_path_no_split-yaml_path-True-None] | ||
'1181dc120be24ceb54a6026d18d5e87c' | ||
# --- | ||
# name: test_split_csv[csv_path_with_split-yaml_path-True-None] | ||
'f5f903e92470dec26f00b25f92a017cd' | ||
# --- |
This file contains 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,51 @@ | ||
"""Tests for the shuffle_csv CLI command.""" | ||
|
||
import hashlib | ||
import pathlib | ||
import tempfile | ||
|
||
import pytest | ||
|
||
from src.stimulus.cli.shuffle_csv import main | ||
|
||
|
||
# Fixtures | ||
@pytest.fixture | ||
def correct_yaml_path() -> str: | ||
"""Fixture that returns the path to a correct YAML file.""" | ||
return "tests/test_data/titanic/titanic_sub_config.yaml" | ||
|
||
|
||
@pytest.fixture | ||
def correct_csv_path() -> str: | ||
"""Fixture that returns the path to a correct CSV file.""" | ||
return "tests/test_data/titanic/titanic_stimulus.csv" | ||
|
||
|
||
# Test cases | ||
test_cases = [ | ||
("correct_csv_path", "correct_yaml_path", None), | ||
] | ||
|
||
|
||
# Tests | ||
@pytest.mark.parametrize(("csv_type", "yaml_type", "error"), test_cases) | ||
def test_shuffle_csv( | ||
request: pytest.FixtureRequest, | ||
snapshot: pytest.fixture, | ||
csv_type: str, | ||
yaml_type: str, | ||
error: Exception | None, | ||
) -> None: | ||
"""Tests the CLI command with correct and wrong YAML files.""" | ||
csv_path = request.getfixturevalue(csv_type) | ||
yaml_path = request.getfixturevalue(yaml_type) | ||
tmpdir = pathlib.Path(tempfile.gettempdir()) | ||
if error: | ||
with pytest.raises(error): | ||
main(csv_path, yaml_path, tmpdir / "test.csv") | ||
else: | ||
assert main(csv_path, yaml_path, tmpdir / "test.csv") is None | ||
with open(tmpdir / "test.csv") as file: | ||
hash = hashlib.md5(file.read().encode()).hexdigest() # noqa: S324 | ||
assert hash == snapshot |
This file contains 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,63 @@ | ||
"""Tests for the split_csv CLI command.""" | ||
|
||
import hashlib | ||
import pathlib | ||
import tempfile | ||
|
||
import pytest | ||
|
||
from src.stimulus.cli.split_csv import main | ||
|
||
|
||
# Fixtures | ||
@pytest.fixture | ||
def csv_path_no_split() -> str: | ||
"""Fixture that returns the path to a CSV file without split column.""" | ||
return "tests/test_data/dna_experiment/test.csv" | ||
|
||
|
||
@pytest.fixture | ||
def csv_path_with_split() -> str: | ||
"""Fixture that returns the path to a CSV file with split column.""" | ||
return "tests/test_data/dna_experiment/test_with_split.csv" | ||
|
||
|
||
@pytest.fixture | ||
def yaml_path() -> str: | ||
"""Fixture that returns the path to a YAML config file.""" | ||
return "tests/test_data/dna_experiment/dna_experiment_config_template_0.yaml" | ||
|
||
|
||
# Test cases | ||
test_cases = [ | ||
("csv_path_no_split", "yaml_path", False, None), | ||
("csv_path_with_split", "yaml_path", False, ValueError), | ||
("csv_path_no_split", "yaml_path", True, None), | ||
("csv_path_with_split", "yaml_path", True, None), | ||
] | ||
|
||
|
||
# Tests | ||
@pytest.mark.skip(reason="There is an issue with non-deterministic output") | ||
@pytest.mark.parametrize(("csv_type", "yaml_type", "force", "error"), test_cases) | ||
def test_split_csv( | ||
request: pytest.FixtureRequest, | ||
snapshot: pytest.fixture, | ||
csv_type: str, | ||
yaml_type: str, | ||
force: bool, | ||
error: Exception | None, | ||
) -> None: | ||
"""Tests the CLI command with correct and wrong YAML files.""" | ||
csv_path = request.getfixturevalue(csv_type) | ||
yaml_path = request.getfixturevalue(yaml_type) | ||
tmpdir = pathlib.Path(tempfile.gettempdir()) | ||
if error: | ||
with pytest.raises(error): | ||
main(csv_path, yaml_path, tmpdir / "test.csv", force=force, seed=42) | ||
else: | ||
filename = f"{csv_type}_{force}.csv" | ||
assert main(csv_path, yaml_path, tmpdir / filename, force=force, seed=42) is None | ||
with open(tmpdir / filename) as file: | ||
hash = hashlib.md5(file.read().encode()).hexdigest() # noqa: S324 | ||
assert hash == snapshot |
This file contains 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
hello:input:dna,hola:label:float,pet:meta:str | ||
hello,hola,pet | ||
ACTGACTGATCGATGC,12,cat | ||
ACTGACTGATCGATGC,12,dog |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
csv has been renamed to data_handers to avoid shadowing csv python librairy