+
Skip to content

Increased test coverage #994

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 4 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions tests/lint/files_unchanged.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest
import shutil
import tempfile
import os

import nf_core.lint


def test_files_unchanged_pass(self):
self.lint_obj._load()
results = self.lint_obj.files_unchanged()
assert len(results.get("warned", [])) == 0
assert len(results.get("failed", [])) == 0
assert len(results.get("ignored", [])) == 0
assert not results.get("could_fix", True)


def test_files_unchanged_fail(self):
failing_file = os.path.join(".github", "CONTRIBUTING.md")
new_pipeline = self._make_pipeline_copy()
with open(os.path.join(new_pipeline, failing_file), "a") as fh:
fh.write("THIS SHOULD NOT BE HERE")

lint_obj = nf_core.lint.PipelineLint(new_pipeline)
lint_obj._load()
results = lint_obj.files_unchanged()
assert len(results["failed"]) == 1
assert failing_file in results["failed"][0]
assert results["could_fix"]
54 changes: 54 additions & 0 deletions tests/lint/nextflow_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import pytest
import unittest
import tempfile
import os
import shutil

import nf_core.create
import nf_core.lint


def test_nextflow_config_example_pass(self):
"""Tests that config variable existence test works with good pipeline example"""
self.lint_obj._load_pipeline_config()
result = self.lint_obj.nextflow_config()
assert len(result["failed"]) == 0
assert len(result["warned"]) == 0


def test_nextflow_config_bad_name_fail(self):
"""Tests that config variable existence test fails with bad pipeline name"""
new_pipeline = self._make_pipeline_copy()
lint_obj = nf_core.lint.PipelineLint(new_pipeline)
lint_obj._load_pipeline_config()

lint_obj.nf_config["manifest.name"] = "bad_name"
lint_obj.nf_config["process.container"] = "bad_name:dev"
result = lint_obj.nextflow_config()
assert len(result["failed"]) == 1
assert len(result["warned"]) == 0


def test_nextflow_config_bad_container_name_failed(self):
"""Tests that config variable existence test fails with bad container name"""
new_pipeline = self._make_pipeline_copy()
lint_obj = nf_core.lint.PipelineLint(new_pipeline)
lint_obj._load_pipeline_config()

lint_obj.nf_config["process.container"] = "bad_name"
result = lint_obj.nextflow_config()
assert len(result["failed"]) == 0
assert len(result["warned"]) == 1


def test_nextflow_config_dev_in_release_mode_failed(self):
"""Tests that config variable existence test fails with dev version in release mode"""
new_pipeline = self._make_pipeline_copy()
lint_obj = nf_core.lint.PipelineLint(new_pipeline)
lint_obj._load_pipeline_config()

lint_obj.release_mode = True
lint_obj.nf_config["manifest.version"] = "dev_is_bad_name"
result = lint_obj.nextflow_config()
assert len(result["failed"]) == 1
assert len(result["warned"]) == 0
12 changes: 12 additions & 0 deletions tests/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ def test_sphinx_rst_files(self):

from lint.merge_markers import test_merge_markers_found

from lint.nextflow_config import (
test_nextflow_config_example_pass,
test_nextflow_config_bad_name_fail,
test_nextflow_config_bad_container_name_failed,
test_nextflow_config_dev_in_release_mode_failed,
)

from lint.files_unchanged import (
test_files_unchanged_pass,
test_files_unchanged_fail,
)


# def test_critical_missingfiles_example(self):
# """Tests for missing nextflow config and main.nf files"""
Expand Down
32 changes: 32 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import nf_core.create
import nf_core.utils

import mock
import os
import pytest
import requests
import tempfile
import unittest

Expand Down Expand Up @@ -92,3 +95,32 @@ def test_list_files_no_git(self):
pipeline_obj = nf_core.utils.Pipeline(tmpdir)
pipeline_obj._list_files()
assert tmp_fn in pipeline_obj.files

def test_pip_package_pass(self):
result = nf_core.utils.pip_package("multiqc=1.10")
assert type(result) == dict

@mock.patch("requests.get")
def test_pip_package_timeout(self, mock_get):
"""Tests the PyPi connection and simulates a request timeout, which should
return in an addiional warning in the linting"""
# Define the behaviour of the request get mock
mock_get.side_effect = requests.exceptions.Timeout()
# Now do the test
with pytest.raises(LookupError):
nf_core.utils.pip_package("multiqc=1.10")

@mock.patch("requests.get")
def test_pip_package_connection_error(self, mock_get):
"""Tests the PyPi connection and simulates a connection error, which should
result in an additional warning, as we cannot test if dependent module is latest"""
# Define the behaviour of the request get mock
mock_get.side_effect = requests.exceptions.ConnectionError()
# Now do the test
with pytest.raises(LookupError):
nf_core.utils.pip_package("multiqc=1.10")

def test_pip_erroneous_package(self):
""" Tests the PyPi API package information query """
with pytest.raises(ValueError):
nf_core.utils.pip_package("not_a_package=1.0")
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载