Skip to content

Externally Executable Tool Tests 2 (with better API)#5628

Merged
mvdbeek merged 21 commits intogalaxyproject:devfrom
jmchilton:external_tool_tests_better_api
Mar 7, 2018
Merged

Externally Executable Tool Tests 2 (with better API)#5628
mvdbeek merged 21 commits intogalaxyproject:devfrom
jmchilton:external_tool_tests_better_api

Conversation

@jmchilton
Copy link
Copy Markdown
Member

This is the same as #5545 but with the addition of 3513930. This added commit significantly improves the quality of the JSON exported from Galaxy API to describe tool tests (and by extension cleans up the internals of Galaxy's test parsing as well).

Comment thread lib/galaxy/tools/__init__.py Outdated
repository_dir = self._repository_dir
if repository_dir:
for root, dirs, files in os.walk(repository_dir):
if '.' in dirs:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if '.hg' in dirs:

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Huh - this was copied and pasted but doesn't make a lot of sense.

-        for root, dirs, files in os.walk(os.path.join(tool_path, installed_tool_path)):
-            if '.' in dirs:
-                dirs.remove('.hg')

I think you must be correct about the original intent. I'll update with that fix.

@jmchilton jmchilton force-pushed the external_tool_tests_better_api branch from 8b963eb to c60a520 Compare March 1, 2018 17:40
Comment thread lib/galaxy/tools/verify/interactor.py Outdated
slept = 0
walltime_exceeded = kwd.get("maxseconds", None)
if walltime_exceeded is None:
walltime_exceeded = DEFAULT_TOOL_TEST_WAIT
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we replace the previous 3 lines with:

        walltime_exceeded = kwd.get("maxseconds", DEFAULT_TOOL_TEST_WAIT)

?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I can do this but I need to make sure ToolTestDescription doesn't allow None as a value for this. I'll make that change.

Comment thread lib/galaxy/tools/verify/interactor.py Outdated
sleep_amount *= 2
else:
exceeded = False
break
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you change break to return, you can get rid of exceeded.

Comment thread lib/galaxy/tools/test.py
"test_index": test_index,
"inputs": {},
"error": True,
"exception": str(e),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not directly save the e object? That would simplify lines 710-713 in lib/galaxy/tools/verify/interactor.py

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It was an object before but the result is JSONified and sent over the wire now - at least through certain paths of the code. This needs to be a str here - if you want I can simplify the other lines to always assume it is a string - I'm not sure if the object path through the code is still valid.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AFAIU, it seems ToolTestDescription.to_dict() does not process the exception attribute.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch - but that is bug it really needs to I think or there is not reason to record it. I'll fix that.

Comment thread test/base/driver_util.py Outdated
@@ -476,19 +475,6 @@ def cleanup_directory(tempdir):
def setup_shed_tools_for_test(app, tmpdir, testing_migrated_tools, testing_installed_tools):
"""Modify Galaxy app's toolbox for migrated or installed tool tests."""
# Store a jsonified dictionary of tool_id : GALAXY_TEST_FILE_DIR pairs.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this comment still relevant here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No - probably not - I'll axe that.

Comment thread lib/galaxy/app.py Outdated
self.dataset_collections_service = DatasetCollectionManager(self)
self.history_manager = HistoryManager(self)
self.dependency_resolvers_view = DependencyResolversView(self)
self.test_data_resolver = test_data.TestDataResolver(file_dirs=getattr(self.config, "tool_test_data_directories", None))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why getattr(self.config, "tool_test_data_directories", None) instead of the simpler self.config.tool_test_data_directories ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I do that frequently - the tool class for instance is used by the tool shed app I believe which doesn't have that attribute in the config. I think it is best to not assume as little about config as necessary to get a Tool that can be used as widely as possible.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But that's the Galaxy UniverseApplication, not Tool class, so this attribute should always be defined, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Indeed, missed that. I will change this for you.

Comment thread lib/galaxy/tools/verify/interactor.py Outdated
else:
return

if exceeded:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You need to remove also this line now that exceeded is gone.

@jmchilton jmchilton force-pushed the external_tool_tests_better_api branch from 9d017bb to 6ba55dc Compare March 5, 2018 15:58
Comment thread lib/galaxy/tools/verify/interactor.py Outdated
DEFAULT_TOOL_TEST_WAIT = os.environ.get("GALAXY_TEST_DEFAULT_WAIT", 86400)

DEFAULT_FTYPE = 'auto'
DEFAULT_DBKEY = 'hg17'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we make that '?' ? hg17 is usually not defined on regular galaxy instances, leading to

  File "script.py", line 39, in main
    tool_id, galaxy_interactor, test_index=test_index, tool_version=tool_version, register_job_data=_register_job_data
  File "/Users/mvandenb/src/galaxy/lib/galaxy/tools/verify/interactor.py", line 632, in verify_tool
    stage_data_in_history(galaxy_interactor, tool_id, testdef.test_data(), test_history)
  File "/Users/mvandenb/src/galaxy/lib/galaxy/tools/verify/interactor.py", line 52, in stage_data_in_history
    upload_waits.append(galaxy_interactor.stage_data_async(test_data, history, tool_id))
  File "/Users/mvandenb/src/galaxy/lib/galaxy/tools/verify/interactor.py", line 279, in stage_data_async
    raise Exception("Request to upload dataset failed [%s]" % submit_response_object.content)
Exception: Request to upload dataset failed [{"err_data": {"dbkey": "An invalid option was selected for dbkey, u'hg17', please verify."}, "err_msg": "An invalid option was selected for dbkey, u'hg17', please verify.", "err_code": 0}]

Changing that to ? works just fine in my limited tests.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Well somewhere there is a legacy test or 7 that is going to fail now but this seems like a good time to fix this.

I guess if some test does break - we could update the code to hit the API key and fetch the dbkeys and use hg17 if it is there or else revert to the new default of '?'.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sounds good to me!

@mvdbeek
Copy link
Copy Markdown
Member

mvdbeek commented Mar 6, 2018

Very nice!
$ python script.py -k <api_key> -t minimap2 -j /dev/stdout|jq

{
  "tests": [
    {
      "data": {
        "inputs": {
          "reference_source|reference_source_selector": "history",
          "fastq_input|fastq_input1": {
            "src": "hda",
            "id": "cb30f97aa5666a57"
          },
          "reference_source|ref_file": {
            "src": "hda",
            "id": "fb1f8927541ed886"
          },
          "fastq_input|fastq_input_selector": "single",
          "analysis_type_selector": "sr"
        },
        "job": {
          "tool_id": "toolshed.g2.bx.psu.edu/repos/iuc/minimap2/minimap2/2.3",
          "update_time": "2018-03-06T08:58:42.445108",
          "stdout": "",
          "outputs": {
            "alignment_output": {
              "src": "hda",
              "id": "28b4834f28bbe266",
              "uuid": "0f7342b8-d72a-4c98-bdde-9011ff0aa915"
            }
          },
          "command_line": "ln -f -s '/Users/mvandenb/src/galaxy/database/files/001/dataset_1296.dat' reference.fa && minimap2 -a -x sr    -t ${GALAXY_SLOTS:-4} reference.fa '/Users/mvandenb/src/galaxy/database/files/001/dataset_1297.dat' | samtools sort -@${GALAXY_SLOTS:-2} -O BAM -o '/Users/mvandenb/src/galaxy/database/files/001/dataset_1298.dat'",
          "exit_code": 0,
          "inputs": {
            "ref_file": {
              "src": "hda",
              "id": "fb1f8927541ed886",
              "uuid": "af999c2f-ad38-4679-b94d-f8160d79ec02"
            },
            "fastq_input1": {
              "src": "hda",
              "id": "cb30f97aa5666a57",
              "uuid": "d5eaf6b9-7980-4368-9e3c-9298ec97dfda"
            }
          },
          "state": "ok",
          "create_time": "2018-03-06T08:58:38.873519",
          "stderr": "[M::mm_idx_gen::0.002*1.89] collected minimizers\n[M::mm_idx_gen::0.004*3.75] sorted minimizers\n[M::main::0.004*3.71] loaded/built the index for 1 target sequence(s)\n[M::mm_mapopt_update::0.004*3.71] mid_occ = 1000\n[M::mm_idx_stat] kmer size: 21; skip: 11; is_HPC: 0; #seq: 1\n[M::mm_idx_stat::0.004*3.61] distinct minimizers: 2777 (100.00% are singletons); average occurrences: 1.000; average spacing: 5.967\n[M::worker_pipeline::0.006*3.48] mapped 100 sequences\n[M::main] Version: 2.4-r562-dirty\n[M::main] CMD: minimap2 -a -x sr -t 8 reference.fa /Users/mvandenb/src/galaxy/database/files/001/dataset_1297.dat\n[M::main] Real time: 0.008 sec; CPU: 0.023 sec\n",
          "model_class": "Job",
          "job_metrics": [
            {
              "raw_value": "2.0000000",
              "title": "Job Runtime (Wall Clock)",
              "name": "runtime_seconds",
              "value": "2 seconds",
              "plugin": "core"
            },
            {
              "raw_value": "8.0000000",
              "title": "Cores Allocated",
              "name": "galaxy_slots",
              "value": "8",
              "plugin": "core"
            },
            {
              "raw_value": "1520326720.0000000",
              "title": "Job Start Time",
              "name": "start_epoch",
              "value": "2018-03-06 09:58:40",
              "plugin": "core"
            },
            {
              "raw_value": "1520326722.0000000",
              "title": "Job End Time",
              "name": "end_epoch",
              "value": "2018-03-06 09:58:42",
              "plugin": "core"
            }
          ],
          "params": {
            "alignment_options": "{\"A\": \"\", \"B\": \"\", \"E\": \"\", \"-O2\": \"\", \"O\": \"\", \"s\": \"\", \"u\": null, \"z\": \"\", \"E2\": \"\"}",
            "io_options": "{\"Q\": \"false\", \"cs\": null, \"output_format\": \"BAM\", \"K\": \"\", \"L\": \"false\"}",
            "dbkey": "\"?\"",
            "analysis_type_selector": "\"sr\"",
            "mapping_options": "{\"g\": \"\", \"G\": \"\", \"F\": \"\", \"f\": \"\", \"m\": \"\", \"n\": \"\", \"p\": \"\", \"r\": \"\", \"X\": \"false\", \"N\": \"\"}",
            "fastq_input": "{\"__current_case__\": 1, \"fastq_input_selector\": \"single\", \"fastq_input1\": {\"values\": [{\"src\": \"hda\", \"id\": 1880}]}}",
            "reference_source": "{\"ref_file\": {\"values\": [{\"src\": \"hda\", \"id\": 1879}]}, \"reference_source_selector\": \"history\", \"__current_case__\": 1}",
            "indexing_options": "{\"I\": \"\", \"k\": \"\", \"w\": \"\"}",
            "chromInfo": "\"/Users/mvandenb/src/tool-data/shared/ucsc/chrom/?.len\""
          },
          "external_id": "58330",
          "id": "9fea3536e8286cc5",
          "user_email": "xxxxxxxxxxxx@yyy.com"
        }
      },
      "id": "minimap2-0",
      "has_data": true
    }
  ],
  "version": "0.1"
}

jmchilton added a commit to jmchilton/galaxy that referenced this pull request Mar 6, 2018
This makes a lot more sense, since the target Galaxy may not be configured with this dbkey. Thanks to @mvdbeek for the catch (galaxyproject#5628 (review)).

Restore the legacy behavior with "export GALAXY_TEST_DEFAULT_DBKEY=hg17".
Comment thread lib/galaxy/tools/verify/interactor.py Outdated

DEFAULT_FTYPE = 'auto'
DEFAULT_DBKEY = 'hg17'
# This following defualt dbkey was traditionally hg17 before Galaxy 18.05,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

s/defualt/default/

@jmchilton jmchilton force-pushed the external_tool_tests_better_api branch from 99b3bc9 to 948be85 Compare March 6, 2018 12:30
jmchilton added a commit to jmchilton/galaxy that referenced this pull request Mar 6, 2018
This makes a lot more sense, since the target Galaxy may not be configured with this dbkey. Thanks to @mvdbeek for the catch (galaxyproject#5628 (review)).

Restore the legacy behavior with "export GALAXY_TEST_DEFAULT_DBKEY=hg17".
@jmchilton jmchilton force-pushed the external_tool_tests_better_api branch from 948be85 to ec399c3 Compare March 6, 2018 17:24
jmchilton added a commit to jmchilton/galaxy that referenced this pull request Mar 6, 2018
This makes a lot more sense, since the target Galaxy may not be configured with this dbkey. Thanks to @mvdbeek for the catch (galaxyproject#5628 (review)).

Restore the legacy behavior with "export GALAXY_TEST_DEFAULT_DBKEY=hg17".
@nsoranzo
Copy link
Copy Markdown
Member

nsoranzo commented Mar 6, 2018

There's one unit test that keeps failing.

@jmchilton
Copy link
Copy Markdown
Member Author

@nsoranzo Yeah - I saw that too - I've looked at it at a bit. It is quite baffling because everything was green before I added that last commit related to dbkey and I've tried running it locally and it doesn't fail for me - either as part of the whole unit test or alone.

I was hoping some other PR would have it fail also but it really seems to just be this one. Maybe something to do with the test data resolver changes - I'll have to figure it out.

@jmchilton
Copy link
Copy Markdown
Member Author

Actually an unrelated PR does exhibit this error on Travis https://travis-ci.org/galaxyproject/galaxy/jobs/349953355 and against 18.01 no less. Odd.

@jmchilton
Copy link
Copy Markdown
Member Author

Well the problem is we don't have a fixed sniffer order for the new bam types I think.

@mvdbeek
Copy link
Copy Markdown
Member

mvdbeek commented Mar 6, 2018

I think that's my fault, this was introduced with #5589.
Some files could be sniffed to bam_native or bam_input_qname_sorted. We should disable the sniffer for the latter.

mvdbeek added a commit to mvdbeek/galaxy that referenced this pull request Mar 6, 2018
Only aligners should produce this datatype. If an alignment
is not explicitly coordinate or queryname sorted it should
be BamNative.
Also addresses galaxyproject#5628 (comment),
though I think the sniff order should be dependent on the order with which
datatypes are loaded.
Can be shared between tests and TDTs. A step toward not requiring one to load the tool to test the tool (important for external testing of tools).
jmchilton added 17 commits March 6, 2018 20:07
Should enable greater reuse from outside the test framework (e.g. standalone scripts and Planemo).
Working toward making interactor stand-alone and independent of the test framework.
This gets us a lot closer to being able to construct a ToolTestBuilder from simple dictionaries generated from the API for instance or from any tool really.
Use this is in tool testing. Prevents needing to load / have tools in memory to run tool tests - should allow external tool testing.
Previously this was set in the test framework but that doesn't help running Galaxies.
Cleanup up internal representations used to bridge the tool parser and the tool testing modules to produce more sensible dictified representations when exported via the API. This is mostly replacing tuples (which get converted to JSON lists) to dicts but there are some other small cleanups.
This makes a lot more sense, since the target Galaxy may not be configured with this dbkey. Thanks to @mvdbeek for the catch (galaxyproject#5628 (review)).

Restore the legacy behavior with "export GALAXY_TEST_DEFAULT_DBKEY=hg17".
@jmchilton jmchilton force-pushed the external_tool_tests_better_api branch from ec399c3 to ffc929d Compare March 7, 2018 01:08
Comment thread config/datatypes_conf.xml.sample Outdated
<sniffer type="galaxy.datatypes.binary:H5"/>
<sniffer type="galaxy.datatypes.binary:Bam"/>
<sniffer type="galaxy.datatypes.binary:BamQuerynameSorted" />
<sniffer type="galaxy.datatypes.binary:BamInputSorted" />
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this, I missed that! Can you move galaxy.datatypes.binary:BamInputSorted below BamNative ? We don't want to actually sniff that one (or give the impression that it can be sniffed).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ugh - this was my attempt to fix the failing test before you did. This commit doesn’t belong here - sorry about that and thanks for catching it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Okay - I've stripped the commit. Thanks again for the catch.

@jmchilton jmchilton force-pushed the external_tool_tests_better_api branch from ffc929d to f741ab1 Compare March 7, 2018 12:18
@mvdbeek mvdbeek merged commit 3afb4ab into galaxyproject:dev Mar 7, 2018
@mvdbeek
Copy link
Copy Markdown
Member

mvdbeek commented Mar 7, 2018

Exciting! Thanks a lot @jmchilton !

@jmchilton
Copy link
Copy Markdown
Member Author

@mvdbeek Thank you and @nsoranzo for the detailed review and testing! I appreciate the merge.

I've created a list of follow up work with #5651

jmchilton added a commit to jmchilton/galaxy that referenced this pull request Mar 8, 2018
jmchilton added a commit to jmchilton/galaxy that referenced this pull request Mar 9, 2018
@nsoranzo nsoranzo deleted the external_tool_tests_better_api branch November 7, 2025 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants