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

Pytests creator #8

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Pytests creator #8

wants to merge 17 commits into from

Conversation

Desk3505
Copy link
Contributor

@Desk3505 Desk3505 commented Feb 3, 2025

creation of basic pytest files and minor changes to utils,filter, optimization_loop

Copy link
Contributor

@karanphil karanphil left a comment

Choose a reason for hiding this comment

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

Good job! Here are a few comments to start with.

  1. Make sure your code fulfills the pep8 requirements. You can pip install flake8 and run it on your code. There are a few lines that are too long and spaces missing. (come and see me for help)
  2. Find a way to remove hardcoded paths from the code. As I said in the comment, go see how we do in scilpy.
  3. I think we should follow the same structure as scilpy. Thus, instead of a pytest directory, you could ad a tests directory in each module and put the tests there. Go see how we organize it in scilpy. It is very similar to what you did but structured a bit differently.

Don't hesitate if you have questions!

@pytest.mark.parametrize("graph, node_indices, expected", test_data)
def test_remove_orphan_nodes(graph, node_indices, expected):

out_graph,out_ind = remove_orphan_nodes(graph, node_indices)
Copy link
Contributor

Choose a reason for hiding this comment

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

Always put an empty space after a comma.


@pytest.mark.parametrize("graph, node_indices, expected", test_KEEP)
def test_remove_orphan_nodes_KEEP(graph, node_indices, expected):
out_graph,out_ind = remove_orphan_nodes(graph, node_indices, keep_indices=np.array([2]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing here for the comma.


out_graph = remove_intermediate_connections(graph)
assert np.array_equal(out_graph, expected)
assert np.array_equal(remove_intermediate_connections(graph,node_indices,keep_indices=[1]),graph)
Copy link
Contributor

Choose a reason for hiding this comment

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

And here (comma).



test_data = [
(nib.load('/home/kevin-da/LibrairiesQuack/Quackto/quactography/data/simplePhantoms/fanning_2d_3bundles/wm_vf.nii.gz'),
Copy link
Contributor

Choose a reason for hiding this comment

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

This hardcoded path will not work on someone else's computer. You can do something like we do in scilpy. For instance, the scilpy_bot uses a file in data. Go see scil_search_keywords.py and scilpy_bot.py from scilpy.utils.

@Desk3505 Desk3505 requested a review from karanphil February 3, 2025 23:23
Copy link
Contributor

@karanphil karanphil left a comment

Choose a reason for hiding this comment

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

Good job on the modules tests. I think they are GTG. For the scripts tests, please refer to how we do in scilpy. After that I think it will be good to go!



def test_quac_mat_adj_build():
script_path = str_path + "/scripts/quac_matrix_adj_build.py"
Copy link
Contributor

Choose a reason for hiding this comment

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

We should follow the same method as Scilpy for testing the scripts. You can refer to any scilpy script test (here is an example: https://github.com/scilus/scilpy/blob/master/scripts/tests/test_aodf_metrics.py). If you pip install -e . the repo, you should have the scripts in your path and be able to use lines like ret = script_runner.run('scil_aodf_metrics.py', '--help').


def test_quac_rndmat_adj_build():
script_path = os.path.abspath(
"/home/kevin-da/LibrairiesQuack/Quackto/quactography/scripts/quac_randmatrix_adj_build.py"
Copy link
Contributor

Choose a reason for hiding this comment

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

You forgot a hardcoded path here and below.

@Desk3505 Desk3505 requested a review from karanphil February 6, 2025 20:28
Copy link
Contributor

@karanphil karanphil left a comment

Choose a reason for hiding this comment

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

Good job, you are getting there! Here are a few other comments.

@@ -8,26 +8,20 @@
str_path = str(DIR_PATH)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this line and apply the str() directly in line 6.

assert result.returncode == 0
assert os.path.exists(output_file)
data = np.load(output_file)
print(data.files)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove print

@@ -0,0 +1,69 @@
import os
import numpy as np

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove one blank line here.


str_path = str(DIR_PATH)


Copy link
Contributor

Choose a reason for hiding this comment

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

Add a test for the help, like you did for the other script.

assert result.returncode == 0
assert os.path.exists(output_file)
data = np.load(output_file)
print(data.files)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove print

assert result.returncode == 0
assert os.path.exists(output_file)
data = np.load(output_file)
print(data.files)
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove print

def test_quac_mat_adj_build(script_runner):
wm_path = str_path + "/data/simplePhantoms/fanning_2d_5bundles/wm_vf.nii.gz"
fods_path = str_path + "/data/simplePhantoms/fanning_2d_5bundles/fods.nii.gz"
output_file = "test_output_graph.npz"
Copy link
Contributor

Choose a reason for hiding this comment

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

If the output file is always the same for every test, I think you could move this line outside the functions, with DIR_PATH.

@Desk3505 Desk3505 requested a review from karanphil February 7, 2025 18:38
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