-
Notifications
You must be signed in to change notification settings - Fork 632
Separate static analysis, move tests out of the package #1528
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -14,7 +14,7 @@ author-email = '[email protected], [email protected]' | |
|
||
[tool.pytest.ini_options] | ||
python_files = 'test_*.py' | ||
testpaths = 'scanpy/tests/' | ||
testpaths = 'tests/' | ||
xfail_strict = true | ||
markers = [ | ||
'internet: tests which rely on internet resources (enable with `--internet-tests`)', | ||
|
@@ -60,16 +60,4 @@ exclude = ''' | |
|palettes | ||
|_tools/(__init__|paga) | ||
) | ||
|tests/( | ||
test_get | ||
|test_neighbors | ||
|test_readwrite | ||
|test_clustering | ||
|test_preprocessing | ||
|test_rank_genes_groups | ||
|test_marker_gene_overlap | ||
|test_highly_variable_genes | ||
|test_rank_genes_groups_logreg | ||
|notebooks/(test_paga_paul15_subsampled|test_pbmc3k) | ||
) | ||
).py''' |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,140 @@ | ||
import sys | ||
from pathlib import Path | ||
|
||
import matplotlib as mpl | ||
import numpy as np | ||
from anndata import AnnData | ||
from scipy import sparse | ||
from anndata.tests.helpers import asarray, assert_equal | ||
|
||
mpl.use('agg') | ||
from matplotlib import pyplot | ||
from matplotlib.testing.compare import compare_images | ||
import pytest | ||
|
||
import scanpy | ||
|
||
scanpy.settings.verbosity = "hint" | ||
|
||
# define this after importing scanpy but before running tests | ||
IMPORTED = frozenset(sys.modules.keys()) | ||
|
||
|
||
@pytest.fixture | ||
def imported_modules(): | ||
return IMPORTED | ||
|
||
|
||
def make_comparer(path_expected: Path, path_actual: Path, *, tol: int): | ||
def save_and_compare(basename, tolerance=None): | ||
path_actual.mkdir(parents=True, exist_ok=True) | ||
out_path = path_actual / f'{basename}.png' | ||
pyplot.savefig(out_path, dpi=40) | ||
pyplot.close() | ||
if tolerance is None: | ||
tolerance = tol | ||
res = compare_images( | ||
str(path_expected / f'{basename}.png'), str(out_path), tolerance | ||
) | ||
assert res is None, res | ||
|
||
return save_and_compare | ||
|
||
|
||
@pytest.fixture | ||
def image_comparer(): | ||
return make_comparer | ||
|
||
|
||
@pytest.fixture | ||
def plt(): | ||
return pyplot | ||
|
||
|
||
@pytest.fixture( | ||
params=[sparse.csr_matrix, sparse.csc_matrix, asarray], | ||
ids=["scipy-csr", "scipy-csc", "np-ndarray"], | ||
) | ||
def array_type(request): | ||
"""Function which converts passed array to one of the common array types.""" | ||
return request.param | ||
|
||
|
||
@pytest.fixture(params=[np.float64, np.float32]) | ||
def float_dtype(request): | ||
return request.param | ||
|
||
|
||
########################### | ||
# Representation choice | ||
########################### | ||
# These functions can be used to check that functions are correctly using arugments | ||
# like `layers`, `obsm`, etc. | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def check_rep_mutation(): | ||
def check_rep_mutation(func, X, **kwargs): | ||
"""Check that only the array meant to be modified is modified.""" | ||
adata = AnnData( | ||
X=X.copy(), | ||
layers={"layer": X.copy()}, | ||
obsm={"obsm": X.copy()}, | ||
dtype=X.dtype, | ||
) | ||
adata_X = func(adata, copy=True, **kwargs) | ||
adata_layer = func(adata, layer="layer", copy=True, **kwargs) | ||
adata_obsm = func(adata, obsm="obsm", copy=True, **kwargs) | ||
|
||
assert np.array_equal(asarray(adata_X.X), asarray(adata_layer.layers["layer"])) | ||
assert np.array_equal(asarray(adata_X.X), asarray(adata_obsm.obsm["obsm"])) | ||
|
||
assert np.array_equal(asarray(adata_layer.X), asarray(adata_layer.obsm["obsm"])) | ||
assert np.array_equal( | ||
asarray(adata_obsm.X), asarray(adata_obsm.layers["layer"]) | ||
) | ||
assert np.array_equal( | ||
asarray(adata_X.layers["layer"]), asarray(adata_X.obsm["obsm"]) | ||
) | ||
|
||
return check_rep_mutation | ||
|
||
|
||
@pytest.fixture(scope='session') | ||
def check_rep_results(): | ||
def check_rep_results(func, X, **kwargs): | ||
"""Checks that the results of a computation add values/ | ||
mutate the anndata object in a consistent way. | ||
""" | ||
# Gen data | ||
adata_X = AnnData( | ||
X=X.copy(), | ||
layers={"layer": np.zeros(shape=X.shape, dtype=X.dtype)}, | ||
obsm={"obsm": np.zeros(shape=X.shape, dtype=X.dtype)}, | ||
) | ||
adata_layer = AnnData( | ||
X=np.zeros(shape=X.shape, dtype=X.dtype), | ||
layers={"layer": X.copy()}, | ||
obsm={"obsm": np.zeros(shape=X.shape, dtype=X.dtype)}, | ||
) | ||
adata_obsm = AnnData( | ||
X=np.zeros(shape=X.shape, dtype=X.dtype), | ||
layers={"layer": np.zeros(shape=X.shape, dtype=X.dtype)}, | ||
obsm={"obsm": X.copy()}, | ||
) | ||
|
||
# Apply function | ||
func(adata_X, **kwargs) | ||
func(adata_layer, layer="layer", **kwargs) | ||
func(adata_obsm, obsm="obsm", **kwargs) | ||
|
||
# Reset X | ||
adata_X.X = np.zeros(shape=X.shape, dtype=X.dtype) | ||
adata_layer.layers["layer"] = np.zeros(shape=X.shape, dtype=X.dtype) | ||
adata_obsm.obsm["obsm"] = np.zeros(shape=X.shape, dtype=X.dtype) | ||
|
||
# Check equality | ||
assert_equal(adata_X, adata_layer) | ||
assert_equal(adata_X, adata_obsm) | ||
|
||
return check_rep_results |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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.
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.
I'm not sure this should be a separate job. I would prefer we use the jobs we have for other operating systems. Azure allows us to have multiple checks within a job, so I'm not sure it's that useful to put static analysis in it's own build.
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.
that way it runs much faster, so people see earlier if they didn’t format things properly