Skip to content
Snippets Groups Projects

Draft: Count gene

Closed Michele Garioni requested to merge count_gene into main
1 file
+ 38
4
Compare changes
  • Side-by-side
  • Inline
+ 38
4
@@ -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
Loading