Skip to content

Commit

Permalink
Update test-repo to use grapevne-helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbrittain committed Sep 12, 2024
1 parent 4b65cdf commit 855aa31
Show file tree
Hide file tree
Showing 27 changed files with 300 additions and 52 deletions.
35 changes: 31 additions & 4 deletions electron-app/postbuild_tests/modules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -595,13 +595,40 @@ describe('modules', () => {

// Conda tests
runif(is_installed(['mamba', 'conda'], 'any')).each([
['conda', [path.join('results', 'conda', 'data.csv')]],
// Test: 1 (connect two modules)
[
[
// Modules to add to scene
'payload shell', // data-nodeid="n0"
'conda', // data-nodeid="n1"
],
[
// Connections to make between modules
['n0-out-source', 'n1-in-target'], // (nodeid)-(portname)-(porttype)
],
[
// Expected output files
path.join('results', 'conda', 'data.csv'),
],
],
])(
"Build and Test the conda workflow: module '%s'",
async (modulename, outfiles) => {
await BuildAndRun_SingleModuleWorkflow(driver, modulename, outfiles);
async (modulenames, connections, outfiles) => {
// Open settings pane
await driver.findElement(By.xpath('//div[@id="btnSidenavSettings"]')).click();

// Set snakemake command line arguments
const args = await driver.findElement(webdriver.By.id('inputBuilderSettingsSnakemakeArgs'));
await OverwriteInputField(args, '--cores 1 --use-conda');

// Close settings pane
await driver.findElement(By.xpath('//div[@id="btnSidenavBuilder"]')).click();
console.log('<<< test Set snakemake arguments list to use conda');

// Build and run workflow
await BuildAndRun_MultiModuleWorkflow(driver, modulenames, connections, outfiles);
},
10 * ONE_MINUTE,
5 * ONE_MINUTE,
); // long timeout

test(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"input_namespace":
"payload_run$": "in"
"output_namespace": "payload_run"
"payload_run":
"name": "payload_run"
"type": "module"
"snakefile": "/Users/jsb/repos/jsbrittain/GRAPEVNE/electron-app/postbuild_tests/test-repo/workflows/single_modules/sources/payload_run/workflow/Snakefile"
"config":
"input_namespace": "in"
"output_namespace": "payload_run"
"params":
"filename": "data.csv"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
configfile: "config/config.yaml"

module payload_run:
snakefile:
config["payload_run"]["snakefile"]
config:
config["payload_run"]["config"]
use rule * from payload_run exclude _test as payload_run_*
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

rm -rf results/out
snakemake --cores 1 --use-conda --configfile=config/.test.yaml _test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
input_namespace: in
output_namespace: out
params:
filename: data.csv
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
configfile: "config/config.yaml"
from grapevne_helper import *
import shutil

params = config["params"]
init(workflow)

rule copy:
input:
expand(
"results/{indir}/{filename}",
indir=config["input_namespace"],
filename=params["filename"],
)
input(params("filename")),
output:
expand(
"results/{outdir}/{filename}",
outdir=config["output_namespace"],
filename=params["filename"],
)
output(params("filename")),
run:
shutil.copy(input[0], output[0])

rule _test:
input:
src=rules.copy.input[0],
dst=rules.copy.output[0],
run:
# Verify that the file has been copied correctly
with open(input.src) as src, open(input.dst) as dst:
assert src.read() == dst.read()
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys
import logging

try:
from grapevne.helpers import * # noqa: F403
except ImportError:
import ensurepip
import subprocess

ensurepip.bootstrap()
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "--upgrade", "grapevne"]
)
try:
from grapevne.helpers import * # noqa: F403 F401
except ImportError:
logging.error("Failed to install grapevne. Exiting.")
sys.exit(1)

# Tidy-up namespace
del sys, logging

# Dynamically export all names imported from grapevne
__all__ = [name for name in dir() if not name.startswith("_")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

rm -rf results/out
snakemake --cores 1 --use-conda --configfile=config/.test.yaml _test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
input_namespace:
in1: in1
in2: in2
in3: in3
output_namespace: out
params:
filename: data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ Input namespaces: [in1, in2, in3]
Copy file from first input namespace (in1) only
"""
configfile: "config/config.yaml"
from grapevne_helper import *
import shutil

params = config["params"]
init(workflow)

rule copy:
input:
expand(
"results/{indir}/{filename}",
indir=config["input_namespace"]["in1"],
filename=params["filename"],
)
input(params("filename"), "in1"),
output:
expand(
"results/{outdir}/{filename}",
outdir=config["output_namespace"],
filename=params["filename"],
)
output(params("filename")),
run:
shutil.copy(input[0], output[0])

rule _test:
input:
src=rules.copy.input[0],
dst=rules.copy.output[0],
run:
# Verify that the file has been copied correctly
with open(input.src) as src, open(input.dst) as dst:
assert src.read() == dst.read()
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys
import logging

try:
from grapevne.helpers import * # noqa: F403
except ImportError:
import ensurepip
import subprocess

ensurepip.bootstrap()
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "--upgrade", "grapevne"]
)
try:
from grapevne.helpers import * # noqa: F403 F401
except ImportError:
logging.error("Failed to install grapevne. Exiting.")
sys.exit(1)

# Tidy-up namespace
del sys, logging

# Dynamically export all names imported from grapevne
__all__ = [name for name in dir() if not name.startswith("_")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

rm -rf results/out
snakemake --cores 1 --use-conda --configfile=config/.test.yaml _test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
input_namespace: in
output_namespace: out
params:
filename: data.csv
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
configfile: "config/config.yaml"
from grapevne_helper import *

params = config["params"]
init(workflow)

rule copy:
input:
expand(
srcdir("../results/{indir}/{filename}"),
indir=config["input_namespace"],
filename=params["filename"],
)
input(params("filename")),
output:
expand(
"results/{outdir}/{filename}",
outdir=config["output_namespace"],
filename=params["filename"],
)
output(params("filename")),
conda:
"envs/conda.yaml"
shell:
"""
cp {input} {output}
"""

rule _test:
input:
src=rules.copy.input[0],
dst=rules.copy.output[0],
run:
# Verify that the file has been copied correctly
with open(input.src) as src, open(input.dst) as dst:
assert src.read() == dst.read()
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys
import logging

try:
from grapevne.helpers import * # noqa: F403
except ImportError:
import ensurepip
import subprocess

ensurepip.bootstrap()
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "--upgrade", "grapevne"]
)
try:
from grapevne.helpers import * # noqa: F403 F401
except ImportError:
logging.error("Failed to install grapevne. Exiting.")
sys.exit(1)

# Tidy-up namespace
del sys, logging

# Dynamically export all names imported from grapevne
__all__ = [name for name in dir() if not name.startswith("_")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

rm -rf results
snakemake --cores 1 --use-conda --configfile=config/.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
input_namespace: null
output_namespace: utility_touch
utility_touch:
config:
input_namespace: null
output_namespace: utility_touch
params:
filename: data.csv
name: (Utility) touch
snakefile:
args:
- jsbrittain/snakeshack
function: github
kwargs:
branch: main
path: workflows/Utility/modules/touch/workflow/Snakefile
type: module
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module utility_touch:
*config["utility_touch"]["snakefile"]["args"],
**config["utility_touch"]["snakefile"]["kwargs"],
)
)
config:
config["utility_touch"]["config"]
use rule * from utility_touch as utility_touch_*
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

rm -rf results/out
snakemake --cores 1 --use-conda --configfile=config/.test.yaml _test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
input_namespace: in
output_namespace: out
params:
filename: data.csv
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
configfile: "config/config.yaml"

from grapevne_helper import *
import os
import pathlib
import shutil

params = config["params"]
init(workflow)

rule copy:
input:
srcdir("../resources/file"),
resource("file"),
output:
expand(
"results/{outdir}/{filename}",
outdir=config["output_namespace"],
filename=params["filename"],
)
output(params("filename")),
run:
pathlib.Path(os.path.dirname(output[0])).mkdir(parents=True, exist_ok=True)
shutil.copy(input[0], output[0])

rule _test:
input:
src=resource("file"),
dst=output(params("filename")),
run:
# Verify that the file has been copied correctly
with open(input.src) as src, open(input.dst) as dst:
assert src.read() == dst.read()
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys
import logging

try:
from grapevne.helpers import * # noqa: F403
except ImportError:
import ensurepip
import subprocess

ensurepip.bootstrap()
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "--upgrade", "grapevne"]
)
try:
from grapevne.helpers import * # noqa: F403 F401
except ImportError:
logging.error("Failed to install grapevne. Exiting.")
sys.exit(1)

# Tidy-up namespace
del sys, logging

# Dynamically export all names imported from grapevne
__all__ = [name for name in dir() if not name.startswith("_")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

rm -rf results/out
snakemake --cores 1 --use-conda --configfile=config/.test.yaml _test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
input_namespace: in
output_namespace: out
params:
filename: data.csv
Loading

0 comments on commit 855aa31

Please sign in to comment.