Skip to content
Snippets Groups Projects
Commit eaaef016 authored by Michele Garioni's avatar Michele Garioni
Browse files

fix: add testing for cli

parent 9de5ef24
Branches
No related tags found
3 merge requests!24Draft: Count gene,!21fix: add cli to sample_from_input,!20Feature
Pipeline #13789 passed
...@@ -2,11 +2,20 @@ ...@@ -2,11 +2,20 @@
import pytest import pytest
import pandas as pd import pandas as pd
import os
import importlib.util
from pathlib import Path
import sys
from src.sample_from_input import sample_from_input from src.sample_from_input import (
sample_from_input,
main
)
PACKAGE_DIR = Path(__file__).resolve().parents[1] / 'src'
def test_sampleinput(tmpdir): def test_sample_from_input(tmpdir):
"""Tests the output, input file name and separator.""" """Tests the output, input file name and separator."""
sample_from_input( sample_from_input(
input_file='./tests/resources/Transcript2.tsv', input_file='./tests/resources/Transcript2.tsv',
...@@ -14,9 +23,34 @@ def test_sampleinput(tmpdir): ...@@ -14,9 +23,34 @@ def test_sampleinput(tmpdir):
sep='\t', sep='\t',
n=142958 n=142958
) )
t1=pd.read_table(tmpdir / 'test1.csv', header=None, sep=',') t1 = pd.read_table(tmpdir / 'test1.csv', header=None, sep=',')
assert t1[1].sum()==142958 assert t1[1].sum() == 142958
with pytest.raises(IndexError): with pytest.raises(IndexError):
sample_from_input(input_file='./tests/resources/Transcript2.tsv') sample_from_input(input_file='./tests/resources/Transcript2.tsv')
with pytest.raises(IOError): with pytest.raises(IOError):
sample_from_input(input_file='file_not_existing.txt') sample_from_input(input_file='file_not_existing.txt')
def test_main_with_args(monkeypatch, tmpdir):
"""Call with args."""
monkeypatch.setattr(
sys, 'argv', [
'sample_from_input',
'./tests/resources/Transcript1.csv',
'-o',
str(tmpdir / 'test1.csv'),
]
)
ret_val = main()
assert ret_val is None
def test_main_as_script():
"""Run as script."""
main_file = PACKAGE_DIR / "sample_from_input.py"
fl = os.path.join(os.path.dirname(__file__), main_file)
spec = importlib.util.spec_from_file_location('__main__', fl)
module = importlib.util.module_from_spec(spec)
with pytest.raises(SystemExit) as exc:
spec.loader.exec_module(module)
assert exc.value.code != 0
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment