Skip to content

Commit

Permalink
adapt python sdk tests to new version
Browse files Browse the repository at this point in the history
  • Loading branch information
mfleisch committed Dec 21, 2024
1 parent 5f3c323 commit a64d0e5
Show file tree
Hide file tree
Showing 7 changed files with 8,053 additions and 66 deletions.
7,993 changes: 7,992 additions & 1 deletion .updater/api/api-docs-enums.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion .updater/api/api-docs.json

This file was deleted.

4 changes: 2 additions & 2 deletions .updater/clientTests/PythonTests/test/test_compounds_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import unittest

import PySirius
from PySirius import PySiriusAPI, SiriusSDK
from PySirius import PySiriusAPI, SiriusSDK, PagedModelCompound
from PySirius.models.compound import Compound
from PySirius.models.trace_set import TraceSet
from PySirius.models.page_compound import PageCompound
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_get_compounds_paged(self) -> None:
Page of available compounds (group of ion identities) in the given project-space.
"""
response = self.api.compounds().get_compounds_paged(self.project_id)
self.assertIsInstance(response, PageCompound)
self.assertIsInstance(response, PagedModelCompound)

def test_get_traces(self) -> None:
"""Test case for get_traces
Expand Down
90 changes: 40 additions & 50 deletions .updater/clientTests/PythonTests/test/test_features_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,23 @@
""" # noqa: E501

import os
import json
import unittest

import PySirius
from PySirius import PySiriusAPI, SiriusSDK
from PySirius.models.ms_data import MsData
from PySirius.models.feature_import import FeatureImport
from PySirius import SiriusSDK, PagedModelAlignedFeature, PagedModelStructureCandidateScored, \
PagedModelStructureCandidateFormula, PagedModelFormulaCandidate, QuantificationTableExperimental, \
PagedModelSpectralLibraryMatch, TraceSetExperimental
from PySirius.models.aligned_feature import AlignedFeature
from PySirius.models.aligned_feature_quality import AlignedFeatureQuality
from PySirius.models.compound_classes import CompoundClasses
from PySirius.models.quantification_table import QuantificationTable
from PySirius.models.canopus_prediction import CanopusPrediction
from PySirius.models.annotated_ms_ms_data import AnnotatedMsMsData
from PySirius.models.page_aligned_feature import PageAlignedFeature
from PySirius.models.annotated_spectrum import AnnotatedSpectrum
from PySirius.models.canopus_prediction import CanopusPrediction
from PySirius.models.compound_classes import CompoundClasses
from PySirius.models.formula_candidate import FormulaCandidate
from PySirius.models.page_formula_candidate import PageFormulaCandidate
from PySirius.models.fragmentation_tree import FragmentationTree
from PySirius.models.isotope_pattern_annotation import IsotopePatternAnnotation
from PySirius.models.lipid_annotation import LipidAnnotation
# from PySirius.models.spectral_library_match import SpectralLibraryMatch
from PySirius.models.page_spectral_library_match import PageSpectralLibraryMatch
from PySirius.models.spectral_library_match_summary import SpectralLibraryMatchSummary
from PySirius.models.structure_candidate_formula import StructureCandidateFormula
from PySirius.models.structure_candidate_scored import StructureCandidateScored
from PySirius.models.page_structure_candidate_formula import PageStructureCandidateFormula
from PySirius.models.page_structure_candidate_scored import PageStructureCandidateScored
from PySirius.models.trace_set import TraceSet


class TestFeaturesApi(unittest.TestCase):
Expand All @@ -49,7 +38,9 @@ def setUp(self) -> None:
self.api = SiriusSDK().attach_or_start_sirius()
self.project_id = "test_features_api"
self.path_to_project = f"{os.environ.get('HOME')}/tomato_small.sirius"
self.api.projects().open_project_space(self.project_id, self.path_to_project)
# check if test project already open -> allows to run tests in independent calls.
if self.api.projects().get_project_space_without_preload_content(self.project_id).status == 404:
self.api.projects().open_project_space(self.project_id, self.path_to_project)
# the single one ID with MSNovelist results computed
self.aligned_feature_id = "586487307819356741"

Expand Down Expand Up @@ -103,32 +94,31 @@ def test_delete_aligned_feature(self) -> None:
Delete feature (aligned over runs) with the given identifier from the specified project-space.
"""
path_to_demo_data = f"{os.environ.get('HOME')}/sirius-client-openAPI/.updater/clientTests/Data"
preproc_ms2_file_1 = path_to_demo_data + "/Kaempferol.ms"
preproc_ms2_file_2 = path_to_demo_data + "/laudanosine.mgf"
input_files = [preproc_ms2_file_1, preproc_ms2_file_2]
import_result = self.api.projects().import_preprocessed_data(self.project_id, input_files=input_files)
feature_ids = import_result.affected_aligned_feature_ids

response_before = self.api.features().get_aligned_features(self.project_id)
self.api.features().delete_aligned_feature(self.project_id, feature_ids[0])
self.api.features().delete_aligned_feature(self.project_id, feature_ids[1])
response_after = self.api.features().get_aligned_features(self.project_id)
project_info = self.api.projects().create_project_space(project_id="delete-project")
project_id = project_info.project_id
try:
path_to_demo_data = f"{os.environ.get('HOME')}/sirius-client-openAPI/.updater/clientTests/Data"
preproc_ms2_file_1 = path_to_demo_data + "/Kaempferol.ms"
preproc_ms2_file_2 = path_to_demo_data + "/laudanosine.mgf"
input_files = [preproc_ms2_file_1, preproc_ms2_file_2]
import_result = self.api.projects().import_preprocessed_data(project_id, input_files=input_files)
feature_ids = import_result.affected_aligned_feature_ids

self.assertIsInstance(response_before, list)
self.assertIsInstance(response_before[0], AlignedFeature)
response_before = self.api.features().get_aligned_features(project_id)
self.api.features().delete_aligned_feature(project_id, feature_ids[0])
self.api.features().delete_aligned_feature(project_id, feature_ids[1])
response_after = self.api.features().get_aligned_features(project_id)

self.assertIsInstance(response_after, list)
self.assertIsInstance(response_after[0], AlignedFeature)
self.assertIsInstance(response_before, list)
self.assertIsInstance(response_before[0], AlignedFeature)

self.assertEqual(len(response_before) - len(response_after), 2)
self.assertIsInstance(response_after, list)
self.assertEqual(len(response_after), 0)

def test_delete_aligned_features(self) -> None:
"""Test case for delete_aligned_features
Delete feature (aligned over runs) with the given identifier from the specified project-space.
"""
pass
self.assertEqual(len(response_before) - len(response_after), 2)
finally:
self.api.projects().close_project_space(project_id)
os.remove(project_info.location)

def test_get_aligned_feature(self) -> None:
"""Test case for get_aligned_feature
Expand All @@ -153,7 +143,7 @@ def test_get_aligned_features_paged(self) -> None:
Get all available features (aligned over runs) in the given project-space.
"""
response = self.api.features().get_aligned_features_paged(self.project_id)
self.assertIsInstance(response, PageAlignedFeature)
self.assertIsInstance(response, PagedModelAlignedFeature)

def test_get_best_matching_compound_classes(self) -> None:
"""Test case for get_best_matching_compound_classes
Expand Down Expand Up @@ -200,15 +190,15 @@ def test_get_de_novo_structure_candidates_by_formula_paged(self) -> None:
response = self.api.features().get_de_novo_structure_candidates_by_formula_paged(self.project_id,
self.aligned_feature_id,
self.formula_id)
self.assertIsInstance(response, PageStructureCandidateScored)
self.assertIsInstance(response, PagedModelStructureCandidateScored)

def test_get_de_novo_structure_candidates_paged(self) -> None:
"""Test case for get_de_novo_structure_candidates_paged
Page of de novo structure candidates (e.g. generated by MsNovelist) ranked by CSI:FingerID score for the given 'alignedFeatureId' with minimal information. StructureCandidates can be enriched with molecular fingerprint.
"""
response = self.api.features().get_de_novo_structure_candidates_paged(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, PageStructureCandidateFormula)
self.assertIsInstance(response, PagedModelStructureCandidateFormula)

def test_get_fingerprint_prediction(self) -> None:
"""Test case for get_fingerprint_prediction
Expand Down Expand Up @@ -259,7 +249,7 @@ def test_get_formula_candidates_paged(self) -> None:
Page of FormulaResultContainers available for this feature with minimal information.
"""
response = self.api.features().get_formula_candidates_paged(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, PageFormulaCandidate)
self.assertIsInstance(response, PagedModelFormulaCandidate)

def test_get_frag_tree(self) -> None:
"""Test case for get_frag_tree
Expand Down Expand Up @@ -301,8 +291,8 @@ def test_get_quantification(self) -> None:
"""Test case for get_quantification
"""
response = self.api.features().get_quantification(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, QuantificationTable)
response = self.api.features().get_quantification_experimental(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, QuantificationTableExperimental)

def test_get_spectral_library_match(self) -> None:
"""Test case for get_spectral_library_match
Expand All @@ -326,7 +316,7 @@ def test_get_spectral_library_matches_paged(self) -> None:
Page of spectral library matches for the given 'alignedFeatureId'.
"""
response = self.api.features().get_spectral_library_matches_paged(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, PageSpectralLibraryMatch)
self.assertIsInstance(response, PagedModelSpectralLibraryMatch)

def test_get_spectral_library_matches_summary(self) -> None:
"""Test case for get_spectral_library_matches_summary
Expand Down Expand Up @@ -377,22 +367,22 @@ def test_get_structure_candidates_by_formula_paged(self) -> None:
response = self.api.features().get_structure_candidates_by_formula_paged(self.project_id,
self.aligned_feature_id,
self.formula_id)
self.assertIsInstance(response, PageStructureCandidateScored)
self.assertIsInstance(response, PagedModelStructureCandidateScored)

def test_get_structure_candidates_paged(self) -> None:
"""Test case for get_structure_candidates_paged
Page of structure database search candidates ranked by CSI:FingerID score for the given 'alignedFeatureId' with minimal information.
"""
response = self.api.features().get_structure_candidates_paged(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, PageStructureCandidateFormula)
self.assertIsInstance(response, PagedModelStructureCandidateFormula)

def test_get_traces1(self) -> None:
"""Test case for get_traces1
"""
response = self.api.features().get_traces1(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, TraceSet)
response = self.api.features().get_traces_experimental(self.project_id, self.aligned_feature_id)
self.assertIsInstance(response, TraceSetExperimental)


if __name__ == '__main__':
Expand Down
9 changes: 6 additions & 3 deletions .updater/clientTests/PythonTests/test/test_jobs_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import PySirius
from PySirius import PySiriusAPI, SiriusSDK
from PySirius.models.job import Job
from PySirius.models.page_job import PageJob
from PySirius.models.paged_model_job import PagedModelJob
from PySirius.models.job_submission import JobSubmission


Expand All @@ -31,7 +31,10 @@ def setUp(self) -> None:
self.api = SiriusSDK().attach_or_start_sirius()
self.project_id = "test_jobs_api"
self.path_to_project = f"{os.environ.get('HOME')}/test_jobs_api.sirius"
self.api.projects().create_project_space(self.project_id, self.path_to_project)
if self.api.projects().get_project_space_without_preload_content(self.project_id).status == 404:
if os.path.exists(self.path_to_project):
os.remove(self.path_to_project)
self.api.projects().create_project_space(self.project_id, self.path_to_project)

path_to_demo_data = f"{os.environ.get('HOME')}/sirius-client-openAPI/.updater/clientTests/Data"
preproc_ms2_file_1 = path_to_demo_data + "/Kaempferol.ms"
Expand Down Expand Up @@ -157,7 +160,7 @@ def test_get_jobs_paged(self) -> None:
Get Page of jobs with information such as current state and progress (if available).
"""
response = self.api.jobs().get_jobs_paged(self.project_id)
self.assertIsInstance(response, PageJob)
self.assertIsInstance(response, PagedModelJob)

def test_has_jobs(self) -> None:
"""Test case for has_jobs
Expand Down
20 changes: 12 additions & 8 deletions .updater/clientTests/PythonTests/test/test_projects_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import os
import unittest

from PySirius import SiriusSDK
from PySirius.api.projects_api import ProjectsApi
from PySirius import SiriusSDK, JobOptField
from PySirius.models.job import Job
from PySirius.models.project_info import ProjectInfo
from PySirius.models.import_result import ImportResult
Expand All @@ -26,7 +25,8 @@ class TestProjectsApi(unittest.TestCase):
"""ProjectsApi unit test stubs"""

def setUp(self) -> None:
self.projects = SiriusSDK().attach_or_start_sirius().projects()
self.api = SiriusSDK().attach_or_start_sirius()
self.projects = self.api.projects()
path_to_demo_data = f"{os.environ.get('HOME')}/sirius-client-openAPI/.updater/clientTests/Data"
self.preproc_ms2_file_1 = path_to_demo_data + "/Kaempferol.ms"
self.preproc_ms2_file_2 = path_to_demo_data + "/laudanosine.mgf"
Expand All @@ -35,7 +35,11 @@ def setUp(self) -> None:
# equals test_create_project_space
self.project_id = "test_projects_api"
self.path_to_project = f"{os.environ.get('HOME')}/test_projects_api.sirius"
self.create_response = self.projects.create_project_space(self.project_id, self.path_to_project)

if self.api.projects().get_project_space_without_preload_content(self.project_id).status == 404:
if os.path.exists(self.path_to_project):
os.remove(self.path_to_project)
self.create_response = self.projects.create_project_space(self.project_id, self.path_to_project)

def tearDown(self) -> None:
# equals test_close_project_space
Expand Down Expand Up @@ -103,8 +107,8 @@ def test_import_ms_run_data(self) -> None:
Import and Align full MS-Runs from various formats into the specified project Possible formats (mzML, mzXML)
"""
input_files = [self.full_ms_file]
parameters = LcmsSubmissionParameters()
response = self.projects.import_ms_run_data(self.project_id, parameters, input_files=input_files)
parameters = LcmsSubmissionParameters(align_lcms_runs=False)
response = self.projects.import_ms_run_data(project_id=self.project_id, parameters=parameters, input_files=input_files)
self.assertIsInstance(response, ImportResult)

def test_import_ms_run_data_as_job(self) -> None:
Expand All @@ -113,8 +117,8 @@ def test_import_ms_run_data_as_job(self) -> None:
Import and Align full MS-Runs from various formats into the specified project as background job.
"""
input_files = [self.full_ms_file]
parameters = LcmsSubmissionParameters()
response = self.projects.import_ms_run_data_as_job(self.project_id, parameters, input_files=input_files)
parameters = LcmsSubmissionParameters(align_lcms_runs=False)
response = self.projects.import_ms_run_data_as_job(project_id=self.project_id, parameters=parameters, input_files=input_files)
self.assertIsInstance(response, Job)

def test_import_preprocessed_data(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_import_into_database(self) -> None:
Start import of structure and spectra files into the specified database.
"""
response = self.dbs.import_into_database(self.database_id, input_files=[self.test_file])
response = self.dbs.import_into_database_e(self.database_id, input_files=[self.test_file])
self.assertIsInstance(response, SearchableDatabase)

def test_remove_database(self) -> None:
Expand Down

0 comments on commit a64d0e5

Please sign in to comment.