-
Notifications
You must be signed in to change notification settings - Fork 42
Add pytest, enable coverage testing, fix key issue #105
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
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
bc61b6b
add pytest and coverage requirements
rhpvorderman 9228879
create src dir
rhpvorderman 91f5964
update manifest and setup.py for moving ephemeris
rhpvorderman a95582a
add one test, to ensure test-framework works
rhpvorderman 7c20722
update test framework
rhpvorderman 8fd3e32
remove some redundant stuff
rhpvorderman 0a04f50
disable codacy coverage until stuff is there
rhpvorderman d633092
remove BOTO workaround
rhpvorderman 959a85b
fix error with invalid keys
rhpvorderman 8274c16
add a warning for invalid keys
rhpvorderman bcd915a
fix bugs
rhpvorderman c366547
fix some other bugs
rhpvorderman 8f43d94
make it a constant
rhpvorderman a093beb
fix typo
rhpvorderman f69eec1
update tox
rhpvorderman 5cb805b
Merge branch 'pytest' of github.com:rhpvorderman/ephemeris into pytest
rhpvorderman f0ed60c
test stripping of invalid key
rhpvorderman 51f8d0b
proper code formatting
rhpvorderman 9e18881
add docker test code
rhpvorderman e13e872
flake issues
rhpvorderman 799c117
lint issues
rhpvorderman 308b4cb
fix pyyaml typo
rhpvorderman 7ea3401
start on writing fixture
rhpvorderman 8fbea21
rename to galaxy_wait
rhpvorderman 4008158
use tests with fixtures
rhpvorderman d7bf785
coverage reports enabled on codacy
rhpvorderman 9b25b53
enable docker for pytest as well
rhpvorderman 20a28e5
use the right coverage command
rhpvorderman 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,8 @@ pip-log.txt | |
| .tox | ||
| nosetests.xml | ||
| htmlcov | ||
| .pytest_cache | ||
| coverage.xml | ||
|
|
||
| # Translations | ||
| *.mo | ||
|
|
||
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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| graft src | ||
| include *.rst LICENSE |
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 |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| six>=1.9.0 | ||
| pyyaml | ||
| PyYAML | ||
| bioblend>=0.10.0 | ||
| Jinja2 | ||
| galaxy-lib>=18.5.7 | ||
|
|
||
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
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
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
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
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,48 @@ | ||
| from collections import namedtuple | ||
|
|
||
| import docker | ||
| import pytest | ||
| from bioblend.galaxy import GalaxyInstance | ||
|
|
||
| from ephemeris.sleep import galaxy_wait | ||
|
|
||
|
|
||
| # It needs to work well with dev. Alternatively we can pin this to 'master' or another stable branch. | ||
| # Preferably a branch that updates with each stable release | ||
| GALAXY_IMAGE = "bgruening/galaxy-stable:dev" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fine for now, but we can also parameterize the start_container fixture to control which image to start. |
||
|
|
||
| client = docker.from_env() | ||
|
|
||
| GalaxyContainer = namedtuple('GalaxyContainer', ['url', 'container', 'attributes', 'gi']) | ||
|
|
||
|
|
||
| # Class scope is chosen here so we can group tests on the same galaxy in a class. | ||
| @pytest.fixture(scope="class") | ||
| def start_container(**kwargs): | ||
| """Starts a docker container with the galaxy image. Returns a named tuple with the url, a GalaxyInstance object, | ||
| the container attributes, and the container itself.""" | ||
| # We start a container from the galaxy image. We detach it. Port 80 is exposed to the host at a random port. | ||
| # The random port is because we need mac compatibility. On GNU/linux a better option would be not to expose it | ||
| # and use the internal ip address instead. | ||
| # But alas, the trappings of a proprietary BSD kernel compel us to do ugly workarounds. | ||
|
|
||
| container = client.containers.run(GALAXY_IMAGE, detach=True, ports={'80/tcp': None}, **kwargs) | ||
| container_id = container.attrs.get('Id') | ||
| print(container_id) | ||
|
|
||
| # This seems weird as we also can just get container.attrs but for some reason | ||
| # the network settings are not loaded in container.attrs. With the get request | ||
| # these attributes are loaded | ||
| container_attributes = client.containers.get(container_id).attrs | ||
|
|
||
| # Venturing into deep nested dictionaries. | ||
| exposed_port = container_attributes.get('NetworkSettings').get('Ports').get('80/tcp')[0].get('HostPort') | ||
|
|
||
| container_url = "http://localhost:{0}".format(exposed_port) | ||
| galaxy_wait(container_url, | ||
| timeout=60) # We are only going to wait 60 seconds. These are tests, and we are impatient! | ||
| yield GalaxyContainer(url=container_url, | ||
| container=container, | ||
| attributes=container_attributes, | ||
| gi=GalaxyInstance(container_url, key="admin")) | ||
| container.remove(force=True) | ||
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,28 @@ | ||
| #!/usr/bin/env python | ||
| import logging | ||
|
|
||
| from docker_for_galaxy import start_container | ||
|
|
||
| from ephemeris.shed_tools import InstallRepositoryManager | ||
|
|
||
| # This line is needed because flake things the import for start_container is not used otherwise. | ||
| start_container_is_used = start_container | ||
|
|
||
|
|
||
| # NOTE: For each series of tests that needs the same container, use the same class. | ||
| # The start_container fixture has the "class" scope. | ||
|
|
||
| class TestMiscellaneous(object): | ||
| """This class is for miscellaneous tests that can use the same galaxy container""" | ||
|
|
||
| def test_invalid_keys_in_repo_list(self, caplog, start_container): | ||
| container = start_container | ||
| irm = InstallRepositoryManager(container.gi) | ||
| caplog.set_level(logging.WARNING) | ||
| irm.install_repositories([ | ||
| dict(name="bwa", | ||
| owner="devteam", | ||
| tool_panel_section_name="NGS: Alignment", | ||
| sesame_ouvre_toi="Invalid key") | ||
| ], log=logging.getLogger()) | ||
| assert "'sesame_ouvre_toi' not a valid key. Will be skipped during parsing" in caplog.text |
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,44 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| from ephemeris.shed_tools_methods import flatten_repo_info | ||
|
|
||
|
|
||
| def test_flatten_repo_info(): | ||
| test_repositories = [ | ||
| dict(name="bwa", | ||
| owner="devteam", | ||
| tool_panel_section_label="NGS: Alignment", | ||
| revisions=["1", "2"]), | ||
| dict(name="bowtie2", | ||
| owner="devteam", | ||
| tool_panel_section_label="NGS: Alignment", | ||
| changeset_revisions=["3", "4"]) | ||
| ] | ||
| flattened_repos = flatten_repo_info(test_repositories) | ||
| assert (flattened_repos == [ | ||
| dict(name="bwa", | ||
| owner="devteam", | ||
| tool_panel_section_label="NGS: Alignment", | ||
| changeset_revision="1"), | ||
| dict(name="bwa", | ||
| owner="devteam", | ||
| tool_panel_section_label="NGS: Alignment", | ||
| changeset_revision="2"), | ||
| dict(name="bowtie2", | ||
| owner="devteam", | ||
| tool_panel_section_label="NGS: Alignment") | ||
| ]) | ||
|
|
||
|
|
||
| def test_flatten_repo_info_invalid_key(): | ||
| test_repositories = [ | ||
| dict(name="bwa", | ||
| owner="devteam", | ||
| tool_panel_section_label="NGS: Alignment", | ||
| tool_shed_url="toolshed.g2.bx.psu.edu", | ||
| sesame_ouvre_toi="This is an invalid key") | ||
| ] | ||
| flattened_repos = flatten_repo_info(test_repositories) | ||
|
|
||
| assert "sesame_ouvre_toi" not in flattened_repos[0].keys() | ||
| assert "tool_shed_url" in flattened_repos[0].keys() |
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.
Another direction for the future: the verbose handling should happen via the logging facility. I.e you'd only see INFO and DEBUG levels if you increase verbosity. Which would be nice because it removes the conditional handling here.