Skip to content
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

Hook test_suite.py into lcdb-wf-test #421

Open
wants to merge 4 commits into
base: fix_issue_407
Choose a base branch
from
Open
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
17 changes: 13 additions & 4 deletions lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
'merged_dir',
'peaks_dir',
'hub_config',
'include_references',
]


Expand Down Expand Up @@ -66,13 +67,17 @@ def resolve_config(config, workdir=None):
if isinstance(config, str):
config = yaml.load(open(config), Loader=yaml.FullLoader)

def rel(pth):
if workdir is None or os.path.isabs(pth):
def abs_path(pth):
if os.path.isabs(pth):
return pth
return os.path.join(workdir, pth)
for key in PATH_KEYS:
if key in config:
config[key] = rel(config[key])
if key in config and workdir:
if isinstance(config[key], list):
for i in range(len(config[key])):
config[key][i] = abs_path(config[key][i])
else:
config[key] = abs_path(config[key])
return config


Expand Down Expand Up @@ -626,6 +631,10 @@ def load_config(config, missing_references_ok=False):
handler.
"""

if isinstance(config, str):
config = yaml.load(open(config), Loader=yaml.FullLoader)

config = resolve_config(config)
# Here we populate a list of reference sections. Items later on the list
# will have higher priority
includes = config.get('include_references', [])
Expand Down
3 changes: 1 addition & 2 deletions lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ def get_top_level_dir(start_dir=None):
if current_dir == parent_dir:
break
current_dir = parent_dir
#TODO: Check for other edge cases?

return None
return current_dir

7 changes: 4 additions & 3 deletions lib/patterns_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from . import common
from . import chipseq
from . import helpers
from pathlib import Path

HERE = os.path.abspath(os.path.dirname(__file__))

Expand Down Expand Up @@ -46,17 +47,17 @@ def __init__(self, config, patterns, workdir=None):
as relative to `workdir`
"""
self.path = None
self.workdir = '.'
self.workdir = None
if workdir is not None:
config = os.path.join(workdir, config)
patterns = os.path.join(workdir, patterns)
self.workdir = workdir

if isinstance(config, str):
config = os.path.join(workdir, config)
self.path = config

self.config = common.load_config(
common.resolve_config(config, workdir))
common.resolve_config(config, self.workdir))

stranded = self.config.get('stranded', None)
self.stranded = None
Expand Down
1 change: 1 addition & 0 deletions test/lcdb-wf-test
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ class Runner(object):
if args.pytest:
print_header("pytest")
sp.run(["pytest", "--doctest-modules", "lib"], check=True, cwd=TOPLEVEL)
sp.run(["pytest", "test/tests"], check=True, cwd=TOPLEVEL)

if args.url_check:
print_header("url check")
Expand Down
17 changes: 9 additions & 8 deletions test/tests/test_suite.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import sys
import os
import subprocess
top_level_dir = subprocess.run(["dirname $(dirname $(pwd))"], shell=True, capture_output=True, text=True).stdout.strip()
print("top level dir: ", top_level_dir)
from pathlib import Path
top_level_dir = str(Path(".").resolve())
sys.path.insert(0, top_level_dir)
import pytest
from textwrap import dedent
Expand All @@ -11,15 +12,15 @@
@pytest.fixture
def config(request):
config_path = request.param
config = common.load_config(config_path, test=True)
return patterns_targets.RNASeqConfig(config, config.get('patterns', '../workflows/rnaseq/config/rnaseq_patterns.yaml'))
rnaseq_workdir = os.path.join(helpers.get_top_level_dir(), "workflows","rnaseq")
config = common.load_config(common.resolve_config(config_path, rnaseq_workdir))
return patterns_targets.RNASeqConfig(config, config.get('patterns', '../workflows/rnaseq/config/rnaseq_patterns.yaml'), workdir=rnaseq_workdir)

# Call helpers.detect_layout(), which implicitly tests common.is_paired_end()
# TODO: Make assertion condition NOT hard coded in to work with current example table
@pytest.mark.parametrize("config", ['../../workflows/rnaseq/config/config.yaml'], indirect=True)
def test_is_paired_end(config):
@pytest.mark.parametrize("config, is_paired_ref", [("workflows/rnaseq/config/config.yaml", False)], indirect=["config"])
def test_is_paired_end(config, is_paired_ref):
is_paired = helpers.detect_layout(config.sampletable) == 'PE'
assert not is_paired, f"Test failed, is_paired = {is_paired}"
assert is_paired==is_paired_ref, f"Test failed, is_paired is {is_paired} when it should be {is_paired_ref}"

def test_config_loading(tmpdir):
f0 = tmpdir.mkdir('subdir').join('file0.yaml')
Expand Down